Repository navigation
perf(ui): keep chat render state alive across session switches - #115059
Conversation
Retain bounded per-session chat items and virtualizer measurements, avoid redundant tool-card walks, and reduce markdown cache churn during rapid switching. User-visible behavior: switching back to a session now restores its prior reading position while end-anchored sessions continue following the latest message.
|
Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 4:08 AM ET / 08:08 UTC. ClawSweeper reviewWhat this changesRetains bounded per-session chat item, virtualizer, markdown, and scroll state so switching back to a Control UI session avoids transcript reflow and restores the prior reading position. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 5 items remain Keep this PR open: it proposes a meaningful Control UI behavior change, but the available evidence is test-only and the deliberate switch-back scroll behavior still needs maintainer confirmation and real after-fix proof. Priority: P2 Review scores
Verification
How this fits togetherThe Control UI loads a session transcript, projects it into chat items, and renders it through a virtualized transcript. Session navigation currently resets transient presentation state; this PR retains selected per-session render and viewport state before the transcript is shown again. flowchart LR
A[Session selection] --> B[Chat history load]
B --> C[Per-session item cache]
C --> D[Virtualized chat transcript]
A --> E[Saved viewport state]
E --> D
D --> F[Restored reading position]
D --> G[New-message follow behavior]
Decision needed
Why: The branch intentionally changes a visible default navigation behavior, and tests cannot determine whether that compatibility tradeoff matches the product expectation for existing users. Before merge
Agent review detailsSecurityNone. PR surfaceSource +480, Tests +519. Total +999 across 15 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Mantis proof suggestionA redacted web UI chat interaction would directly demonstrate the proposed session-switch and restored-viewport behavior that tests alone do not prove. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the retention caches bounded, confirm that restored reading position is the intended default for existing sessions, and add redacted live Control UI proof covering A→B→A, new-message arrival while away, and cache eviction. Do we have a high-confidence way to reproduce the issue? Unclear. The PR supplies a concrete A→B→A scenario and targeted browser coverage, but the supplied material does not show an independently observed current-main regression or a live after-fix interaction. Is this the best way to solve the issue? Unclear. Bounded per-session retention is a plausible narrow solution, but changing the default restored-scroll policy requires maintainer confirmation before it can be called the best solution. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 521d05f290c2. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…law#115059) * perf(ui): keep chat render state alive across session switches Retain bounded per-session chat items and virtualizer measurements, avoid redundant tool-card walks, and reduce markdown cache churn during rapid switching. User-visible behavior: switching back to a session now restores its prior reading position while end-anchored sessions continue following the latest message. * chore(ui): drop dead resetChatThreadPresentationState barrel re-export
The width-change path wiped the virtualizer's entire item-size cache (instance.measure()), collapsing every offscreen row to the 120px estimate with no scroll compensation: the reader teleported mid-transcript and the trickle of remeasure corrections made text visibly jump for several frames on every pane or window resize. Keep the stale offscreen sizes as estimates instead. The existing synchronous resizeItem pass plus TanStack's per-row ResizeObserver re-seed connected rows with fold-based scroll compensation, so the anchor row holds still; offscreen rows correct lazily as they connect. End-pinned transcripts keep following the tail via the existing height-change scrollToEnd path. Regression e2e: mid-transcript anchor stays within 60px across 1280->1000->820->1280 resizes (pre-fix: anchor scrolled out of the viewport entirely and scrollTop drifted by 250px+). Wipe introduced in #115059, refined by #117687/#123713 without addressing anchoring.
…24013) * fix(ui): keep the chat transcript anchored while the pane resizes The width-change path wiped the virtualizer's entire item-size cache (instance.measure()), collapsing every offscreen row to the 120px estimate with no scroll compensation: the reader teleported mid-transcript and the trickle of remeasure corrections made text visibly jump for several frames on every pane or window resize. Keep the stale offscreen sizes as estimates instead. The existing synchronous resizeItem pass plus TanStack's per-row ResizeObserver re-seed connected rows with fold-based scroll compensation, so the anchor row holds still; offscreen rows correct lazily as they connect. End-pinned transcripts keep following the tail via the existing height-change scrollToEnd path. Regression e2e: mid-transcript anchor stays within 60px across 1280->1000->820->1280 resizes (pre-fix: anchor scrolled out of the viewport entirely and scrollTop drifted by 250px+). Wipe introduced in #115059, refined by #117687/#123713 without addressing anchoring. * test(infra): deflake ephemeral-port rebind proof under runner contention The bind->release->rebind cycle races foreign processes on shared CI runners: a stolen port between release and rebind fails the assertion (EADDRINUSE, seen on checks-node-compact-large-17). Retry the whole cycle on a fresh ephemeral port, bounded at 5 attempts; a genuine release regression still fails every attempt because the collision is with our own lingering listener. * test: prove port release on the allocated port; add end-pin resize proof Address ClawSweeper review on #124013: - ports-probe: replace the fresh-port retry with a connect probe against the same allocated port. A lingering listener accepts the probe; a released port refuses it. Unlike a rebind, the probe does not collide with foreign outbound sockets that transiently occupy the port on busy runners, so the release contract stays tied to one port with no retry at all. - chat-resize-anchor e2e: add a width-only end-pinned case proving the virtualizer's wasAtEnd compensation keeps the transcript within 2px of the end across 1280->1000->820->1280 resizes. * test(ui): widen resize-anchor drift bound for Linux font metrics The fold-spanning anchor row re-wraps by a renderer-dependent amount (42px macOS, 63px Linux CI at 820px). 120px keeps a wide margin below the pre-fix failure mode (anchor out of viewport, 250px+ drift). * test(tooling): register manager-session-update-race in memory helper routing #124024 added the memory-core test on main without updating the cross-lane routing expectation in test-projects.test.ts, breaking the core-tooling shard on every merge ref that includes it.
…enclaw#124013) * fix(ui): keep the chat transcript anchored while the pane resizes The width-change path wiped the virtualizer's entire item-size cache (instance.measure()), collapsing every offscreen row to the 120px estimate with no scroll compensation: the reader teleported mid-transcript and the trickle of remeasure corrections made text visibly jump for several frames on every pane or window resize. Keep the stale offscreen sizes as estimates instead. The existing synchronous resizeItem pass plus TanStack's per-row ResizeObserver re-seed connected rows with fold-based scroll compensation, so the anchor row holds still; offscreen rows correct lazily as they connect. End-pinned transcripts keep following the tail via the existing height-change scrollToEnd path. Regression e2e: mid-transcript anchor stays within 60px across 1280->1000->820->1280 resizes (pre-fix: anchor scrolled out of the viewport entirely and scrollTop drifted by 250px+). Wipe introduced in openclaw#115059, refined by openclaw#117687/openclaw#123713 without addressing anchoring. * test(infra): deflake ephemeral-port rebind proof under runner contention The bind->release->rebind cycle races foreign processes on shared CI runners: a stolen port between release and rebind fails the assertion (EADDRINUSE, seen on checks-node-compact-large-17). Retry the whole cycle on a fresh ephemeral port, bounded at 5 attempts; a genuine release regression still fails every attempt because the collision is with our own lingering listener. * test: prove port release on the allocated port; add end-pin resize proof Address ClawSweeper review on openclaw#124013: - ports-probe: replace the fresh-port retry with a connect probe against the same allocated port. A lingering listener accepts the probe; a released port refuses it. Unlike a rebind, the probe does not collide with foreign outbound sockets that transiently occupy the port on busy runners, so the release contract stays tied to one port with no retry at all. - chat-resize-anchor e2e: add a width-only end-pinned case proving the virtualizer's wasAtEnd compensation keeps the transcript within 2px of the end across 1280->1000->820->1280 resizes. * test(ui): widen resize-anchor drift bound for Linux font metrics The fold-spanning anchor row re-wraps by a renderer-dependent amount (42px macOS, 63px Linux CI at 820px). 120px keeps a wide margin below the pre-fix failure mode (anchor out of viewport, 250px+ drift). * test(tooling): register manager-session-update-race in memory helper routing openclaw#124024 added the memory-core test on main without updating the cross-lane routing expectation in test-projects.test.ts, breaking the core-tooling shard on every merge ref that includes it.
What Problem This Solves
Switching sessions A→B→A in the Control UI rebuilds session A's entire chat item list, discards every measured row height (visible reflow as the virtualizer re-estimates at 120px then corrects), and always jumps to the end of the transcript. The per-session caches already exist — the switch path deleted them:
resetChatThreadPresentationStatedropped the whole per-pane item map,ChatTranscriptControllerconstructed a fresh virtualizer host per session change, andresetOlderMessagesViewportnulled the scroll position.Why This Change Was Made
Cache retention makes switch-back render from warm state in the same frame instead of rebuilding: stable row identities (no Lit re-stamping), preserved measurements (no reflow), and restored reading position.
User Impact
Switching back to a recently viewed session is instant and visually stable, and it returns to where you were reading instead of jumping to the end (deliberate, user-visible improvement). First visits still anchor to the end; new-message arrival doesn't force-jump a restored viewport.
Evidence
syncToolCardExpansionStateskips the full-transcript walk when the items array identity is unchanged (spy test).