Skip to content

fix(ui): restore in-flight streaming assistant reply on Control UI reconnect (#90755) - #92969

Closed
Alix-007 wants to merge 2 commits into
openclaw:mainfrom
Alix-007:fix/controlui-reconnect-inflight-90755
Closed

Alix-007 wants to merge 2 commits into
openclaw:mainfrom
Alix-007:fix/controlui-reconnect-inflight-90755

Conversation

@Alix-007

Copy link
Copy Markdown
Contributor

Summary

  • Control UI lost the in-progress assistant reply on reconnect: after switching away from a running chat and back (or reloading), the thread showed only the last committed user message while the streaming assistant response disappeared.
  • The gateway already exposes the still-streaming run via the existing chat.history / chat.startup inFlightRun payload (built from chatAbortControllers / chatRunBuffers and bounded by boundInFlightRunSnapshotForChatHistory), and the TUI history loader already consumes it (src/tui/tui-session-actions.ts). The Control UI history loader did not.
  • This patch makes the Control UI consume the same inFlightRun contract: the loader re-adopts the in-flight run id, rehydrates the buffered partial into chatStream, and sets chatStreamStartedAt, so the partial renders again and subsequent live deltas/final continue on the adopted run. It is symmetric with the TUI fix and adds no new reconnect subsystem or wire-protocol change.
  • Adoption is guarded to only run when no run survived local stream reconciliation (resetStream && !state.chatRunId), so a fresher live local stream is never clobbered by a slightly stale history snapshot. Empty buffered text (e.g. Codex-style runtimes that only deliver assistant text at completion, or text dropped by the history budget) still adopts the run so the thread shows streaming (reading indicator) instead of looking idle.

This is the Control UI parity fix ClawSweeper called out as the best narrow solution on the issue, and the path the HTTP-only PR #90832 did not cover.

Linked context

Closes #90755

Real behavior proof

  • Behavior or issue addressed: Control UI reconnect dropped the in-flight streaming assistant reply; the gateway-provided chat.history/chat.startup inFlightRun payload was never adopted by the browser history loader, so on switch-back/reload the thread showed only committed history.
  • Real environment tested: local openclaw from source on Linux (real Control UI build served by Vite, driven in a real headless Chrome via the repo's Playwright e2e harness ui/src/ui/e2e/chat-flow.e2e.test.ts against the mock gateway; system Chrome 138 used via PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH since the Playwright CDN is blocked on this host).
  • Exact steps or command run after this patch:
    1. PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/google-chrome node node_modules/.bin/vitest run --config test/vitest/vitest.ui-e2e.config.ts ui/src/ui/e2e/chat-flow.e2e.test.ts -t "in-flight streaming assistant reply on reconnect"
    2. The browser loads /chat; the gateway returns committed history = only the user turn, plus inFlightRun: { runId, text: "Streaming the summary so" }. The test asserts the partial assistant text becomes visible in the real .chat-thread DOM, then emits a live final on the adopted run and asserts it renders.
  • Evidence after fix (terminal capture):
 RUN  v4.1.7 /…/wt-90755

 ✓ |ui-e2e| ui/src/ui/e2e/chat-flow.e2e.test.ts > Control UI mocked Gateway E2E > restores the in-flight streaming assistant reply on reconnect (#90755) 5838ms

 Test Files  1 passed (1)
      Tests  1 passed | 13 skipped (14)
   Start at  15:24:34
   Duration  5.31s

Negative control (proves the assertion is real behavior, not a tautology): with the loader change reverted (git stash of ui/src/ui/controllers/chat.ts only) and the same e2e run, the real browser never renders the partial and the test fails on exactly that visibility wait:

 × restores the in-flight streaming assistant reply on reconnect (#90755) 12684ms
   - waiting for locator('.chat-thread').getByText('Streaming the summary so') to be visible
     987|       await page.locator(".chat-thread").getByText("Streaming the summ…
 Test Files  1 failed (1)
      Tests  1 failed | 13 skipped (14)
  • Observed result after fix: in the real browser, after reconnect the in-progress assistant reply ("Streaming the summary so") is restored and visible in the chat thread alongside the committed user turn, and the adopted run continues to receive its live final ("…the reconnect keeps it."). Without the fix the reply is absent (reproduces the reported bug).
  • What was not tested: active tool-call snapshot replay across reconnect — out of scope for this issue and noted by ClawSweeper as a possible follow-up; only buffered assistant text + run adoption is addressed here. Real multi-runtime backends (Codex etc.) were not spun up; the empty-text adoption path is covered by unit tests and mirrors the already-shipped TUI behavior.
  • Proof limitations or environment constraints: the live proof drives the real Control UI bundle in real headless Chrome, but the gateway is the repo's standard e2e mock gateway (a full live agent/gateway browser session was not run on this host). The Playwright Chromium download is blocked on this host, so the system Chrome 138 binary was used via PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH. The symmetric TUI fix (src/tui/tui-session-actions.ts) and the gateway already emitting bounded inFlightRun corroborate the end-to-end behavior.

Tests and validation

  • Added 4 unit tests (ui/src/ui/controllers/chat.test.ts): buffered in-flight text restored on reconnect; empty-text in-flight run adopted (streaming, not idle); inFlightRun without a run id ignored; a fresher live local run not clobbered by a stale snapshot.
  • Added 1 Playwright e2e test (ui/src/ui/e2e/chat-flow.e2e.test.ts) rendering the real Control UI in a real browser (see proof above), with a verified negative control.
  • node scripts/run-vitest.mjs ui/src/ui/controllers/chat.test.ts → 121 passed.
  • node scripts/run-vitest.mjs ui/src/ui/views/chat.test.ts ui/src/ui/chat/build-chat-items.test.ts → 136 passed (related rendering/view suites green).
  • oxlint and oxfmt --write clean on all changed files.

Risk checklist

  • Scope: one Control UI source file (ui/src/ui/controllers/chat.ts, +29 incl. comments / ~9 logic lines) plus tests; no gateway, wire-protocol, or HTTP-payload changes.
  • The inFlightRun snapshot is already bounded by the gateway (boundInFlightRunSnapshotForChatHistory), so no unbounded reconnect payload is introduced by this UI-side change.
  • Adoption only triggers when no local run survived stream reconciliation, so it cannot override a fresher in-progress stream; empty payloads degrade to a reading indicator rather than an idle thread.
  • No secrets, auth, dependency, or permission changes.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: S proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 14, 2026, 12:59 PM ET / 16:59 UTC.

Summary
The PR makes the Control UI history loader adopt the existing inFlightRun payload and adds unit plus Playwright e2e coverage for reconnect restoration.

PR surface: Source +34, Tests +149. Total +183 across 3 files.

Reproducibility: yes. Current main has a high-confidence source reproduction path: the gateway returns bounded inFlightRun, the TUI consumes it, but the Control UI history loader ignores it after session-switch stream clearing; I did not execute tests in this read-only review.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: vector/embedding metadata: ui/src/ui/e2e/chat-flow.e2e.test.ts. Confirm migration or upgrade compatibility proof before merge.

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

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

Risk before merge

  • [P1] Active tool-call snapshot replay is explicitly out of scope for this PR; the text/run adoption fix is still useful, but maintainers may want a separate follow-up if tool-call catch-up remains user-visible.

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused Control UI adoption fix after maintainer review, and track active tool-call snapshot replay separately if it remains a required reconnect behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No ClawSweeper repair lane is needed because no actionable patch defect was found; the remaining action is maintainer review and merge judgment.

Security
Cleared: The diff only changes a UI controller and UI tests, with no dependency, workflow, permission, secret, package, or generated supply-chain surface change.

Review details

Best possible solution:

Land the focused Control UI adoption fix after maintainer review, and track active tool-call snapshot replay separately if it remains a required reconnect behavior.

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

Yes. Current main has a high-confidence source reproduction path: the gateway returns bounded inFlightRun, the TUI consumes it, but the Control UI history loader ignores it after session-switch stream clearing; I did not execute tests in this read-only review.

Is this the best way to solve the issue?

Yes. The PR uses the existing gateway/TUI inFlightRun contract in the Control UI rather than adding a new protocol or reconnect subsystem, and the guard avoids overwriting a fresher live local stream.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix headless Chrome e2e terminal output, observed DOM behavior, and a negative control for the same reconnect assertion.

Label justifications:

  • P2: This is a normal-priority Control UI session continuity bug fix with limited blast radius but real user-visible session/message continuity impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix headless Chrome e2e terminal output, observed DOM behavior, and a negative control for the same reconnect assertion.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix headless Chrome e2e terminal output, observed DOM behavior, and a negative control for the same reconnect assertion.
Evidence reviewed

PR surface:

Source +34, Tests +149. Total +183 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 35 1 +34
Tests 2 149 0 +149
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 184 1 +183

What I checked:

  • Repository policy read: Root AGENTS.md and scoped ui/AGENTS.md were read fully; the root review policy required whole-path source review, while the scoped UI guide added no i18n obligations for these files. (AGENTS.md:1, 7e12a3326dd2)
  • Current main UI gap: Current main's ChatHistoryResult has no inFlightRun field and the history reload path can clear chatStream without adopting the active run snapshot. (ui/src/ui/controllers/chat.ts:420, 7e12a3326dd2)
  • Existing gateway contract: Current main already resolves and bounds an in-flight run for chat.history/chat.startup, preserving the run id while keeping history payload size bounded. (src/gateway/server-methods/chat.ts:2661, 7e12a3326dd2)
  • Sibling TUI parity: The TUI history loader already consumes record.inFlightRun, renders buffered text when present, adopts the run id, and sets streaming status. (src/tui/tui-session-actions.ts:521, 7e12a3326dd2)
  • PR implementation: The PR adds inFlightRun to the Control UI history result and adopts it only after stream reconciliation when no local run survived, avoiding clobber of fresher local streams. (ui/src/ui/controllers/chat.ts:817, 1731908efcd3)
  • Regression coverage: The PR adds unit coverage for buffered adoption, empty-text adoption, missing run id, and fresher local stream preservation, plus a browser e2e that renders the partial and then accepts the final on the adopted run. (ui/src/ui/controllers/chat.test.ts:3386, 1731908efcd3)

Likely related people:

  • vincentkoc: Recent history and blame show multiple changes around ui/src/ui/controllers/chat.ts, including startup metadata, chat timing, startup hydration, and the current history reconciliation block this PR extends. (role: recent Control UI chat-history contributor; confidence: high; commits: 2c6bdc8b2831, b1fccd06058e, c69a8d633d45; files: ui/src/ui/controllers/chat.ts)
  • williamliu-ai: Commit history shows this person authored the TUI switch-back in-flight run behavior that the PR mirrors for the Control UI. (role: sibling in-flight run implementation author; confidence: high; commits: 8eeb9300df40; files: src/tui/tui-session-actions.ts, src/gateway/chat-abort.ts, src/gateway/server-methods/chat.ts)
  • Fermin Quant: Recent session-history work is adjacent to the existing in-flight history contract consumed by this PR. (role: gateway/session history contributor; confidence: medium; commits: 57bed6ae0c4b; files: src/gateway/chat-abort.ts, src/gateway/server-methods/chat.ts)
  • osolmaz: Recent Control UI stream preservation work touches the same chat stream reconciliation behavior that guards this PR's adoption path. (role: adjacent stream reconciliation contributor; confidence: medium; commits: 17a285f29825; files: 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.

@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. labels Jun 14, 2026
@Alix-007

Copy link
Copy Markdown
Contributor Author

@vincentkoc when you have a window — this is the Control UI parity fix for the in-flight streaming reply being lost on reconnect (#90755), the narrow solution ClawSweeper called the best fit. Diamond-rated with sufficient proof (real headless-Chrome e2e + a negative control), CI green, mergeable clean; it covers the Control-UI side that the HTTP-only #90832 does not.

A few of my other small fixes are sitting green-and-ready as well if you are doing a sweep — all narrow, all with sufficient proof and clean/mergeable: #89260 (doctor platform-skill rollup, reviewer concern just closed out), #88988 (status footer), #87487 (mcp list scope). Happy to rebase or trim any of them on request.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Hi @vincentkoc — I see you're sweeping the TUI/UI surface today (just merged the tui spinner fix #92909). This Control UI reconnect fix is right in that area and ready to slot into the sweep: diamond-rated, sufficient proof (real headless-Chrome e2e + a negative control), CLEAN/mergeable. It is the narrow Control-UI-parity solution ClawSweeper flagged as the best fit for #90755, covering the Control-UI side that the HTTP-only #90832 does not touch. Happy to rebase on request.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 14, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 14, 2026
@vincentkoc vincentkoc self-assigned this Jun 14, 2026

@vincentkoc vincentkoc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review found that the reconnect adoption path needs a canonical stream reconciliation step before this is safe to merge:

  • inFlightRun.text is the accumulated gateway buffer and can overlap assistant text already returned in history, so assigning it wholesale can duplicate persisted prefixes/final text.
  • Re-adopting a run must clear stale terminal run status.
  • Refreshing an already-owned empty-text run must preserve its reading indicator instead of appearing idle.

Best fix: reconcile the in-flight snapshot against returned history and surviving local stream state in one helper, rendering only an unpersisted tail while clearing stale terminal state and preserving supported empty active streams. Local guards for each symptom will keep producing edge cases.

@vincentkoc

Copy link
Copy Markdown
Member

Closing this implementation after maintainer deep review. The reported reconnect bug in #90755 is valid, but this patch is not safe to land as written: inFlightRun.text is the cumulative live buffer across tool phases, while chat.history can already contain visible assistant progress from the same active turn. Assigning the full buffer to chatStream can therefore duplicate persisted text, and later cumulative deltas can reintroduce the duplicated prefix even if the initial load trims it locally.

The correct fix needs a canonical gateway/history contract that identifies or carries the unpersisted portion of the active run, then lets both Control UI and TUI adopt it without text inference. #90755 remains open for that owner-boundary fix. Thanks for the strong focused proof and for surfacing the missing Control UI behavior.

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 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

Bug: reconnecting to a running session only shows last user message, missing agent's in-progress response

2 participants