Skip to content

fix(chat): long chat sessions scroll at a few frames per second - #159294

Merged
steipete merged 2 commits into
mainfrom
steipete/choppy-scrolling-perf-90c135
Sep 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/choppy-scrolling-perf-90c135

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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 renderChat rebuilds 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 stable page.items reference 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 on pendingInputs.

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 from PerformanceObserver.

Synthesized scroll gesture (Input.synthesizeScrollGesture) Before After
Frames in window 40 in 10.1 s (~4 fps) 316 in 6.3 s (~50–60 fps)
Median / p95 / max frame 200 / 767 / 1,117 ms 16.7 / 33 / 50 ms
Long tasks 9.8 s 0
History paged in during a 20 s scroll up 3,072 messages (stalled) all 6,947

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.

  • Regression test (chat-thread-input-order.test.ts): a render that rebuilds pendingInputs with 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.
  • Regression test (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.
  • Async-question tests now replace the history array between steps (as the Gateway state does) instead of pushing into it.
  • 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.
  • Test cost: the new test runs in ~1 ms; chat-thread-input-order.test.ts wall ~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.

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

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 27, 2026 01:09
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 9:42 PM ET / September 27, 2026, 01:42 UTC (Revision 2).

ClawSweeper review

What this changes

The PR changes Control UI chat caches to reuse transcript work during scrolling and refresh question reminders after live run outcomes.

Regression provenance

Possible 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
Reviewed head: f3f908bcf358b884f92b5385eee31e11c637eca8

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Detailed before-and-after browser measurements, focused regressions, and a repair of the prior review finding support an above-average review result.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed Control UI transcript caches were exercised through Chromium scrolling and older-history paging with a real 6,947-message transcript served by a mocked Gateway; the PR reports improved frame timing and complete paging after the fix. The changed caches are in memory, so stored-data compatibility is not applicable.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed Control UI transcript caches were exercised through Chromium scrolling and older-history paging with a real 6,947-message transcript served by a mocked Gateway; the PR reports improved frame timing and complete paging after the fix. The changed caches are in memory, so stored-data compatibility is not applicable.
Evidence reviewed 10 items Current-main defect: Current main compares pending-input arrays by identity, while the chat view builds a fresh displayed list on each render.
Rendered input path: The chat view derives the pending-input list and passes it to transcript rendering.
Introduced cache repair: The PR compares pending-input entries while retaining the existing identity checks for other structural inputs.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +44, Tests +54. Total +98 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 60 16 +44
Tests 2 63 9 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 123 25 +98

Review metrics

Metric Value Why it matters
Measured scroll rate About 4 fps → 50–60 fps with 6,947 messages The contributor's browser comparison measures the affected long-session flow.
Production and test lines production +60/−16; tests +63/−9 The PR body explains the production growth as two renderer memos and terminal invalidation.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed Control UI transcript caches were exercised through Chromium scrolling and older-history paging with a real 6,947-message transcript served by a mocked Gateway; the PR reports improved frame timing and complete paging after the fix. The changed caches are in memory, so stored-data compatibility is not applicable.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Long, tool-heavy conversations become difficult to scroll and may stop loading older history.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed Control UI transcript caches were exercised through Chromium scrolling and older-history paging with a real 6,947-message transcript served by a mocked Gateway; the PR reports improved frame timing and complete paging after the fix. The changed caches are in memory, so stored-data compatibility is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed Control UI transcript caches were exercised through Chromium scrolling and older-history paging with a real 6,947-message transcript served by a mocked Gateway; the PR reports improved frame timing and complete paging after the fix. The changed caches are in memory, so stored-data compatibility is not applicable.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-27T01:17:13.681Z sha 2eb70e8 :: blocked before merge. :: [P2] Invalidate question history after a sideband terminal update

@steipete steipete self-assigned this Sep 27, 2026
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.
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@steipete
steipete merged commit 4bf459b into main Sep 27, 2026
123 of 125 checks passed
@steipete
steipete deleted the steipete/choppy-scrolling-perf-90c135 branch September 27, 2026 02:13
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…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.
steipete added a commit that referenced this pull request Sep 27, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant