Skip to content

fix(gateway): surface in-progress assistant response on session reconnect - #90832

Closed
lonexreb wants to merge 1 commit into
openclaw:mainfrom
lonexreb:fix/90755-reconnect-show-in-progress-response
Closed

lonexreb wants to merge 1 commit into
openclaw:mainfrom
lonexreb:fix/90755-reconnect-show-in-progress-response

Conversation

@lonexreb

@lonexreb lonexreb commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Bug (Bug: reconnecting to a running session only shows last user message, missing agent's in-progress response #90755): reconnecting to a running session via the Control UI shows only the last committed user message; the agent's streaming text/tool calls are invisible until the run completes.
  • Root cause: the JSON-RPC chat.history method already surfaces inFlightRun from chatAbortControllers/chatRunBuffers, but the HTTP /sessions/:sessionKey/history (REST + SSE) endpoint had no view into those maps.
  • Fix: thread an optional SessionHistoryInFlightRunResolver from server-runtime-state (which owns the run maps) through createGatewayHttpServer into handleSessionHistoryHttpRequest, and forward the resolved { runId, text } snapshot in both the JSON body and the initial SSE history event.

Real behavior proof

Behavior addressed: reconnect to a running session over the HTTP session-history endpoint now carries the active run's id and any buffered partial assistant text, letting the Control UI restore the in-progress response instead of falling back to the last committed user message.
Real environment tested: local vitest in worktree
Exact steps or command run after this patch: node scripts/run-vitest.mjs src/gateway/sessions-history-http.in-flight-run.test.ts && node scripts/run-vitest.mjs src/gateway/sessions-history-http.test.ts && node scripts/run-vitest.mjs src/gateway/sessions-history-http.revocation.test.ts && node scripts/run-vitest.mjs src/gateway/chat-abort.test.ts && node scripts/run-vitest.mjs src/gateway/server-runtime-state.test.ts
Evidence after fix: new test file src/gateway/sessions-history-http.in-flight-run.test.ts passes; existing sessions-history-http (16/16), revocation suite (12/12), chat-abort suite (108/108), and server-runtime-state (2/2) all stay green.
Observed result after fix: SSE history event/JSON payload includes inFlightRun: { runId, text } whenever the gateway runtime resolver reports an active run for the session key (canonical or requested), and remains absent when no active run is in flight.
What was not tested: live multi-channel reconnect against a real running agent and Control UI client roundtrip.

Fixes #90755

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 6, 2026
@clawsweeper

clawsweeper Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR in favor of the still-open canonical issue because the branch adds an HTTP-only in-flight snapshot path, while the remaining accepted work now needs a canonical gateway/history contract for the unpersisted active-run portion before any client adopts it.

Canonical path: Keep the still-open canonical issue as the owner-boundary work item, design the gateway/history contract for the unpersisted active-run portion, then update Control UI and TUI against that single contract with real reconnect proof.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Keep the still-open canonical issue as the owner-boundary work item, design the gateway/history contract for the unpersisted active-run portion, then update Control UI and TUI against that single contract with real reconnect proof.

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

Yes. Source inspection shows the Control UI session switch clears local stream/run state, then reloads via JSON-RPC chat.history while current ChatHistoryResult ignores inFlightRun; I did not execute a live browser repro in this read-only review.

Is this the best way to solve the issue?

No. This PR is an HTTP-only parity change and now conflicts with the maintainer-stated need for a canonical gateway/history contract that carries only the unpersisted active-run portion.

Security review:

Security review cleared: No dependency, workflow, permission, package, credential, or generated supply-chain surface changed; the blockers are functional contract and availability risks.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy: Root and gateway-scoped AGENTS.md were read fully; their review guidance requires whole gateway caller/callee review, sibling-surface checks, and real behavior proof for user-visible fixes. (AGENTS.md:15, 7a7165ad22c4)
  • PR diff is HTTP-only: The branch forwards resolveSessionHistoryInFlightRun only into the HTTP session-history request stage; it does not update the Control UI history loader that the linked report exercises. (src/gateway/server-http.ts:672, 17365b8ef9e1)
  • Unsafe response contract: The PR emits the resolver snapshot directly in JSON/SSE history responses; the current JSON-RPC chat.history path applies boundInFlightRunSnapshotForChatHistory before returning inFlightRun. (src/gateway/sessions-history-http.ts:211, 17365b8ef9e1)
  • Current main Control UI gap: Current main still has no inFlightRun field in ChatHistoryResult, and loadChatHistory applies committed messages without adopting an active run snapshot after session-switch stream clearing. (ui/src/ui/controllers/chat.ts:420, 7a7165ad22c4)
  • Canonical remaining work: The linked issue remains open, and a related UI-only PR was closed by a member comment saying the correct fix needs a canonical gateway/history contract that identifies or carries the unpersisted portion of the active run for both Control UI and TUI.
  • Canonical search: Live search by the linked issue number finds this PR, the closed related UI PR, and the still-open canonical issue; no merged replacement PR was found.

Likely related people:

  • williamliu-ai: Commit history shows this person authored the earlier gateway/TUI in-flight switch-back work that this PR tries to extend into HTTP history. (role: introduced sibling in-flight history contract; confidence: high; commits: 8eeb9300df40; files: src/gateway/chat-abort.ts, src/gateway/server-methods/chat.ts, src/tui/tui-session-actions.ts)
  • vincentkoc: Recent commits touch Control UI and gateway chat-history adjacent code, and the related UI PR was closed with owner-boundary guidance from this person. (role: recent area contributor and reviewer; confidence: high; commits: 2c6bdc8b2831, cf4000b47b78, f85ef0d1147f; files: ui/src/ui/controllers/chat.ts, src/gateway/server-methods/chat.ts)
  • RomneyDa: Recent TUI session-history/reconnect work is adjacent to the sibling client behavior that a canonical active-run contract would need to preserve. (role: adjacent TUI session-history contributor; confidence: medium; commits: ac9a219692aa, 8b84e951e5a6; files: src/tui/tui-session-actions.ts)

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

@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: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 6, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.

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

1 participant