Skip to content

perf(native-chat): window a bot chat's long runs of item notes - #45737

Merged
AmethystLiang merged 5 commits into
mainfrom
AmethystLiang/fix-react-185-crash
Nov 20, 2026
Merged

AmethystLiang merged 5 commits into
mainfrom
AmethystLiang/fix-react-185-crash

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When a bot posts many short status notes in a row, the chat drew all of them at once, even the ones far off screen. Now it draws them in small groups, so only the groups near what you're looking at are on the page.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​271
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​271 $\color{#cf222e}{\Huge{\mathbf{−}}}$​50 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​221

What Changed

  • Before: consecutive quiet item notes in a bot chat joined one transcript row with no size limit. A busy bot's hidden quiet turns join its notes across turns, so a long run became one huge virtual row: 400 notes mounted together (about 10k DOM nodes, each line with its own ResizeObserver), whatever was on screen.
  • After: a run splits into rows of at most 8 notes (MAX_NATIVE_CHAT_ITEM_NOTE_CLUSTER), counted from the run's first note, so a new live note only changes the last row. The virtualizer mounts only the rows near the view.
  • Spacing: notes still look the same, 4 px apart. A row that continues a run is created with followsNotes and pulls itself up into the row gap (-mt-4), and its height estimate subtracts that amount. A row never changes shape after it is drawn, so measurements the virtualizer keeps stay valid. The full gap stays where an approval card or the "New" marker sits between two rows, and on rows that fade out whole.
  • Jumps: a jump to a continuing row lands on its first note, not 16 px below it (nativeChatRowDrawnAbove). It still targets the row's index, with the virtualizer's start padding set to what the row draws above its top, so the landing is re-resolved as rows above it get measured.
  • Rows outside the window (a group turn, rows after the live turn) join a run's rows by the same rule (nativeChatSlotJoinsNotesAbove).
  • Housekeeping: the retired-measurement compaction effect moves unchanged into use-native-chat-retired-measurements.ts, so the window hook stays within the file-size limit.

Why

The unbounded row made the bot-chats view mount and measure a whole run at once. That is the cost behind a React #185 crash report from the bot-chats sidebar. The render-loop driver itself was fixed separately in #44647. Fixed-size blocks keep the change inside the existing slot model: no new virtualization layer, and no row is reshaped after it has been measured. We considered having the previous row shrink itself when a ninth note arrives, but that changes a row that has already been measured, so each row now sets its own top margin when it is created.

Checked against how comparable products handle this.

Linked Issue

No public issue; this comes from an internal crash report.

Visual Proof

N/A. Nothing is meant to look different: notes stay 4 px apart, and the change is only in which rows are mounted. The Chromium fixture spec measures the spacing.

Testing

  • pnpm check:changed: all 34 checks pass (format, oxlint, typecheck node + web, unit tests, ratchets, localization, import boundaries).

  • native-chat-bot-item-note-clusters.test.ts: splitting at 8, live-note stability (earlier rows don't change), followsNotes and the height estimate, and the join rules (approval card, "New" marker, rows that fade out whole).

  • tests/component-fixtures/native-chat-note-run.spec.ts (Chromium): an 18-note run rendered through the group-turn / post-live-turn stack measures 4 px between every pair of notes, including across row boundaries. With an approval card between two rows, the full 20 px row gap is kept. Run it with ORCA_BACKGROUND_LAUNCH=1 pnpm exec playwright test --config tests/component-fixtures/playwright.config.ts native-chat-note-run.

  • use-native-chat-viewport-align.test.ts: a jump lands on a continuing row's first note; other rows land by their own top. With a real virtualizer, the landing follows the row when a row above it is measured before the jump settles.

  • The added unit and Chromium tests fail when run against main (or with the pull-up removed).

  • I manually tested these changes locally (covered by the component tests above; a live link-click jump wasn't exercised by hand)

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

  • Mount cost: bounded. A note run used to mount O(n) notes, with a ResizeObserver per line, as soon as any part of it was in view. Now it mounts at most 8 notes per row in the overscan range, so a 400-note run drops from about 10k DOM nodes to a few hundred.
  • Clustering pass: still a single O(n) pass over the slots, with one extra comparison per note.
  • Join check: nativeChatSlotJoinsNotesAbove runs per rendered row. It looks at the previous slot and its notes' timed rows, which is at most 8 map lookups.
  • Jumps: nativeChatRowDrawnAbove adds two getBoundingClientRect reads, only on a jump to a row's start. When a jump's padding differs from the last one, one state update re-renders the window.
  • Reflow: live notes only change the last row, so streaming doesn't invalidate earlier measurements.
  • No new timers, subscriptions or IPC.

Risk

Level: Low. Renderer-only and limited to bot-chat item-note rows. The riskiest part is the spacing at the boundary between two rows of a run: if the pull-up didn't apply, users would see a slightly larger gap (20 px instead of 4 px) every 8 notes. A jump to a continuing row is the other edge case. A plain revert backs it out; no saved data or settings are involved.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Renderer layout only: no platform, SSH, mobile or persisted-state impact.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out

Consecutive quiet item notes joined one transcript slot with no bound, and
a busy bot's hidden quiet turns join its notes across turns, so the window
mounted the whole run at once (400 notes: about 10k DOM nodes, each line
with its own ResizeObserver). Split a run into slots of 8 notes; a slot the
next one continues draws 1rem shorter, keeping the notes 4 px apart.
A slot that carries on a run of notes now closes the row gap with its own
top margin, set when it is made, instead of the slot before shortening
itself once a ninth note arrives. A slot never changes shape after it is
drawn, so a measurement the window keeps for it stays true. The gap stays
whole where an approval card or the New marker sits between two slots, or
while the row fades out whole.
…join slots outside the window

A slot that carries on a run of notes draws 16 px above its own top, so a
jump to it now lands by what it draws rather than by its top. Rows drawn
outside the window (a group turn, rows after the live turn) join a run's
slots by the same rule as the window.
…mium

The spacing between two slots of a long note run is layout, which
happy-dom does not compute, so the class-name checks move to a component
fixture spec that measures each note's distance from the next: 4 px
across slot boundaries, and a full row gap below an approval card.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Note runs are split into slots of up to eight notes. Continued slots carry a flag and can join the preceding row when the specified conditions permit. Transcript rendering applies the corresponding row spacing, and start-edge alignment accounts for content drawn above a row. Retired measurement cleanup is handled by a dedicated hook. Tests and fixtures cover clustering, row joining, alignment, and note spacing around an approval card.

Merge Risk: Minimal · up to e5f08

This change splits long runs of chat notes into bounded rows so the transcript mounts far fewer DOM nodes, and it keeps jump-to-row alignment correct for rows pulled up under the preceding notes. The earlier jump-alignment concern is addressed with an index-based target and a test. No actionable merge-blocking risk remains in the reviewed evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf(native-chat): window a bot chat's long runs of item notes" matches the main change. The PR splits long runs of consecutive quiet notes into bounded rows of at most 8, so only nearby ro…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template closely: it has ELI5, What Changed, Why, Visual Proof (N/A with reason), Testing with checkboxes, Risk with level, and Checklist. It also includes a Performance se…
Full details: Title check

Explanation

The title "perf(native-chat): window a bot chat's long runs of item notes" matches the main change. The PR splits long runs of consecutive quiet notes into bounded rows of at most 8, so only nearby rows mount. The title is specific, concise, and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the template closely: it has ELI5, What Changed, Why, Visual Proof (N/A with reason), Testing with checkboxes, Risk with level, and Checklist. It also includes a Performance section and an Agent skill boundary checkbox. Gaps: the Linked Issue section says there is no public issue and does not link one, though the template requires a link for outside contributors. The Risk section does not clearly state how to back out beyond a plain revert, and the AI Disclosure section is left blank. The Testing section also says a live link-click jump was not exercised by hand, which is a partial gap. The description is detailed and mostly complete, so it passes overall, but the linked issue gap should be noted.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 47b30c49-8ae3-49a9-947a-c1c5fc570f33
Commits

Reviewing files that changed from the base of the PR and between 3ac3ced and e5f0874.

Files selected for processing: 4

  • src/renderer/src/components/native-chat/viewport/virtualization/use-native-chat-retired-measurements.ts
  • src/renderer/src/components/native-chat/viewport/virtualization/use-native-chat-transcript-window.ts
  • src/renderer/src/components/native-chat/viewport/virtualization/use-native-chat-viewport-align.test.ts
  • src/renderer/src/components/native-chat/viewport/virtualization/use-native-chat-viewport-align.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4ea2c3bc-9f19-48ed-8e3f-b7c6c1720355
Commits

Reviewing files that changed from the base of the PR and between fc29c3d and 3ac3ced.

Files selected for processing: 9

  • src/renderer/src/components/native-chat/bot-items/native-chat-bot-item-note-clusters.test.ts
  • src/renderer/src/components/native-chat/bot-items/native-chat-bot-item-note-clusters.ts
  • src/renderer/src/components/native-chat/conversation/slots/native-chat-transcript-slots.ts
  • src/renderer/src/components/native-chat/messages/rows/NativeChatTranscriptRow.tsx
  • src/renderer/src/components/native-chat/viewport/virtualization/NativeChatTranscriptItems.tsx
  • src/renderer/src/components/native-chat/viewport/virtualization/NativeChatTranscriptRowStack.fixture.tsx
  • src/renderer/src/components/native-chat/viewport/virtualization/use-native-chat-viewport-align.test.ts
  • src/renderer/src/components/native-chat/viewport/virtualization/use-native-chat-viewport-align.ts
  • tests/component-fixtures/native-chat-note-run.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

A jump to a slot that carries on a run of notes scrolled to a fixed
offset, so rows above it measured before the jump settled moved the
slot away from where it landed. It now targets the row's index like
every other jump, with the virtualizer's start padding set to what the
row draws above its top, so the virtualizer re-resolves the landing as
measurements arrive.

Moves the retired-measurement compaction into its own hook to keep the
window hook within the file-size limit.
@AmethystLiang
AmethystLiang merged commit a93ceb3 into main Nov 20, 2026
56 checks passed
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.

1 participant