Skip to content

fix(session-ui): prevent fatal error when a virtualized timeline row changes type - #62824

Open
ElNeMeR70 wants to merge 1 commit into
anomalyco:devfrom
ElNeMeR70:fix/timeline-row-type-change-62800
Open

ElNeMeR70 wants to merge 1 commit into
anomalyco:devfrom
ElNeMeR70:fix/timeline-row-type-change-62800

Conversation

@ElNeMeR70

@ElNeMeR70 ElNeMeR70 commented Nov 9, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #62800

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes the fatal Error: Expected a user-message timeline row crash when a virtualized timeline row's key disappears and another row type lands at the same index in the same reactive batch (for example when a steered user message row is replaced by an assistant/thinking row).

  • In VirtualRow (packages/app/src/session/timeline/virtualizer.tsx), fall back to initialRow instead of rows()[item().index] when rowByKey().get(rowProps.rowKey) is undefined, preventing VirtualRow from handing a different row variant at the same index to a still-mounted keyed branch before <For> unmounts it.
  • Add TimelineRow.pin (packages/session-ui/src/timeline/timeline-row.ts) and wrap props.row in Row (packages/session-ui/src/timeline/session-timeline-row.tsx) inside <Show when={TimelineRow.key(props.row())} keyed> so each keyed branch stays pinned to its own key while keeping the strict tag checks in current().
  • Capture props.row.userMessageID eagerly in Frame before scheduling growIn's requestAnimationFrame callback.

How did you verify your code works?

Added a unit test in packages/session-ui/src/timeline/rows-current.test.ts verifying that TimelineRow.pin preserves the keyed UserMessage row when constructSessionMessageRows replaces the row at the same index with an assistant/thinking row.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Nov 9, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crash is fixed, but the new regression test is broken and needs fixing before merge.

I checked it with a component test compiled with Solid's real compiler. It mounts a growing steer user-message row, then removes its key so an assistant-part row takes the same index. On the base this throws Expected a user-message timeline row; with this PR there's no error. The virtualizer.tsx change alone also prevents it, and so does pinning the row in Row. tsc -b passes for packages/app. For packages/session-ui it passes apart from errors in the new test.

Public API: unchanged.

Concerns:

  1. The new test is broken and stops other tests from running. Details inline.
  2. The tag fallback in every branch isn't needed. Once Row pins its row by key, the tag can't change inside a branch. Details inline.


const rowKey = "user-message:msg_2"
const index = initial.rows.findIndex((item) => TimelineRow.key(item) === rowKey)
const initialRow = initial.rowByKey.get(rowKey)!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can't pass: Timeline.constructSessionMessageRows returns { activeMessageID, turnPhaseByID, rows } with no rowByKey. It throws TypeError: undefined is not an object here, and tsc -b reports the same error (plus parentID on the assistant message).

The import on line 7 also brings the whole renderer .tsx into a test file that so far only covered row-building. Under the package's bun test src (no browser conditions), that import causes an unhandled error, and the other 62 tests in this file stop running.

The test also only checks the small pinTimelineRow helper, not the cleanup path that crashed. I'd drop it, or rebuild rowByKey from rows and move it, together with pinTimelineRow, somewhere that doesn't import the renderer (e.g. timeline-row.ts).

const value = row()

if (!Predicate.isTagged(value, "UserMessage")) throw new Error("Expected a user-message timeline row")
if (Predicate.isTagged(value, "UserMessage")) last = value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once Row passes pinTimelineRow(props.row, key), a branch only ever sees rows with its own key, and the key includes the tag. So this 'keep the last matching row' fallback, repeated in every branch, can no longer be reached. What it does change is that a real invariant violation would now be silently hidden instead of throwing. I checked that the virtualizer change and the Row pinning each fix the crash on their own. I'd keep the original throws in these current() helpers so the fix stays minimal.

@ElNeMeR70
ElNeMeR70 force-pushed the fix/timeline-row-type-change-62800 branch from bde3f1c to af1f6a2 Compare November 9, 2026 18:30
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are addressed. The regression test now builds its key map from rows and only imports TimelineRow.pin from timeline-row.ts, so it passes and the rest of the file runs again. The strict tag checks in each branch's current() are back, and the fix now relies on Row pinning each keyed branch to its own row.

I re-ran my component test, compiled with Solid's real compiler. A growing steer user-message row has its key removed while an assistant-part row takes the same index. On the base it still throws Expected a user-message timeline row; with this PR there's no error. bun test src/timeline in packages/session-ui passes, and tsc -b printed no errors for packages/session-ui or packages/app.

Public API: unchanged.

No new concerns.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

desktop: fatal 'Expected a user-message timeline row' when a virtualized row changes type

1 participant