Skip to content

fix(ui): reload WebChat history for deferred thinking - #91810

Closed
TurboTheTurtle wants to merge 6 commits into
openclaw:mainfrom
TurboTheTurtle:codex/91727-webchat-live-reasoning
Closed

TurboTheTurtle wants to merge 6 commits into
openclaw:mainfrom
TurboTheTurtle:codex/91727-webchat-live-reasoning

Conversation

@TurboTheTurtle

@TurboTheTurtle TurboTheTurtle commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #91727.

Summary

WebChat now keeps a deferred persisted assistant session.message with thinking/reasoning pending while the local run is active, then reloads the selected transcript after the terminal final when that final payload only contains renderable answer text. The repaint restores the persisted reasoning block without a manual browser refresh and avoids leaving a duplicate text-only final.

Root cause

The terminal final path avoided loadChatHistory() whenever the final carried renderable assistant text. A prior session.message could already contain the persisted assistant message with a thinking block, but a session-row refresh could clear the local run before the final arrived. The final was then appended as a text-only assistant message and the UI could keep both the persisted reasoning final and the live text-only final.

What changed

  • Track thinking-bearing session.message payloads for the selected/equivalent session while a WebChat run is active.
  • Keep those deferred thinking reloads pending until the matching terminal chat event, instead of letting the session-row refresh clear the run early.
  • Reload history when the terminal final lacks the deferred thinking block.
  • Preserve the existing no-reload path for normal renderable finals with no deferred thinking to recover.
  • Dedupe text-only late finals when persisted history has the same assistant final plus thinking, while preserving newer repeated finals from stale history.
  • Keep the cross-session/global-alias and literal user thinking-text guards covered.

Real behavior proof

Behavior or issue addressed: WebChat receives a persisted assistant session.message with a thinking block during an active run, then receives a terminal chat final payload that only contains renderable final text. The fixed behavior is that WebChat reloads the selected transcript, renders the persisted reasoning block, and does not leave a duplicate text-only final answer bubble.

Real environment tested: Local OpenClaw source checkout at PR head f68625750c83ef3eeb08fee396801b28e474fab3 on macOS. The repo Control UI ran through the Vite e2e server and the actual WebChat renderer ran in Playwright Chromium. The browser connected to a gateway-shaped WebSocket endpoint with the selected session row loaded as reasoningLevel: "low".

Exact steps or command run after this patch:

node --import tsx --input-type=module <<'NODE'
# Launch the repo Vite e2e server.
# Open /chat in Playwright Chromium.
# Load the Sessions view once so the selected WebChat session has reasoningLevel: low.
# Return to Chat and send a user prompt.
# Emit session.message with persisted assistant thinking plus final text.
# Set chat.history to that persisted transcript.
# Emit the timestamped terminal chat final payload with only final text.
# Wait for chat.history, screenshot WebChat, and count final/reasoning text in the real DOM.
NODE

Evidence after fix: Copied live browser proof output from the command above:

{
  "head": "f68625750c83ef3eeb08fee396801b28e474fab3",
  "workingTreeStatus": "clean",
  "scenario": "WebChat deferred session.message thinking followed by timestamped terminal final payload without thinking",
  "browser": "Playwright Chromium",
  "sessionKey": "main",
  "activeSessionReasoningLevel": "low",
  "activeSessionThinkingLevel": "low",
  "sessionsListRequests": 1,
  "chatHistoryRequests": 2,
  "finalAnswerCount": 1,
  "reasoningCount": 1,
  "thinkingBlockCount": 1,
  "observedFinalText": "Final answer proof marker 91810",
  "observedReasoningText": "private reasoning proof marker 91810",
  "screenshotPath": "/Users/andy/openclaw-91810/.artifacts/pr-91810-proof/webchat-deferred-reasoning-current-head.png"
}

Observed result after fix: The WebChat DOM contained exactly one Final answer proof marker 91810, exactly one private reasoning proof marker 91810, and exactly one .chat-thinking block. The rendered assistant bubble contained the persisted reasoning block plus the final answer; the text-only terminal final did not remain as a duplicate.

What was not tested: I did not run a live external provider WebChat session because the reported bug is the Control UI/gateway event ordering after the provider has already produced a persisted assistant message. The browser proof exercises the real WebChat renderer and gateway message path without provider credentials.

Validation

node scripts/run-vitest.mjs ui/src/ui/chat-event-reload.test.ts ui/src/ui/app-gateway.node.test.ts ui/src/ui/controllers/chat.test.ts

Result: 3 files passed, 199 tests passed.

node scripts/run-vitest.mjs ui/src/ui/app-gateway.node.test.ts

Result: 1 file passed, 67 tests passed.

pnpm check:test-types

Result: passed.

pnpm exec oxfmt --check --threads=1 ui/src/ui/app-gateway.ts ui/src/ui/chat-event-reload.ts ui/src/ui/app-gateway.node.test.ts ui/src/ui/chat-event-reload.test.ts ui/src/ui/controllers/chat.ts ui/src/ui/controllers/chat.test.ts

Result: all matched files use the correct format.

git diff --check

Result: no whitespace errors.

Commit author verification:

f68625750c Andy Ye <[email protected]> fix(ui): preserve repeated late finals
ebb1d35195 Andy Ye <[email protected]> test(ui): type session result fixtures
02e6638a0a Andy Ye <[email protected]> fix(ui): keep deferred reasoning reload pending
e4508934f3 Andy Ye <[email protected]> fix(ui): preserve final during deferred history reload
39faf8a7ed Andy Ye <[email protected]> fix(ui): avoid duplicate deferred-thinking final
260f6a5aec Andy Ye <[email protected]> fix(ui): reload webchat history for deferred thinking

@TurboTheTurtle

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 10, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 10, 2026
@TurboTheTurtle

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 10, 2026
@clawsweeper

clawsweeper Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 30, 2026, 5:15 PM ET / 21:15 UTC.

Summary
This PR updates Control UI WebChat gateway event handling, final-event reload decisions, and chat-history reconciliation so persisted thinking can repaint after a text-only terminal final without leaving duplicate assistant finals.

PR surface: Source +85, Tests +492. Total +577 across 6 files.

Reproducibility: yes. at source level. Current main skips history reload for renderable text-only finals while WebChat renders reasoning from the displayed message, so persisted thinking can remain hidden until a manual refresh.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: ui/src/ui/controllers/chat.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #91727
Summary: This PR is the focused candidate fix for the canonical deferred WebChat reasoning repaint regression; nearby reasoning reports cover adjacent provider extraction, UX, or sanitization behavior.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Proof path suggestion
A merge-ref browser visual proof would materially help maintainers verify the visible reasoning repaint and duplicate-final behavior. Mantis is currently scoped to Telegram, Discord, and web UI chat proof, so it is not the right proof path for this surface.
Use maintainer screenshot/manual proof, browser or Playwright proof, Crabbox where appropriate, or normal local artifact proof instead.

Risk before merge

  • [P1] The PR changes WebChat session.message and terminal chat reconciliation, so an untested ordering edge could duplicate, suppress, or stale-associate assistant finals in the browser transcript.
  • [P1] The supplied proof exercises the real WebChat renderer through a gateway-shaped WebSocket path, not a live provider or merge-ref browser run; that is reasonable for this UI event-ordering bug, but maintainers may want one final merge-ref smoke before landing.

Maintainer options:

  1. Run One Merge-Ref WebChat Smoke (recommended)
    Before merge, maintainers can ask for a merge-result browser smoke that verifies one assistant answer and one reasoning block after the text-only terminal final path.
  2. Land With Owner Review
    If maintainers accept the event-ordering tradeoff based on the current proof and green checks, this can land as the focused fix for the linked regression.
  3. Pause For Live Provider Proof
    Pause only if maintainers require a live external provider WebChat run instead of the current gateway-shaped browser proof for this UI repaint bug.

Next step before merge

  • No automated repair is needed; the remaining action is maintainer review of the WebChat session-state and message-delivery tradeoff before merge.

Security
Cleared: The diff is limited to Control UI event/history reconciliation and tests, with no dependency, workflow, credential, package, or code-execution surface changes found.

Review details

Best possible solution:

Land this PR or an equivalent narrow fix after maintainer review of the WebChat session/message ordering risk, then close the linked regression issue once the fix reaches main.

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

Yes, at source level. Current main skips history reload for renderable text-only finals while WebChat renders reasoning from the displayed message, so persisted thinking can remain hidden until a manual refresh.

Is this the best way to solve the issue?

Yes. This is the narrowest maintainable fix I found: track only thinking-bearing deferred session messages and reload only when the terminal final lacks that thinking, rather than restoring unconditional final reloads that current code avoids for flicker reasons.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority WebChat regression fix with limited blast radius but real visible reasoning/message impact.
  • merge-risk: 🚨 session-state: The diff changes how selected-session session.message updates keep pending state while a local WebChat run is active.
  • merge-risk: 🚨 message-delivery: The diff changes terminal final reload and late-final dedupe behavior, where mistakes could duplicate or suppress assistant messages.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes after-fix Playwright Chromium DOM live output from the actual WebChat renderer via a gateway-shaped WebSocket path showing one final answer, one reasoning text, and one thinking block.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix Playwright Chromium DOM live output from the actual WebChat renderer via a gateway-shaped WebSocket path showing one final answer, one reasoning text, and one thinking block.
Evidence reviewed

PR surface:

Source +85, Tests +492. Total +577 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 102 17 +85
Tests 3 493 1 +492
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 595 18 +577

What I checked:

  • Repository policy read: Root AGENTS.md and the scoped UI guide were read fully; the review applied the repository's deeper PR-review and UI/session-state merge-risk guidance. (AGENTS.md:1, b885c81479d0)
  • Current main reload predicate: Current main only reloads history for final events when the final lacks a renderable assistant message, so a normal text-only final does not repaint persisted thinking. (ui/src/ui/chat-event-reload.ts:24, b885c81479d0)
  • Current main deferred reload handling: Current main resolves a deferred session-message reload only through the ordinary final reload predicate and has no thinking-aware pending flag. (ui/src/ui/app-gateway.ts:1084, b885c81479d0)
  • Renderer depends on rendered-message thinking: The grouped WebChat renderer extracts reasoning from the message being rendered, so a text-only live final cannot show persisted reasoning unless history reloads or the final carries thinking. (ui/src/ui/chat/grouped-render.ts:1689, b885c81479d0)
  • PR reload predicate: At PR head, shouldReloadHistoryForFinalEvent reloads when a deferred thinking-bearing session message exists and the terminal final lacks a thinking block, while preserving the normal no-reload path otherwise. (ui/src/ui/chat-event-reload.ts:28, f68625750c83)
  • PR pending-thinking tracking: At PR head, WebChat records thinking-bearing session.message payloads during an active run and passes that state into terminal chat reconciliation. (ui/src/ui/app-gateway.ts:1039, f68625750c83)

Likely related people:

  • shakkernerd: Commit 5e28574 added the source-reply final no-reload behavior that made this deferred-thinking repaint gap visible. (role: regression-provenance contributor; confidence: high; commits: 5e2857477b9f; files: ui/src/ui/app-gateway.ts)
  • steipete: Commit dc6afeb introduced shouldReloadHistoryForFinalEvent and the earlier WebChat final-event reload optimization. (role: introduced current reload gate; confidence: medium; commits: dc6afeb4f882; files: ui/src/ui/chat-event-reload.ts, ui/src/ui/app-gateway.ts)
  • scotthuang: Merged PR 92746 changed active-run and session.message reconciliation around the same WebChat/gateway ordering surface. (role: recent adjacent owner; confidence: high; commits: b3dc27403498; files: ui/src/ui/app-gateway.ts, src/gateway/server-session-events.ts)
  • osolmaz: Commit 17a285f recently changed chat history and stream reconciliation in the controller path that applies this PR's post-final reload. (role: current chat reconciliation contributor; confidence: medium; commits: 17a285f29825; files: ui/src/ui/controllers/chat.ts)
  • TurboTheTurtle: The contributor authored this focused PR and recently landed adjacent WebChat rendering work in PR 97575, so they are a practical follow-up contact beyond being this PR's proposer. (role: recent adjacent WebChat contributor; confidence: medium; commits: f68625750c83, 180a960ede9e; files: ui/src/ui/app-gateway.ts, ui/src/ui/chat-event-reload.ts, ui/src/ui/controllers/chat.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (1 earlier review cycle)
  • reviewed 2026-06-21T18:58:48.937Z sha f686257 :: needs maintainer review before merge. :: none

@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. labels Jun 10, 2026
@TurboTheTurtle

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 10, 2026
@clawsweeper

clawsweeper Bot commented Jun 10, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 10, 2026
@clawsweeper clawsweeper Bot added 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. and removed 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. labels Jun 10, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 10, 2026
@TurboTheTurtle

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Latest fix pushed at f68625750c83ef3eeb08fee396801b28e474fab3 for the P2 repeated-final finding.

Fix update:

  • Tightened the reasoning-aware late-final dedupe so an older same-text reasoning message that was already present before the history request cannot suppress a newer repeated terminal final from stale history.
  • Added a regression test: stale history with older reasoning + same visible text preserves the newer user message and newer text-only final.
  • Reran current-head browser proof with a timestamped terminal final payload; the DOM still has one final answer, one reasoning text, and one thinking block.

Validation:

  • node scripts/run-vitest.mjs ui/src/ui/chat-event-reload.test.ts ui/src/ui/app-gateway.node.test.ts ui/src/ui/controllers/chat.test.ts -> 3 files passed, 199 tests passed
  • pnpm check:test-types -> passed
  • pnpm exec oxfmt --check --threads=1 ui/src/ui/app-gateway.ts ui/src/ui/chat-event-reload.ts ui/src/ui/app-gateway.node.test.ts ui/src/ui/chat-event-reload.test.ts ui/src/ui/controllers/chat.ts ui/src/ui/controllers/chat.test.ts -> passed
  • git diff --check -> passed

Current-head browser proof:

{
  "head": "f68625750c83ef3eeb08fee396801b28e474fab3",
  "workingTreeStatus": "clean",
  "scenario": "WebChat deferred session.message thinking followed by timestamped terminal final payload without thinking",
  "browser": "Playwright Chromium",
  "sessionKey": "main",
  "activeSessionReasoningLevel": "low",
  "activeSessionThinkingLevel": "low",
  "sessionsListRequests": 1,
  "chatHistoryRequests": 2,
  "finalAnswerCount": 1,
  "reasoningCount": 1,
  "thinkingBlockCount": 1,
  "observedFinalText": "Final answer proof marker 91810",
  "observedReasoningText": "private reasoning proof marker 91810",
  "screenshotPath": "/Users/andy/openclaw-91810/.artifacts/pr-91810-proof/webchat-deferred-reasoning-current-head.png"
}

@clawsweeper

clawsweeper Bot commented Jun 10, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 10, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jun 19, 2026
@TurboTheTurtle

Copy link
Copy Markdown
Contributor Author

Closing because the current Control UI refactor already handles the deferred terminal history reload in the new chat-state path. Rebasing this older implementation would duplicate behavior on obsolete UI modules. Leaving #91727 open for any remaining current-main verification.

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 merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

[Regression] WebChat does not render reasoning live for any model after #87671 (only appears after manual refresh)

1 participant