Skip to content

perf(ui): keep chat render state alive across session switches - #115059

Merged
steipete merged 2 commits into
mainfrom
perf/switch-render-caches
Jul 28, 2026
Merged

steipete merged 2 commits into
mainfrom
perf/switch-render-caches

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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: resetChatThreadPresentationState dropped the whole per-pane item map, ChatTranscriptController constructed a fresh virtualizer host per session change, and resetOlderMessagesViewport nulled 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

  • Switch now resets only transient fields (searchOpen/searchQuery, menus/popovers) and keeps per-session item caches; A→B→A reuses built items (build-spy regression) with stable row identities.
  • Bounded 3-host virtualizer LRU inside the controller: inactive hosts disconnect their ResizeObservers, eviction fully disposes refs (leak assertion), pane width change triggers remeasure.
  • Scroll restore: bounded 8-pane × 20-session LRU distinguishing fixed positions from end anchoring; restored sessions skip the forced end-scroll; virtualized late-height case kept locked until the offset is reachable (commented).
  • Markdown LRU 200 → 500 with the existing 50k-char entry cap to stop cross-session thrash (bound documented).
  • syncToolCardExpansionState skips the full-transcript walk when the items array identity is unchanged (spy test).
  • Validation: 1,505 tests (grep-selected suites) + 73 browser tests + 222 final focused regressions; UI tsgo, oxlint, oxfmt, git diff --check clean; autoreview clean (one finding rejected with threshold proof).

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.
@steipete
steipete marked this pull request as ready for review July 28, 2026 07:55
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: XL maintainer Maintainer-authored PR labels Jul 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 28, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 4:08 AM ET / 08:08 UTC.

ClawSweeper review

What this changes

Retains 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
Reviewed head: 009388fe9afb87c321b8df56115283ca9e9ae70b
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch presents a focused bounded-cache design with targeted coverage, but it remains below the merge proof bar because the visible interaction has not been demonstrated in a real setup.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR describes browser and focused test coverage, but no redacted live Control UI recording, runtime output, or interaction artifact demonstrates the after-fix session-switch behavior; add proof and redact private data before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR describes browser and focused test coverage, but no redacted live Control UI recording, runtime output, or interaction artifact demonstrates the after-fix session-switch behavior; add proof and redact private data before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Proposed UI behavior: The PR body states that returning to a previously viewed session restores its prior reading position instead of always anchoring at the transcript end; the implementation routes session changes through saved-position capture and restore logic.
Bounded retention design: The branch adds explicit virtualizer-cache limits and observer-disposal behavior, making retained render state a lifecycle and resource-management change rather than a purely cosmetic optimization.
Regression coverage supplied: The branch adds focused unit and browser tests for restored viewport state, item identity retention, virtualizer teardown, and session navigation presentation.
Findings None None.
Security None None.

How this fits together

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

Decision needed

Question Recommendation
Should switching back to a previously viewed Control UI session restore its saved reading position by default instead of retaining the historical end-of-transcript anchor? Adopt restored position: Accept saved reading-position restoration as the default, subject to real interaction proof for new-message and eviction cases.

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

  • Add real behavior proof - Needs real behavior proof before merge: The PR describes browser and focused test coverage, but no redacted live Control UI recording, runtime output, or interaction artifact demonstrates the after-fix session-switch behavior; add proof and redact private data before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Returning to a previously viewed session changes established navigation semantics from end anchoring to saved-reading-position restoration; maintainers need to explicitly accept that default for existing users.
  • Resolve merge risk (P1) - Retaining virtualizer hosts, measured rows, and viewport positions introduces lifecycle and memory-pressure risk that test assertions alone do not demonstrate under a real interactive session-switch workflow.
  • Complete next step (P2) - A maintainer must confirm the user-visible restored-scroll default, and the contributor must add real after-fix Control UI proof; neither is a safe automated repair task.
Agent review details

Security

None.

PR surface

Source +480, Tests +519. Total +999 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 8 503 23 +480
Tests 7 533 14 +519
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 1036 37 +999

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: ui/src/pages/chat/chat-thread.ts, persistent cache schema: ui/src/pages/chat/scroll.ts. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

A 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:

@openclaw-mantis web UI chat proof: reproduce A→B→A session switching, capture restored reading position, and verify that a new message while away does not force-jump the restored viewport.

Merge-risk options

Maintainer options:

  1. Prove and confirm the new navigation default (recommended)
    Capture a redacted real Control UI A→B→A run, including new messages while away and bounded-cache eviction, then obtain maintainer confirmation that restoring reading position is the intended upgrade behavior.
  2. Accept the behavioral change explicitly
    A maintainer may accept saved-position restoration as the new default after reviewing the interaction and resource-lifecycle tradeoff.
  3. Narrow the PR to rendering performance
    If the restored viewport default is not desired, remove that behavior and retain only the independently safe cache and reflow improvements.

Technical review

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

Labels

Label justifications:

  • P2: This is a bounded Control UI performance and navigation improvement with visible but non-emergency impact.
  • merge-risk: 🚨 compatibility: The branch intentionally changes switch-back behavior from end anchoring to restoring a saved transcript position.
  • merge-risk: 🚨 availability: The branch retains virtualizer hosts and observers across session switches, so resource cleanup and eviction behavior matter before merge.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR describes browser and focused test coverage, but no redacted live Control UI recording, runtime output, or interaction artifact demonstrates the after-fix session-switch behavior; add proof and redact private data before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Proposed UI behavior: The PR body states that returning to a previously viewed session restores its prior reading position instead of always anchoring at the transcript end; the implementation routes session changes through saved-position capture and restore logic. (ui/src/pages/chat/chat-pane-session.ts:174, 0598c000b9dd)
  • Bounded retention design: The branch adds explicit virtualizer-cache limits and observer-disposal behavior, making retained render state a lifecycle and resource-management change rather than a purely cosmetic optimization. (ui/src/pages/chat/components/chat-thread.ts:196, 0598c000b9dd)
  • Regression coverage supplied: The branch adds focused unit and browser tests for restored viewport state, item identity retention, virtualizer teardown, and session navigation presentation. (ui/src/e2e/chat-flow.navigation-presentation.e2e.test.ts:12, 0598c000b9dd)
  • Proof status: The PR body reports test and static-check runs, but the supplied context contains no redacted live recording, terminal output, runtime log, or other after-fix evidence showing the A→B→A interaction in a real Control UI session.
  • Repository review policy: The target repository policy treats user-visible Control UI behavior and state retention as compatibility-sensitive, and requires real behavior evidence for external PRs beyond tests and CI. (AGENTS.md:1, 521d05f290c2)

Likely related people:

  • steipete: The available commit provenance attributes both commits that introduce and then clean up this Control UI session-state change to this contributor; broader current-main ownership could not be established from the supplied review material. (role: proposed implementation author; confidence: low; commits: 0598c000b9dd, 009388fe9afb; files: ui/src/pages/chat/chat-pane-session.ts, ui/src/pages/chat/components/chat-thread.ts, ui/src/pages/chat/scroll.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add redacted live Control UI proof of A→B→A restoration, including a new message arriving while session A is inactive.
  • Ask a maintainer to confirm that saved reading position, rather than end anchoring, is the desired default for existing users.

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.

@steipete
steipete merged commit 3f209cf into main Jul 28, 2026
92 checks passed
@steipete
steipete deleted the perf/switch-render-caches branch July 28, 2026 08:27
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
…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
steipete added a commit that referenced this pull request Aug 15, 2026
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.
steipete added a commit that referenced this pull request Aug 15, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
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 maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant