Repository navigation
fix(chat): stop redrawing settled chat rows on every streamed chunk - #20641
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Check in a live crewmate DM that settled rows (reply footer, "Steered" chip, Resume button, "Last reply" age) still update while a reply streams. [UX-REVIEWED] 85a1846 Description read[DESCRIPTION-READ] 1654af26f8fb71ded86394c471bd359029a8771d8b181a315fdd122aa04c91ac That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merge, confirm no shipped App Kit renderer reads a streaming neighbour's text: under the new [DESIGN-REVIEWED] 85a1846 Description read[DESCRIPTION-READ] 33c75b13694f27e26582b17a3a2e26f829d69df1b5387adbdb907f504127a281 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check one thing before merge: App Kit renderers that read a streaming neighbour's text will no longer redraw while it grows (now documented in What this change shipsInventory (6 items) — 6 justifiedIntent: A crewmate chat (and any
[FIRST-PRINCIPLES-REVIEWED] 85a1846 Description read[DESCRIPTION-READ] c64db661d0eea1baf186e457dd7ad228002c5a55a79cbf96105e8a8a6ccc6614 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
e00b4fc to
b421982
Compare
|
HOLD at b421982. The approach reads as sound. Rows get their previous object back from the reconcile, and the renderers move only with a transcript version that changes on every list change except a streaming row growing in place (transcriptVersion.ts L30-L53). The footer gets its own one-minute clock. The new tests cover the in-place updates the memo could have frozen. Blockers:
To clear: CI and GPT 6.1 finish green on this head, and items 2 and 3 get dispositions. — crew-pr-reviewer (r103) |
b421982 to
d9a7690
Compare
d9a7690 to
b23f312
Compare
Dispositions. Everything below is on the current head, 1. CI and GPT 6.1 on this head: done. GPT 6.1 Review passed at 09:36:17Z, and PR Readiness reported success at 10:09:04Z, both on 2. First Principles item 5: done in 3a. Design: no bundled renderer reads a streaming neighbour's text through
The rest of the list's reads are covered too:
3b. UX: a live crewmate-DM check shows the footer, the Steered chip and the Last reply age all update while a reply streams. Setup:
The expected behaviour comes from the code and the matching
The one difference in every comparison comes from the data, not from the rendering. In the live tab's store, the reply part above a steer is the client's settled copy of the streaming row. That copy has no In one earlier run, the live copy was also 6 characters shorter than the server's row. That run's turn-end redraw of every row left it unchanged, so those characters were missing from the store, not just from the screen. This PR does not change the store. |
|
HOLD (reviewed b23f312). The code is ready, but the green is stale. #20756 merged into main after this head's CI ran, and it edits four of this PR's files: Our r103 blockers are cleared on this head:
The design is sound. Rows get their previous objects back, and renderers move only with a transcript version that ignores nothing except a streaming row growing in place. The one public-contract narrowing for App Kit renderers is documented. All AI lanes pass, and no change request is open. I can't promise approval of the rebased head before seeing it. Optional: the live check found an older store gap, where the client's settled copy above a steer lacks — crew-pr-reviewer (r104) |
b23f312 to
da4b64b
Compare
da4b64b to
a22dc5a
Compare
The crewmate DM, split panes and the app-SDK embed draw their transcript through ChatMessageList's virtualized mount. Every streaming flush minted a new object for every grouped row and a new render function closed over the new message list, and every keystroke in the composer re-rendered the mounted rows too. So each chunk of a reply rendered every message on screen again: on a 10-second reply in a crewmate DM that was about 3.4 s of React render time. A settled row now gets its previous object back (createDisplayItemReconciler, which ChatPage's createTurnGrouper now calls too, so the substitution loop exists once) and is a memoized ListRow. The row renderers read the message list through a view that changes only with the transcript version, so their identity changes only when something a row can read changes: the host's props, the running flag, or the version, with every input checked by exhaustive-deps. The version moves on every change to the message list except a streaming row's text growing, which no other row reads; a row re-minted as an equal copy does not move it either. ListRow subscribes to language switches itself, and ThreadFooter redraws its "last reply" age once a minute. ChatPane hands the crewmate rows the unfiltered transcript as a getter keyed on the same version, and the crewmateTranscript option now takes only a getter, so the renderer set is no longer rebuilt per chunk. The API reference states the one rule this asks of an app's renderer: read a streaming neighbour by its role, not its text. Fixes #20518
…ply streams Main now hands the newest error row its Resume state (continuable, interrupted, continuing, onContinue), and those values sit in the memo that builds the pane's row set. Row reuse holds only while that set keeps its identity, so add a case that runs the real Resume hook in a crewmate chat: typing under an offered Resume, and streaming a resumed reply, must not rebuild the row set or redraw a settled row. Making onContinue a fresh function per render turns both cases red. Also follow the tool pill's ok colour, now text-ok-text on main.
a22dc5a to
85a1846
Compare
Reply to r104. Rebased. New head 2a. Resume in the renderer memo. New
The four Resume values are stable while a reply streams: 2b. Reverse mutation. Making 2c. Resume itself. #20756's own specs pass on the merged tree: 2d. #19903 ( Locally on the merged tree: On |
buluoray
left a comment
There was a problem hiding this comment.
Reviewed at 85a1846. The memo boundary is sound: every input a reused row can read either sits in the renderers' deps (running, host props) or moves the transcript version, and the one exception the version skips — a streaming row's text growing — is read by role only in every built-in rule I traced: the reply footer loop (messageRenderers.tsx:537-545, isHiddenInvisibleAssistantRow/isSystemNoticeRow both return false for streaming), answeredAfter, turnHadPolicyBlock, sessionStartFailureStreak, contextOverflowIsNewest, and crewmateRunPosition (isCrewmateSpeech is true for any streaming row). The streaming row itself still redraws because the reconcile hands it a new item.
Verified locally: the 8 touched/related suites pass (81 tests) plus the two groupDisplayItems suites (39). Mutations, each run alone and restored: versioner never moving (5 named reds), treating every changed row as unchanged (2), dropping useLanguageGeneration in ListRow (1), dropping the ThreadFooter tick (1), disabling the reconciler (2).
Non-blocking: the documented contract for app renderers (read a streaming neighbour by role, not text) is now load-bearing for third-party renderers; nothing enforces it, so a renderer that breaks it would show a stale row rather than fail. Fine as documented.
Problem / Motivation
Goal: A crewmate chat stops re-rendering every message on screen for each streamed chunk and each keystroke, while every row that changes in place keeps changing.
In a crewmate DM (Crewmates page), every streaming flush re-rendered every mounted transcript row, and so did every keystroke in the composer.
ChatPanehandedChatMessageLista new renderer set per flush, the grouping minted a fresh object for every row, and each row's render function closed over the new message list, so no row could bail out. On a 10-second reply this was about 3.4 s of React render time, with the main thread 63-70% busy.Why it matters
Everyone who chats with a crewmate pays it, whatever dashboard page or template they use; split panes and the app-SDK embed draw through the same list. On a fast machine it shows as CPU use and heat. On a slower one it becomes typing lag: with the page CPU throttled 4x, a keystroke typed while a reply streams took 161 ms to reach the screen at p95, and a 10-second reply produced 116 long tasks (7.7 s in total).
Not a goal
ChatPage), which already reuses its rows throughcreateTurnGrouper.What changed (motivation -> approach -> change)
Symptom -> cause. Profiling the DM showed
UserMessage,AssistantMessage,CrewmateMessageandTurnBlockrendering several times per chunk for rows that had not changed. Three things defeated every memo boundary under the list: the grouping returned new objects for every row on each flush, the row render function was rebuilt on each flush because it readsmessages, andChatPanerebuilt its whole renderer set per flush because it passed the unfiltered crewmate transcript as an array.Change.
pages/chat/groupDisplayItems.ts:createDisplayItemReconciler()hands a row its previous object when it describes the same message references.createTurnGrouper(the main chat page) now calls it instead of keeping its own copy of that loop, and keeps only its own "every row was reused" check; its output is unchanged.app-sdk/ChatMessageList.tsx: virtualized rows render through a memoizedListRow(no DOM of its own). The row renderers read the message list through a view that changes only with the transcript version, so their identity moves only when something a row can read moves: the host's props,running, or the version. Every other input they close over stays in their own dependency arrays, checked by exhaustive-deps; the list is read through a ref, so a row that does render sees the newest messages.chat-core/transcript/transcriptVersion.ts: the version moves on every change to the message list (a row lands or leaves, a reorder, a role change, any edit to a settled row, history loaded above) except astreamingrow's text growing, and a row replaced by an equal copy. Every built-in rule that looks at other rows (reply footer, steer chip, transient notice tense, crewmate run position, error-card scans) reads a streaming row by its role only, so that one change cannot alter another row's output.ListRowcallsuseLanguageGeneration(), so a language switch redraws reused rows, footer dates included.pages/chat/ThreadFooter.tsx: redraws its "Last reply 2h ago" once a minute. Before, any flush redrew it; a reused row no longer does.components/ChatPane.tsx,components/ChatPaneTranscript.tsxandpages/chat/transcriptRenderers.tsx: the crewmate transcript is handed as a getter whose identity follows the same version, so the renderer set is rebuilt only when the unfiltered rows change. ThecrewmateTranscriptoption now takes only a getter;ChatPaneis its one caller.docs/app-kit/api-reference.md+MessageRenderContext.messages: the rule an app renderer must follow: read a streaming neighbour by its role, not its text.Before -> after, measured in Chromium 145 (headless, 1600x1000) on a crewmate DM with a synthetic 1,667-row transcript and a fake backend streaming 500 chunks over about 10 s. The numbers come from an earlier cut of this change. It behaves the same as this head while only the streaming row grows; this head also redraws every mounted row when any other row changes.
UserMessagerenders per chunk / per keystrokeWith the dashboard tab open, React render time for the same reply went 3581 -> 2507 ms (-30%). On an unthrottled fast machine, keystroke latency barely moves (main-thread part 26 -> 25 ms); the gain there is CPU. Samples: 1 profiling run per cell, 2 throttled runs per cell.
Backwards compatibility
Compatible: the row DOM, every prop of
ChatMessageListandMessageRenderContextare unchanged.crewmateTranscript, an option of the dashboard's own row set (not App Kit API), now takes a getter where main took an array. Its writers on origin/main @ 10b7fa7 (which includes #20756 and #19903) arecomponents/ChatPane.tsxand two tests, all switched to the getter here; tsc finds no other. One rule is now written down for app renderers: a renderer that reads the text of astreamingrow other than its own is not redrawn as that text grows. No built-in renderer does.Removes nothing: no prop, row or behaviour is taken away; the one option whose type changed keeps every caller working (above); settled rows redraw on fewer occasions, and every occasion that can change a row's output still redraws it.
Tests
ChatMessageList.inPlaceRows.test.tsx(new, 11 cases, real row components): while a reply streams below, a settled row still updates for: the reply footer appearing when the turn ends in an error, and moving when a quiet row below is rewritten into words; a replaced message; the steer badge and the reply's "Steered" chip; a tool pill's result and a policy block; the thread footer's count, and its "last reply" age with nothing else changing; a language switch; a theme switch (a reused row's markup equals a freshly mounted one); earlier history loaded above, including a block that holds only an undrawn row; a change card following the card store.ChatPane.crewmateRunReuse.test.tsx(new, 2 cases, realChatPaneand store frames): a crewmate run's corners and footer regroup as a reply joins, streams and settles; a run ended at a patrol wake that the chat does not draw keeps its corners and footer while the next turn streams.ChatPane.crewmateResumeReuse.test.tsx(new, 2 cases, realChatPane,CrewComposerand the realuseChatPaneContinue): fix(chat): offer Resume in a crewmate's chat after a turn ends on a model error #20756 put the error row's Resume state (continuable,interrupted,continuing,onContinue) into the memo that builds the row set. Typing under an offered Resume, and streaming a resumed reply while typing, build no new row set and redraw no settled row; pressing Resume still redraws the error row (its button disables) and the turn starting removes it.ChatMessageList.rowIdentity.test.tsx(new): a flush that only grows the streaming row does not re-render a settled row; a row appended below still updates the settled row's footer.transcriptVersion.test.ts(new): what moves the version and what does not.createTurnGrouperreds 3 of its structural-sharing cases; makingonContinuea fresh function per render reds both Resume reuse cases.AppSdkMessageRenderersCov80,ChatEmbed.approvalRollback,CollapsibleToolGroupCov80,ChatEmbed.stop,useStopPress) (ChatPane.crewmateResume,useContinuePress,chatSlice.slotResume,ChatPane.featureRequestFallback,useChatPageTurnRecovery) and the new Resume reuse spec, plus everyChatPane.*,ChatEmbed.*,SideChat.*,ChatMessageList.*,MembersPage.*,TurnBlock.*,transcriptRenderers.*,messageRenderers.*andgroupDisplayItems.*spec, pluschatCoreTranscript.contract,ChatPane.owners,MemoI18nSubscriptionRatchet,VirtualTranscript,CrewChatWindowandThreadFooter, and everyChatPagespec, since the main chat page's grouper now runs the shared reconcile.tsc -p tsconfig.app.jsonandeslint --max-warnings 0on the changed files are clean. The cross-surface set the doc change pulls in runs in CI on the merge ref.Manual verification
The before/after numbers were taken in a real browser on the earlier cut described above. This head is covered by the component tests above (happy-dom), not re-measured in a browser.
Screenshots / video
Why no screenshot: Rows render the same DOM as before; only how often a settled row re-renders changes, and a test checks that a reused row's markup equals a freshly mounted one.
Related Issues
Fixes #20518
Pattern harvest
Rule candidate: review-prompt
Pattern: a memoized list row whose render reads its sibling rows must redraw on every sibling change it can read (a whole-list version), never on a hand-picked subset such as the list length or the last row's role.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.
Inherited CI red (main breakage, not this PR): test/test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them
Failing on main run e492fda (2026-10-15); this PR does not touch that file. Will rebase onto origin/main once main carries a fix.