Skip to content

fix(ui): own chat history issuance with a closed state machine - #129776

Merged
steipete merged 3 commits into
mainfrom
steipete/chat-history-issuance-state-machine
Aug 26, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/chat-history-issuance-state-machine

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #128655
Supersedes #128691

What Problem This Solves

Two related silent/dead-end failure legs in Control UI chat history loading:

  1. Never-asked leg (worst class — silent no-outcome): loadChatHistory opened with if (!state.client || !state.connected) return undefined;. Any caller racing the connection lifecycle (observed live during onboarding's config hot-reload ws bounce; also reachable through the pane context's early-return legs) left the pane in skeletons forever: zero requests on the wire, no error, no recorded fact, nothing to retry. Reproduced live on a fresh gateway (chat.history never appeared in the gateway request log while the pane skeletoned across reloads).
  2. Failed leg (dead-end alert, [Bug]: Control UI chat history failures offer no retry action #128655): when the request was issued and failed, the error fed setChatError — a dismiss-only alert with no recovery action.

Why This Change Was Made

History issuance now lives in one closed state machine recorded at the owner (ChatHistoryLoadState: idle | pending-connection | in-flight | committed | failed), replacing the implicit combination of inFlightHistory, chatLoading, and connected booleans callers had to keep in sync:

  • A load requested while disconnected records pending-connection (the skeleton is then honest — a load is owed) and re-arms exactly once at the pane context's connected false→true transition; the resumed promise threads through refreshPageChat so startup paths cannot double-issue.
  • A failure records failed with a retryable fact. With an empty transcript it renders an accessible .chat-history-error panel with a Retry action instead of the dismiss-only alert; retryable failures also auto-resume on reconnect. In-flight loads invalidated by reconnect transfer their intent back to pending-connection instead of vanishing.
  • Session switches and projection resets return the machine to idle; the old InFlightChatHistoryRequest parallel state is deleted.

This supersedes #128691 by fixing the failure leg at the request owner rather than adding a panel-status presentation layer, and by also covering the never-asked leg a retry affordance cannot reach (there is no failure to retry when no request was ever made). Credit to @vyctorbrzezowski for the issue, the deterministic repro, and the retry-affordance direction.

User Impact

Chat panes can no longer skeleton forever after connection races — they either load once connected or show an actionable error. History failures self-heal on reconnect when retryable and otherwise offer Retry in the transcript area.

Evidence

  • Pre-fix behavioral failure (this branch's tests against unpatched main): chat-flow.history-issuance.e2e.test.ts times out waiting for .chat-history-error (the dismiss-only alert reality), and the host regression records zero gateway requests for a disconnected-then-connected pane.
  • Post-fix: node scripts/run-vitest.mjs run ui/src/pages/chat — 153 files, 3,154 passed / 15 skipped; e2e batch (chat-flow.history-issuance, chat-flow.streaming, chat-flow.queue-edit, chat-run-lifecycle) — 25/25 passed; node scripts/check-changed.mjs green.
  • Mock-gateway harness e2e covers the changed path per the real-behavior-proof gate: failure → visible retryable panel → Retry recovers the transcript; retryable failure → reconnect auto-resumes exactly once.

loadChatHistory silently returned undefined when the pane was not yet
connected, so any caller racing the connection lifecycle left the pane
in skeletons forever: no request, no error, no recorded fact. Failures
that did happen fed a dismiss-only alert with no recovery (#128655).

Record issuance as one ChatHistoryLoadState union
(idle | pending-connection | in-flight | committed | failed) at the
owner, absorbing the old inFlightHistory nullable. Disconnected requests
record pending-connection and re-arm exactly once at the pane context's
connected transition; failures render a retryable transcript error and
retryable ones auto-resume on reconnect; invalidated in-flight loads
transfer intent back to pending instead of vanishing.

Closes #128655. Supersedes #128691.
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: L maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

UI proof from the mocked-gateway e2e harness (real Chromium, captured via OPENCLAW_UI_E2E_ARTIFACT_DIR, frames inspected):

  1. Failed history load now renders an accessible transcript-area error with Retry (pre-fix: dismiss-only alert; the branch's e2e times out on unpatched main waiting for this element).
  2. Clicking Retry recovers the transcript.
  3. A retryable failure auto-resumes after Gateway reconnect with no user action.

01-history-load-failed

02-history-load-retried

03-history-load-auto-resumed

@steipete
steipete marked this pull request as ready for review August 26, 2026 02:24
Repeated identical disconnected snapshots must stay no-ops for pane
ownership (chat-pane-lifecycle contract); normalize chatLoading only on
the connected->disconnected edge.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P1 High-priority user-facing bug, regression, or broken workflow. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed P2 Normal backlog priority with limited blast radius. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 25, 2026, 11:59 PM ET / August 26, 2026, 03:59 UTC.

ClawSweeper review

What this changes

The PR records chat-history loading as an owner-scoped state machine, resumes deferred loads after reconnect, and shows retryable failure UI for empty and cached transcripts.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open: the current head fixes the prior cached-transcript finding, but its Retry button bypasses the pane’s canonical refresh flow and can leave session reconciliation and startup metadata stale after recovery.

Priority: P1
Reviewed head: 19b2d6cdefcdd617a8ee7a165bb3c21d8361560b

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The browser proof and repaired prior finding are strong, but the Retry lifecycle currently bypasses the canonical refresh owner.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (screenshot): The supplied PR discussion includes mocked-Gateway Chromium screenshots, and the added browser test covers visible failure, retry, reconnect, and cached-history recovery; the remaining finding concerns lifecycle completeness.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The supplied PR discussion includes mocked-Gateway Chromium screenshots, and the added browser test covers visible failure, retry, reconnect, and cached-history recovery; the remaining finding concerns lifecycle completeness.
Evidence reviewed 6 items Current-main defect: Current main returns before recording or issuing a history request when the pane is disconnected, matching the reported silent no-outcome path.
Owner-boundary repair: The PR records pending, in-flight, committed, and failed history states at the history owner and transfers invalidated work back to pending connection.
Canonical-refresh bypass: The new Retry handler invokes the low-level history loader directly, while the pane callback runs refreshPageChat, which performs session reconciliation and startup metadata handling.
Findings 1 actionable finding [P2] Route history Retry through the pane refresh callback
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.history-issuance.e2e.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.history-issuance.e2e.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.history-issuance.e2e.test.ts"

RUN  v4.1.10 /tmp/clawsweeper-live-proof-129776-U2Q5vb/target

[vitest] still running with no output for 30000ms.

Assertions:

  • FAIL expect_output: keeps cached history visible and actionable when a refresh fails

How this fits together

The Control UI chat pane loads transcript history from the Gateway, then reconciles session state and renders the conversation. This PR governs how disconnected, failed, and retried history requests pass through that lifecycle.

flowchart LR
  A[Gateway connection] --> B[Chat pane lifecycle]
  B --> C[History load state]
  C --> D[History request]
  D --> E[Session reconciliation]
  E --> F[Transcript view]
  C --> G[Retry or reconnect]
  G --> D
Loading

Before merge

  • Route history Retry through the pane refresh callback (P2) - The new handler calls retryChatHistoryLoad directly, bypassing onRefresh in chat-pane-render.ts, which performs refreshPageChat session reconciliation and startup metadata work. A successful retry can therefore restore visible messages while leaving surrounding session state stale; use the pane-owned refresh path and cover that recovered lifecycle.
  • Resolve merge risk (P1) - Clicking Retry bypasses the pane-owned refresh lifecycle, so a recovered startup response need not reconcile session state, queued work, or startup metadata.
  • Resolve merge risk (P1) - The bug fix has a production delta of +225/-33; route Retry through the existing refresh path and remove the now-redundant direct retry helper rather than maintaining a parallel refresh path.
  • Complete next step (P2) - The remaining blocker is a narrow mechanical routing repair with a focused browser validation path.

Findings

  • [P2] Route history Retry through the pane refresh callback — ui/src/pages/chat/chat-view.ts:560
Agent review details

Security

None.

PR surface

Source +192, Tests +311. Total +503 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 6 225 33 +192
Tests 3 319 8 +311
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 544 41 +503

Review metrics

Metric Value Why it matters
Production versus test delta production +225/-33; tests +319/-8 The state-machine repair adds substantial production logic, so retaining one canonical Retry path matters before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128655
Summary: This PR is the candidate owner-boundary fix for the chat-history recovery issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Use the canonical pane refresh (recommended)
    Have Retry enter the pane-owned refresh lifecycle and add focused proof that recovered history also reconciles its session state.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Route the history Retry control through the existing pane refresh callback, remove the bypass helper if unused, and add focused browser coverage for recovered session reconciliation.

Technical review

Best possible solution:

Route the history Retry action through the pane’s existing refresh callback, preserve the retry’s intended startup semantics if required, delete the raw bypass if unused, and cover the full recovered-refresh lifecycle.

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

Yes: current main’s disconnected early return is source-reproducible, and the PR provides mocked-Gateway browser coverage for the affected lifecycle.

Is this the best way to solve the issue?

No: the owner-scoped state machine is the right repair boundary, but Retry should re-enter the canonical pane refresh flow rather than invoke only the low-level loader.

Full review comments:

  • [P2] Route history Retry through the pane refresh callback — ui/src/pages/chat/chat-view.ts:560
    The new handler calls retryChatHistoryLoad directly, bypassing onRefresh in chat-pane-render.ts, which performs refreshPageChat session reconciliation and startup metadata work. A successful retry can therefore restore visible messages while leaving surrounding session state stale; use the pane-owned refresh path and cover that recovered lifecycle.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The PR changes ownership and recovery of transcript and session-history state across Gateway reconnects.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR discussion includes mocked-Gateway Chromium screenshots, and the added browser test covers visible failure, retry, reconnect, and cached-history recovery; the remaining finding concerns lifecycle completeness.
  • remove merge-risk: 🚨 other: Current PR review merge-risk labels are merge-risk: 🚨 session-state.

Label justifications:

  • P1: This repairs silent or dead-end failure behavior in the default Control UI chat workflow.
  • merge-risk: 🚨 session-state: The PR changes ownership and recovery of transcript and session-history state across Gateway reconnects.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The supplied PR discussion includes mocked-Gateway Chromium screenshots, and the added browser test covers visible failure, retry, reconnect, and cached-history recovery; the remaining finding concerns lifecycle completeness.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR discussion includes mocked-Gateway Chromium screenshots, and the added browser test covers visible failure, retry, reconnect, and cached-history recovery; the remaining finding concerns lifecycle completeness.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The supplied PR discussion includes mocked-Gateway Chromium screenshots, and the added browser test covers visible failure, retry, reconnect, and cached-history recovery; the remaining finding concerns lifecycle completeness.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.history-issuance.e2e.test.ts.
  • [P1] node scripts/run-vitest.mjs run ui/src/pages/chat/chat-pane-history-issuance.test.ts ui/src/pages/chat/chat-gateway.test.ts.
  • [P1] node scripts/check-changed.mjs -- ui/src/pages/chat/chat-view.ts ui/src/pages/chat/chat-pane-render.ts ui/src/e2e/chat-flow.history-issuance.e2e.test.ts.

What I checked:

  • Current-main defect: Current main returns before recording or issuing a history request when the pane is disconnected, matching the reported silent no-outcome path. (ui/src/pages/chat/chat-history.ts:1490, 937c89675b04)
  • Owner-boundary repair: The PR records pending, in-flight, committed, and failed history states at the history owner and transfers invalidated work back to pending connection. (ui/src/pages/chat/chat-history.ts:1535, 19b2d6cdefcd)
  • Canonical-refresh bypass: The new Retry handler invokes the low-level history loader directly, while the pane callback runs refreshPageChat, which performs session reconciliation and startup metadata handling. (ui/src/pages/chat/chat-view.ts:560, 19b2d6cdefcd)
  • Browser regression coverage: The added mocked-Gateway browser test proves the visible failure, retry, reconnect, and cached-transcript states, but currently asserts only the raw history request and recovered transcript. (ui/src/e2e/chat-flow.history-issuance.e2e.test.ts:53, 19b2d6cdefcd)
  • Prior-finding follow-through: The current head adds the compact non-displacing failed-refresh banner and browser coverage for cached history, addressing the prior review’s stated blocker. (ui/src/pages/chat/chat-view.ts:549, 19b2d6cdefcd)
  • History provenance: Blame ties the current-main disconnected early return to the recent chat-history source revision, with Peter Steinberger as the recorded source author; shallow history prevents reliable predecessor-PR attribution. (ui/src/pages/chat/chat-history.ts:1490, 3caf21bdd4c3)

Likely related people:

  • steipete: Current-main blame attributes the affected history-loader path to Peter Steinberger, and this PR continues work in the same owner boundary. (role: current source author and recent area contributor; confidence: high; commits: 3caf21bdd4c3, 19b2d6cdefcd; files: ui/src/pages/chat/chat-history.ts, ui/src/pages/chat/chat-pane-render.ts, ui/src/pages/chat/chat-state-refresh.ts)

Rank-up moves

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

  • Route Retry through the pane-owned refresh flow and prove the recovered session reconciliation path in the mocked-Gateway browser harness.

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-26T03:15:31.975Z sha f7aca53 :: found issues before merge. :: [P1] Keep failed refreshes actionable with cached history

…ipts

A refresh failure with cached messages rendered nothing: the failure
panel only replaced an empty thread, so stale content sat with no error
or Retry. Render the same failure surface as a compact non-displacing
banner above the transcript when content exists, sharing one builder
with the empty-state panel. Adds the cached-refresh browser regression
with screenshot proof.
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the P1 in 19b2d6c: a failed refresh with cached history now renders the same failure surface as a compact non-displacing banner (.chat-history-error--inline, role=status) above the retained transcript, sharing one builder with the empty-state panel (no extra presentation branch). New browser regression covers cached content surviving the failure, the banner's Retry re-issuing the request, and the banner clearing on success — screenshot attached (inspected).

@clawsweeper re-review

04-history-refresh-failed-cached

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 1e84f42 into main Aug 26, 2026
108 checks passed
@steipete
steipete deleted the steipete/chat-history-issuance-state-machine branch August 26, 2026 04: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 Aug 26, 2026
…law#129776)

* fix(ui): own chat history issuance with a closed state machine

loadChatHistory silently returned undefined when the pane was not yet
connected, so any caller racing the connection lifecycle left the pane
in skeletons forever: no request, no error, no recorded fact. Failures
that did happen fed a dismiss-only alert with no recovery (openclaw#128655).

Record issuance as one ChatHistoryLoadState union
(idle | pending-connection | in-flight | committed | failed) at the
owner, absorbing the old inFlightHistory nullable. Disconnected requests
record pending-connection and re-arm exactly once at the pane context's
connected transition; failures render a retryable transcript error and
retryable ones auto-resume on reconnect; invalidated in-flight loads
transfer intent back to pending instead of vanishing.

Closes openclaw#128655. Supersedes openclaw#128691.

* fix(ui): scope disconnect loading normalization to the transition

Repeated identical disconnected snapshots must stay no-ops for pane
ownership (chat-pane-lifecycle contract); normalize chatLoading only on
the connected->disconnected edge.

* fix(ui): keep failed history refreshes actionable over cached transcripts

A refresh failure with cached messages rendered nothing: the failure
panel only replaced an empty thread, so stale content sat with no error
or Retry. Render the same failure surface as a compact non-displacing
banner above the transcript when content exists, sharing one builder
with the empty-state panel. Adds the cached-refresh browser regression
with screenshot proof.
vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (24 commits)
  fix(gateway): reject rootless session permission modes (#128149)
  docs(memory): document shipped turn-taint propagation for network tool output (#129837)
  fix(ui): pool reply-less wake activity into one chat rollup (#128442)
  fix(package): prevent installs from deleting validated runtime assets (#129724)
  fix(nodes): approve silent initial node surfaces and name the pending surface approval (#129795)
  fix(backup): preserve configured agent state roots (#129773)
  fix(ui): own chat history issuance with a closed state machine (#129776)
  fix(cron): preserve cancellation reason after late finalization (#129331)
  fix(cron): prevent run waits from failing after clock changes (#129805)
  fix(telegram): route commentary through one frozen progress owner (#128259)
  fix(release): start approved VCR mirror recovery jobs (#129829)
  test: complete current-plugin-metadata-snapshot mock factories (#129791)
  test(telegram): remove duplicate reaction case (#129848)
  fix(channels): honor supported account reply-threading policies (#129679)
  refactor(cli): deduplicate lazy subcommand registration (#129351)
  fix(ai): report interrupted local-model streams instead of empty success (#129794)
  refactor(cli): consolidate Gateway fallback and hook ownership (#129802)
  fix(qa): reject token confidence lanes without executed evidence (#129830)
  fix(tui): fence session state and delayed actions (#129810)
  fix(control-ui): keep task progress full width on hover (#129832)
  ...
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: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P1 High-priority user-facing bug, regression, or broken workflow. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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.

[Bug]: Control UI chat history failures offer no retry action

1 participant