Repository navigation
fix(chat): long chat sessions scroll at a few frames per second - #159294
Conversation
Every virtualizer range change re-renders the chat pane. renderChat derives the displayed pending-input list as a fresh array per render (since #157135), and the chat-item cache compared it by identity, so every scroll frame rebuilt chat items for all loaded history (tool cards, JSON parsing, schema validation). A 7k-message session scrolled at 4-8 fps and older history paging stalled. Compare pending inputs entry-wise (immutable Gateway records) and memoize the two remaining per-render history scans (async-question history and the user-identity index in selectChatInputDisplay) per transcript array.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 9:42 PM ET / September 27, 2026, 01:42 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR changes Control UI chat caches to reuse transcript work during scrolling and refresh question reminders after live run outcomes. Regression provenancePossible regression — probable (failure trace; known regression link). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Current main still has the scroll-driven cache miss. The latest commit resolves the stale-reminder finding from the prior review, and the supplied browser measurements support the performance fix. I found no remaining actionable patch defect. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway supplies message history and pending inputs to the Control UI chat pane. The pane turns them into visible rows and reminders while scrolling requests older history pages. flowchart LR
A[Gateway history pages] --> B[Chat view inputs]
C[Live run outcomes] --> B
B --> D[Transcript projections]
D --> E[Cache freshness check]
E --> F[Visible rows and reminders]
F --> G[Scrolling and older pages]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +44, Tests +54. Total +98 across 6 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the Gateway as transcript owner and invalidate renderer caches when their message arrays, pending-input records, or live terminal metadata change. Do we have a high-confidence way to reproduce the issue? Yes. The contributor measured the baseline failure in Chromium with a 6,947-message transcript, and current-main source still contains the array-identity miss; this reviewer did not rerun the browser scenario. Is this the best way to solve the issue? Yes. The patch repairs invalidation in the Control UI's existing projection caches without changing Gateway paging or the stored transcript. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c207efc0680c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Message-less aborts and errors record their outcome beside an already published history array (rememberLiveTerminalRun), so an array-keyed question-history memo could keep a reminder pending after the originating run settled. Key the memo on a live-terminal revision bumped by that owner.
|
Merged via squash.
|
…claw#159294) * fix(chat): restore smooth scrolling in long chat sessions Every virtualizer range change re-renders the chat pane. renderChat derives the displayed pending-input list as a fresh array per render (since openclaw#157135), and the chat-item cache compared it by identity, so every scroll frame rebuilt chat items for all loaded history (tool cards, JSON parsing, schema validation). A 7k-message session scrolled at 4-8 fps and older history paging stalled. Compare pending inputs entry-wise (immutable Gateway records) and memoize the two remaining per-render history scans (async-question history and the user-identity index in selectChatInputDisplay) per transcript array. * fix(chat): rescan question history after live terminal outcomes Message-less aborts and errors record their outcome beside an already published history array (rememberLiveTerminalRun), so an array-keyed question-history memo could keep a reminder pending after the originating run settled. Key the memo on a live-terminal revision bumped by that owner.
…up (#159562) While a new session's first turn waits on a workspace or cloud worker (including after a failed or uncertain startup), every chat pane render rebuilt all loaded history and re-rendered every mounted transcript row. renderChat appended the retained startup turn to the queue as a fresh array each render, and both placement getters rebuilt that turn on every get(), so the identity-keyed chat-item cache always missed. The initial-turn producer now returns its previous item while content is unchanged, and renderChat reuses the appended queue until the outbox publishes a new array or the turn changes. The queue keeps identity semantics because queued items are edited in place before publish. The pane also passed a fresh Retry closure per render; chat view forwards it as the queued-turn action, a shared row-render dependency. The pane now owns one stable callback that retries its current session when invoked, still only while the startup is retryable. Introduced by #131594. Same class as #159294.
…up (openclaw#159562) While a new session's first turn waits on a workspace or cloud worker (including after a failed or uncertain startup), every chat pane render rebuilt all loaded history and re-rendered every mounted transcript row. renderChat appended the retained startup turn to the queue as a fresh array each render, and both placement getters rebuilt that turn on every get(), so the identity-keyed chat-item cache always missed. The initial-turn producer now returns its previous item while content is unchanged, and renderChat reuses the appended queue until the outbox publishes a new array or the turn changes. The queue keeps identity semantics because queued items are edited in place before publish. The pane also passed a fresh Retry closure per render; chat view forwards it as the queued-turn action, a shared row-render dependency. The pane now owns one stable callback that retries its current session when invoked, still only while the startup is retryable. Introduced by openclaw#131594. Same class as openclaw#159294.
What Problem This Solves
Fixes: scrolling a long chat session in the Control UI drops to a few frames per second (and older history stops paging in) once a few thousand messages are loaded.
User Impact
User impact: long, tool-heavy sessions scroll smoothly again, and scrolling up keeps loading older history instead of stalling behind blocked frames.
Why This Change Was Made
Every scroll step that changes the visible rows re-renders the chat pane. The transcript item cache is supposed to make that cheap, but
renderChatrebuilds the displayed pending-input list as a fresh array on every render, and the cache compared it by identity. Since #157135 started showing queued inputs (it replaced the stablepage.itemsreference with that derived list), every scroll frame missed the cache and rebuilt the chat items for every loaded message: tool-card extraction, JSON argument parsing, and schema validation. Instrumenting a real session showed 322 misses vs 6 hits while scrolling, all onpendingInputs.The cache now compares the pending-input list entry by entry; its entries are Gateway records that are never mutated in place. The queue keeps its identity check, because outbox snapshots reuse queue items whose send state can change in place. Two other per-render scans over the whole history (async-question reminder history and the user-identity index used to hide already-delivered inputs) are memoized per history array; history arrays are replaced on change, never mutated, which is the same invariant the item cache already relies on for
messages. Live terminal outcomes from message-less aborts and errors are recorded beside an already published array, so the question-history memo also keys on a revision bumped by that owner (found by ClawSweeper review).Evidence
Reproduced locally with the real 6,947-message transcript from the affected session, served through the mocked Gateway with production paging (80-message startup page, 1,000-message older pages), in the bundled Control UI E2E harness (Chromium, 1440×900). Frame intervals from
requestAnimationFrame, long tasks fromPerformanceObserver.Input.synthesizeScrollGesture)Steady wheel scrolling through already loaded history: median frame 133 ms → 16.7 ms; long tasks 10.9 s → 0.7 s per 10 s.
CPU profile before the fix: 87% of scroll time was inside
projectChatTranscript→buildCachedChatItems→buildChatItems(tool activity coalescing,extractToolCards, JSON coercion, TypeBox validation). After the fix, chat item building no longer appears in the scroll profile.The live session on team.openclaw.ai showed the same symptom before this change: with ~3,000 messages loaded, p95 frame 199 ms, max 1.2 s, 5.7 s of long tasks across eight scroll bursts.
chat-thread-input-order.test.ts): a render that rebuildspendingInputswith the same entries must reuse the cached items without reading loaded messages. It fails on the previous code (items rebuilt, 145 message reads) and passes now.chat-async-question.test.ts): a reminder from run-1 retires once a message-less terminal settles run-1's published partial behind a later successful run-2. It fails with an array-only memo and passes with the revision key.node scripts/check-changed.mjs(format, ratchets, i18n, typecheck graphs), oxlint on changed files, and all 56 UI test files importing the changed modules (2,337 tests).pnpm ui:check-performance:base: startup JS stays inside the growth limit (370,957 B vs 371,268 B); startup CSS unchanged.chat-thread-input-order.test.tswall ~1.5 s with--maxWorkers=1.Production lines: +60 / −16 (the entry comparison also replaces the inline copy in
stabilizeChatItems). Not LOC-neutral: the two memos and the terminal revision add small caches; I found no dead code nearby to offset them.Known remaining costs, not addressed here: the position rail's per-frame layout sync forces a style/layout pass, and hover changes under a scrolling pointer trigger ancestor
:has()restyles of the whole document; both are well inside frame budget after this fix on the test transcript.