Skip to content

fix(ui): stop per-message branch-list polling and unlatch transient branch failures - #124094

Merged
steipete merged 2 commits into
mainfrom
codex/autoqa-branch-list-amplification
Aug 15, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/autoqa-branch-list-amplification

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Four coupled defects around the chat branch dropdown, found by round-5 web-UI QA:

  1. Per-message branch polling with O(transcript) gateway cost. Every persisted session.message and every sessions.changed made each viewing Control UI client issue an unconditional sessions.branches.list RPC. The gateway branch cache watermark is max(seq) over transcript events, so every message append invalidated it and the miss path re-loaded and re-scanned the full transcript — to refresh a dropdown that renders only when more than one branch exists.
  2. Transient failure latched into a permanently hidden dropdown. The UI catch recorded success (chatBranchesSessionKey set, branches=[]) on any error, so a single network/gateway hiccup hid the branch dropdown for that session+connection forever with no visible outcome and no recorded reason — the worst bug class per the Product Doctrine. (Landing fix 1 alone would have made this latch permanent, which is why they land together.)
  3. Upstream-linked sessions errored on a read. sessions.branches.list responded INVALID_REQUEST for upstream-linked sessions even though "no local branches" is their truthful steady state. The fresh-session sibling was already converted from error to {branches: []} for exactly this reason (the inline comment documents the spurious gateway-log failures it fixed); only the mutating siblings (rewind/switch/fork) must fail closed.
  4. Alias-window blanking. Branch state was keyed by raw session-key spelling and strict-compared in the header render and history reload gate, blanking the dropdown across the legacy main → agent:main:main canonicalization window — the same class fix(ui): use session-key equivalence for active-row lookups in model/thinking/fast-mode paths #124020 fixed at six sites two days ago; these two were missed.

Why This Change Was Made

Branch topology changes are produced exclusively by the rewind/switch/fork mutations, which already record the reason on sessions.changed — the recorded fact at the producer replaces polling at the consumer ("record facts where they happen; read them where they are needed"). Tradeoff named: the active branch's messageCount/updatedAt in the rarely-open dropdown can go slightly stale between structural events.

Pathfinder riders in the same files: deleted the write-only chatBranchesLoading flag, a duplicate activeLeafEntryId recompute, and two provably no-op second dropPreSessionStartAnnouncePairs passes in chat-history-pages.ts (the filter is single-pass complete and both inputs were already filtered).

User Impact

Idle Control UI viewers stop generating one full-transcript gateway scan per incoming message; the branch dropdown recovers from transient failures instead of vanishing permanently; upstream-linked sessions stop producing spurious gateway error logs on every load; the dropdown no longer blanks during session-key canonicalization.

Evidence

  • Three new regression tests, each verified to fail pre-fix (via stash): transient-failure retry, alias-equivalence reload skip, upstream-linked list returning {branches: []} while switch still rejects.
  • node scripts/run-vitest.mjs run ui/src/pages/chat/chat-history.test.ts src/gateway/server-methods/sessions-rewind.test.ts src/gateway/server-methods/chat-history-pages.test.ts src/gateway/server-methods/chat-history-handler.test.ts — 60/60 green; ui/src/pages/chat/chat-state.test.ts + chat-send.test.ts — 344/344 green.
  • pnpm tsgo, pnpm tsgo:ui, pnpm check:test-types, oxfmt/oxlint clean; autoreview clean (0.99).

Production LOC +27/−34 (net −7); tests +51/−12.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 15, 2026 07:41
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 15, 2026, 4:20 AM ET / 08:20 UTC.

ClawSweeper review

What this changes

The PR reduces Control UI branch-list polling, retries branch metadata after failures, normalizes equivalent session keys, and returns an empty list for upstream-linked sessions.

Merge readiness

⛔ Blocked by patch quality or review findings - 7 items remain

Keep open: both prior blocking findings remain on the current head. A failed structural refresh can retain a valid cache marker and suppress the retry, and checkpoint restoration is omitted from the new structural-reason gate.

Priority: P2
Reviewed head: 7fe349161f020366cb3fb78f27a87faf26fe8816

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch contains useful targeted fixes but remains blocked by two previously identified session-branch correctness gaps.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to this maintainer-authored PR; its test claims are supplemental and the correctness blockers are source-visible.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this maintainer-authored PR; its test claims are supplemental and the correctness blockers are source-visible.
Evidence reviewed 7 items Failed refresh leaves a successful marker intact: The changed catch intentionally does nothing; after a refresh of already-loaded branches fails, the existing session key and epoch remain valid.
Retry gate then skips the failed refresh: The history loader only starts a branch request when the key is not equivalent or the connection epoch changed, so the retained marker prevents a retry.
New retry test lacks the preloaded-cache case: The added test starts with no branch marker, so it proves an initial-load retry but not failure after a successful cached load.
Findings 2 actionable findings [P1] Clear cached branch metadata after a failed refresh
[P2] Reload branches after checkpoint restoration
Security None None.

How this fits together

The Control UI receives Gateway session events, refreshes selected-session history and branch metadata, and renders a branch dropdown. Gateway owns branch topology and emits mutation reasons; UI state uses those reasons to decide when cached branch metadata must reload.

flowchart LR
  A[Session mutation] --> B[Gateway change event]
  B --> C[Control UI event handler]
  C --> D{Branch topology changed?}
  D -->|Yes| E[Branch-list request]
  D -->|No| F[Keep cached metadata]
  E --> G[Branch dropdown]
Loading

Before merge

  • Clear cached branch metadata after a failed refresh (P1) - When a structural event refreshes an already-loaded pane and listBranches rejects, this catch leaves the old key and epoch in place. The next history load treats that cache as valid and skips retry, leaving stale branch UI; clear the marker under the current-request guard and cover the preloaded-cache failure. This prior P1 remains on this head.
  • Reload branches after checkpoint restoration (P2) - Checkpoint restoration replaces the active transcript but emits checkpoint-restore, which this new allow-list excludes. The selected pane therefore keeps cached branch metadata after restore; include that producer reason and add an event-path regression. This prior P2 remains on this head.
  • Resolve merge risk (P1) - Merging leaves a stale or hidden branch dropdown after a failed refresh of previously loaded branch metadata.
  • Resolve merge risk (P1) - Checkpoint restoration can replace the active transcript while the dropdown continues to show the prior branch topology.
  • Complete next step (P2) - This maintainer-labelled PR needs its two concrete review blockers resolved on the branch rather than a separate repair dispatch.
  • Improve patch quality - Clear the guarded cached marker after a failed refresh and add the preloaded-cache regression.
  • Improve patch quality - Handle checkpoint-restore in the structural refresh path and cover it through the UI event handler.

Findings

  • [P1] Clear cached branch metadata after a failed refresh — ui/src/pages/chat/chat-history.ts:1413-1416
  • [P2] Reload branches after checkpoint restoration — ui/src/pages/chat/chat-state-events.ts:267
Agent review details

Security

None.

PR surface

Source -2, Tests +39. Total +37 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 6 35 37 -2
Tests 2 51 12 +39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 86 49 +37

Review metrics

Metric Value Why it matters
Production versus test delta production +35/-37 (net -2); tests +51/-12 The PR is net-negative in production code, but its new tests do not yet cover both remaining cached-branch failure paths.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/sessions-rewind.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair the branch-cache invalidation contract (recommended)
    Clear the current branch marker after a guarded failed refresh and reload after checkpoint restoration, with focused preloaded-cache and event-path tests.

Technical review

Best possible solution:

Invalidate cached branch ownership under the existing request guard on failure, include checkpoint restoration in the structural branch-refresh contract, and cover both event paths with regressions.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a preloaded branch cache followed by a rejected refresh leaves the retry predicate false, and a checkpoint-restore event is excluded from the reload gate. No runtime test was run in this read-only review.

Is this the best way to solve the issue?

No. The owner-boundary direction is sound, but it must invalidate prior successful state after a failed refresh and handle Gateway's checkpoint-restore producer before it is merge-ready.

Full review comments:

  • [P1] Clear cached branch metadata after a failed refresh — ui/src/pages/chat/chat-history.ts:1413-1416
    When a structural event refreshes an already-loaded pane and listBranches rejects, this catch leaves the old key and epoch in place. The next history load treats that cache as valid and skips retry, leaving stale branch UI; clear the marker under the current-request guard and cover the preloaded-cache failure. This prior P1 remains on this head.
    Confidence: 0.99
  • [P2] Reload branches after checkpoint restoration — ui/src/pages/chat/chat-state-events.ts:267
    Checkpoint restoration replaces the active transcript but emits checkpoint-restore, which this new allow-list excludes. The selected pane therefore keeps cached branch metadata after restore; include that producer reason and add an event-path regression. This prior P2 remains on this head.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a4f61d135a48.

Labels

Label justifications:

  • P2: The PR addresses a bounded but user-visible Control UI session-branch workflow and still has two repairable correctness blockers.
  • merge-risk: 🚨 session-state: The changed cache invalidation and event-reason logic can leave branch metadata stale for the active session.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable to this maintainer-authored PR; its test claims are supplemental and the correctness blockers are source-visible.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the feature commit containing the new reason gate and the current-head refactor; blame also attributes the checkpoint event and existing UI event path to this area. (role: recent Control UI and session-event contributor; confidence: high; commits: 0ab98e1bd404, 7fe349161f02, 1320a0bff944; files: ui/src/pages/chat/chat-history.ts, ui/src/pages/chat/chat-state-events.ts, src/gateway/server-methods/sessions-compaction-checkpoints.ts)

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-08-15T07:48:08.007Z sha 8945727 :: found issues before merge. :: [P1] Invalidate cached branch state after a failed refresh | [P2] Refresh branches after checkpoint restoration

…ranch failures

Four coupled defects around the chat branch dropdown, fixed at their owners:

- Every persisted session.message and every sessions.changed triggered an
  unconditional sessions.branches.list RPC per viewing client; the gateway
  branch cache watermark is max(seq), so each message append made the next
  list a full transcript rescan. Branch topology only changes on structural
  mutations, and the producer already records the reason — the reload is now
  gated on rewind/branch-switch/fork/reset/new.
- A transient listBranches failure recorded success (chatBranchesSessionKey
  set with branches=[]), permanently hiding the branch dropdown for that
  session+connection with no visible outcome. The catch no longer latches;
  the next history load retries naturally.
- sessions.branches.list errored for upstream-linked sessions even though
  "no local branches" is their truthful steady state; the fresh-session
  sibling was already converted to {branches: []} for the same reason
  (spurious gateway-log failures). Only mutating siblings fail closed now.
- Branch state was keyed by raw session-key spelling and strict-compared in
  the header and history gate, blanking the dropdown across the legacy
  main -> agent:main:main alias window (same class as #124020); both
  compares use areUiSessionKeysEquivalent.

Riders per pathfinder rule: deleted the write-only chatBranchesLoading flag,
a duplicate activeLeafEntryId recompute, and two provably-no-op second
dropPreSessionStartAnnouncePairs passes in chat-history-pages.ts (the filter
is single-pass complete and its inputs were already filtered).

Production LOC +27/-34 (net -7); regression tests fail pre-fix.
@steipete
steipete force-pushed the codex/autoqa-branch-list-amplification branch from 8945727 to 0ab98e1 Compare August 15, 2026 08:04
check-lint-core-4 flagged chat-pane-header.ts at 702 counted lines after the
equivalence gate landed there. The branches-for-display decision belongs to
the state owner anyway: displayedChatSessionBranches in chat-history.ts now
owns it and the header render consumes the fact.
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 15, 2026
@steipete
steipete merged commit f4beff1 into main Aug 15, 2026
198 checks passed
@steipete
steipete deleted the codex/autoqa-branch-list-amplification branch August 15, 2026 08:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…ranch failures (openclaw#124094)

* fix(ui): stop per-message branch-list polling and unlatch transient branch failures

Four coupled defects around the chat branch dropdown, fixed at their owners:

- Every persisted session.message and every sessions.changed triggered an
  unconditional sessions.branches.list RPC per viewing client; the gateway
  branch cache watermark is max(seq), so each message append made the next
  list a full transcript rescan. Branch topology only changes on structural
  mutations, and the producer already records the reason — the reload is now
  gated on rewind/branch-switch/fork/reset/new.
- A transient listBranches failure recorded success (chatBranchesSessionKey
  set with branches=[]), permanently hiding the branch dropdown for that
  session+connection with no visible outcome. The catch no longer latches;
  the next history load retries naturally.
- sessions.branches.list errored for upstream-linked sessions even though
  "no local branches" is their truthful steady state; the fresh-session
  sibling was already converted to {branches: []} for the same reason
  (spurious gateway-log failures). Only mutating siblings fail closed now.
- Branch state was keyed by raw session-key spelling and strict-compared in
  the header and history gate, blanking the dropdown across the legacy
  main -> agent:main:main alias window (same class as openclaw#124020); both
  compares use areUiSessionKeysEquivalent.

Riders per pathfinder rule: deleted the write-only chatBranchesLoading flag,
a duplicate activeLeafEntryId recompute, and two provably-no-op second
dropPreSessionStartAnnouncePairs passes in chat-history-pages.ts (the filter
is single-pass complete and its inputs were already filtered).

Production LOC +27/-34 (net -7); regression tests fail pre-fix.

* refactor(ui): move branch-display ownership out of the header render

check-lint-core-4 flagged chat-pane-header.ts at 702 counted lines after the
equivalence gate landed there. The branches-for-display decision belongs to
the state owner anyway: displayedChatSessionBranches in chat-history.ts now
owns it and the header render consumes the fact.
SemonCat pushed a commit to SemonCat/openclaw that referenced this pull request Aug 16, 2026
…ranch failures (openclaw#124094)

* fix(ui): stop per-message branch-list polling and unlatch transient branch failures

Four coupled defects around the chat branch dropdown, fixed at their owners:

- Every persisted session.message and every sessions.changed triggered an
  unconditional sessions.branches.list RPC per viewing client; the gateway
  branch cache watermark is max(seq), so each message append made the next
  list a full transcript rescan. Branch topology only changes on structural
  mutations, and the producer already records the reason — the reload is now
  gated on rewind/branch-switch/fork/reset/new.
- A transient listBranches failure recorded success (chatBranchesSessionKey
  set with branches=[]), permanently hiding the branch dropdown for that
  session+connection with no visible outcome. The catch no longer latches;
  the next history load retries naturally.
- sessions.branches.list errored for upstream-linked sessions even though
  "no local branches" is their truthful steady state; the fresh-session
  sibling was already converted to {branches: []} for the same reason
  (spurious gateway-log failures). Only mutating siblings fail closed now.
- Branch state was keyed by raw session-key spelling and strict-compared in
  the header and history gate, blanking the dropdown across the legacy
  main -> agent:main:main alias window (same class as openclaw#124020); both
  compares use areUiSessionKeysEquivalent.

Riders per pathfinder rule: deleted the write-only chatBranchesLoading flag,
a duplicate activeLeafEntryId recompute, and two provably-no-op second
dropPreSessionStartAnnouncePairs passes in chat-history-pages.ts (the filter
is single-pass complete and its inputs were already filtered).

Production LOC +27/-34 (net -7); regression tests fail pre-fix.

* refactor(ui): move branch-display ownership out of the header render

check-lint-core-4 flagged chat-pane-header.ts at 702 counted lines after the
equivalence gate landed there. The branches-for-display decision belongs to
the state owner anyway: displayedChatSessionBranches in chat-history.ts now
owns it and the header render consumes the fact.
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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant