Skip to content

fix(ui): restore in-flight streaming assistant reply on Control UI session switch-back - #95025

Closed
wings1029 wants to merge 2 commits into
openclaw:mainfrom
wings1029:fix/issue-90755-control-ui-restore-in-flight-run-on-reconnect
Closed

wings1029 wants to merge 2 commits into
openclaw:mainfrom
wings1029:fix/issue-90755-control-ui-restore-in-flight-run-on-reconnect

Conversation

@wings1029

@wings1029 wings1029 commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When you switch away from a Control UI chat session while the agent is actively generating a response and then switch back, the in-progress streaming reply was lost — only the last user message was shown.

The gateway already exposes the still-streaming run via chat.history / chat.startup responses (the inFlightRun field), and the TUI already uses this to restore state on reconnect. The Control UI was simply ignoring it.

Fixes #90755.

Root cause

Three things were missing in ui/src/ui/controllers/chat.ts:

  1. ChatHistoryResult type didn't include inFlightRun — the field was silently dropped
  2. No adoption logic — the history loader ignored the gateway's in-flight run data
  3. The maintainer's concern from previous PRs: inFlightRun.text is the cumulative gateway buffer that overlaps with already-persisted assistant messages; without reconciliation, the UI would show duplicate text

Three previous PRs attempted this fix (#90832, #92969, #93273) but all were closed — two because they lacked the text reconciliation step.

Change

File Change
ui/src/ui/controllers/chat.ts Add inFlightRun to ChatHistoryResult type
ui/src/ui/controllers/chat.ts Create adoptInFlightRunFromChatHistory() with text overlap reconciliation
ui/src/ui/controllers/chat.ts Call adoption after stream reconciliation when no fresher local run exists
ui/src/ui/controllers/chat.test.ts Add 5 tests covering: basic adoption, empty-text adoption, overlap reconciliation, missing runId, and local-run preservation

Reconciliation logic

inFlightRun.text: "Silent pond,\nA frog jumps in—\nSplash!"
last committed assistant: "Silent pond,"
→ Adopted stream text: "\nA frog jumps in—\nSplash!"

This prevents duplicating already-persisted text while preserving the new suffix.

Evidence

  • ✅ Restores buffered in-flight assistant stream on switch-back
  • ✅ Adopts empty-text run for reading-in-progress state
  • ✅ Applies text overlap reconciliation to avoid duplicated content
  • ✅ Preserves the local in-progress run when one already exists
  • ✅ Cleans up properly when runId is missing
  • ✅ All 5 new tests pass in ui/src/ui/controllers/chat.test.ts

Risk

  • Low risk: only affects Control UI session switch-back edge case
  • The inFlightRun field is already returned by the gateway for TUI usage
  • Text reconciliation logic handles the overlap corner case that blocked prior PRs
  • No changes to gateway, protocol, or other UI surfaces

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 28, 2026, 11:20 PM ET / 03:20 UTC.

Summary
The PR teaches the Control UI chat history loader to adopt gateway inFlightRun data on session switch-back and adds controller tests for buffering, overlap trimming, stale errors, and local-run preservation.

PR surface: Source +84, Tests +197. Total +281 across 2 files.

Reproducibility: yes. at source level: a history response with a committed assistant prefix plus cumulative inFlightRun.text makes this PR store only the suffix, and the next cumulative gateway delta can return the full snapshot through the current UI delta resolver.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #90755
Summary: This PR is an open candidate fix for the canonical Control UI in-flight run reconnect issue, with prior same-surface PRs closed or superseded and the merged TUI/Gateway work only partially overlapping.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Fix the adopted stream baseline so later cumulative gateway deltas cannot duplicate persisted assistant text.
  • [P1] Add a regression test that loads an overlapping inFlightRun and then handles the next delta for the same run.
  • [P1] Add redacted real Control UI switch-back proof in the PR body after the code is corrected.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only unit-test/CI evidence is present; add redacted screenshot, recording, terminal/live output, linked artifact, or logs from a real Control UI switch-back and update the PR body to trigger a fresh review, or ask a maintainer for @clawsweeper re-review.

Mantis proof suggestion
A visible Control UI browser proof would materially help because the changed behavior is a session switch-back flow and the current proof is test-only. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis visual task: verify Control UI switching away from and back to a running chat restores the in-flight reply and the next delta does not duplicate persisted assistant text.

Risk before merge

  • [P1] Merging as-is can duplicate already-persisted assistant text when the next cumulative gateway delta arrives after suffix-only adoption.
  • [P1] The PR changes active run/session state and visible message delivery in the Control UI without after-fix proof from a real browser or live setup.

Maintainer options:

  1. Repair the cumulative stream contract (recommended)
    Keep state.chatStream compatible with later cumulative gateway snapshots, or move the unpersisted-tail contract into history before adopting it in Control UI, then cover adoption followed by the next delta.
  2. Pause in favor of the canonical issue
    If the branch cannot resolve the owner-boundary contract and proof gap, keep the canonical issue open and close or replace this PR with a narrower implementation.

Next step before merge

  • [P1] Contributor action and maintainer review are needed because the external PR has a blocking code defect and lacks author-supplied real behavior proof; ClawSweeper should not take over proof for the contributor setup.

Security
Cleared: No concrete security or supply-chain concern was found; the diff only changes a Control UI controller and colocated tests.

Review findings

  • [P1] Preserve the cumulative stream baseline — ui/src/ui/controllers/chat.ts:737
Review details

Best possible solution:

Revise the PR so adopted in-flight state remains compatible with cumulative gateway snapshots/deltas, cover adoption followed by a later delta, and add real Control UI switch-back proof.

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

Yes at source level: a history response with a committed assistant prefix plus cumulative inFlightRun.text makes this PR store only the suffix, and the next cumulative gateway delta can return the full snapshot through the current UI delta resolver.

Is this the best way to solve the issue?

No. The narrow Control UI adoption direction is reasonable, but this implementation still needs a cumulative-baseline-safe reconciliation or a canonical unpersisted-tail contract before it is the best fix.

Full review comments:

  • [P1] Preserve the cumulative stream baseline — ui/src/ui/controllers/chat.ts:737
    This stores only the unpersisted suffix in state.chatStream, but the next gateway delta still carries a cumulative assistant snapshot. resolveDeltaChatStreamText will compare that cumulative prefix against the suffix, treat it as a mismatch, and return the full snapshot, so the previously persisted assistant prefix can render a second time. Keep the adopted baseline compatible with later cumulative deltas, or change the gateway/history contract to carry a true unpersisted tail and cover adoption plus a following delta.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.89

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority Control UI session/message continuity bug with limited blast radius but real user-visible impact.
  • merge-risk: 🚨 session-state: The PR re-adopts active run ids and stream state after history reload, and the current implementation can leave the selected session with an inconsistent stream baseline.
  • merge-risk: 🚨 message-delivery: The suffix-only adoption path can cause already-persisted assistant text to render again when the next cumulative delta is delivered.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only unit-test/CI evidence is present; add redacted screenshot, recording, terminal/live output, linked artifact, or logs from a real Control UI switch-back and update the PR body to trigger a fresh review, or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +84, Tests +197. Total +281 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 84 0 +84
Tests 1 197 0 +197
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 281 0 +281

What I checked:

  • Repository policy read: Root and scoped UI policy were read fully; root review policy affected this review because the PR changes Control UI session state/message delivery and requires whole-path review plus real behavior proof. (AGENTS.md:1, 2001b15f5b92)
  • PR stores a trimmed suffix as live stream baseline: At PR head, adoptInFlightRunFromChatHistory trims overlap against the last committed assistant message and stores the remaining suffix in state.chatStream. (ui/src/ui/controllers/chat.ts:737, 18eed42d5038)
  • PR adopts that suffix after history stream reset: The PR calls the adoption helper after history reconciliation when resetStream is true and no local run remains, so the suffix becomes the active baseline for subsequent events. (ui/src/ui/controllers/chat.ts:915, 18eed42d5038)
  • Current delta resolver expects a cumulative baseline: Current main's resolveDeltaChatStreamText compares the cumulative snapshot prefix against currentStream; if a suffix-only stream is active, it returns the full snapshot and can re-render persisted prefix text. (ui/src/ui/controllers/chat.ts:538, 2001b15f5b92)
  • Gateway sends cumulative assistant text with deltas: Current main merges live assistant text into mergedText, stores it as the run buffer, and sends that cumulative text in payload.message.content alongside deltaText. (src/gateway/server-chat.ts:781, 2001b15f5b92)
  • Maintainer-review context from prior attempt: A prior same-surface PR was closed after review because local text inference around cumulative inFlightRun.text was unsafe; the remaining canonical issue asks for a safer gateway/history contract or reconciliation shape.

Likely related people:

  • vincentkoc: Reviewed the prior same-surface implementation with the cumulative-buffer concern and appears repeatedly in recent ui/src/ui/controllers/chat.ts chat-history/startup work. (role: prior reviewer and recent Control UI chat-history contributor; confidence: high; commits: 2c6bdc8b2831, c69a8d633d45, b09b35c13c17; files: ui/src/ui/controllers/chat.ts)
  • williamliu-ai: Authored the merged Gateway/TUI chat.history.inFlightRun snapshot and TUI switch-back adoption path that this PR consumes from Control UI. (role: sibling in-flight run contract author; confidence: high; commits: 8eeb9300df40; files: src/gateway/chat-abort.ts, src/gateway/server-methods/chat.ts, src/tui/tui-session-actions.ts)
  • osolmaz: Authored recent Control UI stream/history reconciliation work in the same loader and rendering path affected by this PR. (role: adjacent stream reconciliation contributor; confidence: medium; commits: 17a285f29825; files: ui/src/ui/controllers/chat.ts, ui/src/ui/chat/stream-reconciliation.ts, ui/src/ui/controllers/chat.test.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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 19, 2026
wings1029 and others added 2 commits June 29, 2026 10:55
…ssion switch-back

- Add inFlightRun to ChatHistoryResult type so the Control UI receives the
  gateway's existing in-flight run data on chat.history / chat.startup.
- Create adoptInFlightRunFromChatHistory() with text reconciliation: strip
  any overlap between the cumulative in-flight buffer and the last committed
  assistant message to avoid duplicating already-persisted text.
- Call adoption after stream reconciliation when no fresher local run exists,
  mirroring the TUI loader in src/tui/tui-session-actions.ts.

Fixes openclaw#90755
…iliation, clear stale errors, add edge-case tests

Co-Authored-By: Claude <[email protected]>
@wings1029
wings1029 force-pushed the fix/issue-90755-control-ui-restore-in-flight-run-on-reconnect branch from 4e968f2 to 18eed42 Compare June 29, 2026 03:10
@steipete steipete self-assigned this Jul 6, 2026
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks @wings1029 for pursuing #90755.

Closing this branch because the submitted client-side overlap heuristic cannot preserve the Gateway stream contract safely, and the touched Control UI controller paths have since been replaced.

inFlightRun.text and subsequent chat deltas are cumulative snapshots. This patch trims persisted history from the snapshot and stores only the suffix as the local stream baseline. On the next cumulative event, the baseline no longer matches the Gateway snapshot, so the client can restore the full snapshot and duplicate already-persisted text. Additional whitespace normalization cannot identify the true persisted/unpersisted boundary reliably.

The canonical issue remains open. The landable fix needs a Gateway-owned active-run projection with an explicit visible/unpersisted boundary while retaining the cumulative baseline for later deltas, consumed consistently by both Control UI and TUI. Required proof should cover switch-away/back, persisted tool-phase prefixes, the next cumulative delta, finalization, and stale-local-run protection in a real mocked-Gateway Chromium flow.

This is the same contract gap that blocked the older attempts #92969 and #93273; keeping another heuristic branch open would invite an unsafe partial merge.

@steipete steipete closed this Jul 6, 2026
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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

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