Skip to content

fix: queued chat follow-ups stay stuck after missed terminal events - #124054

Closed
yanmo42 wants to merge 1 commit into
openclaw:mainfrom
yanmo42:fix/control-ui-stuck-queue
Closed

yanmo42 wants to merge 1 commit into
openclaw:mainfrom
yanmo42:fix/control-ui-stuck-queue

Conversation

@yanmo42

@yanmo42 yanmo42 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #42213

What Problem This Solves

Fixes an issue where Control UI users who queued a follow-up during an active run could see it remain stuck indefinitely when the browser missed both the run's terminal event and the later session-state update.

Why This Change Was Made

Adds a bounded exact-run recovery watchdog owned by the durable chat outbox. It waits before probing the authoritative agent.wait state, keeps active or ambiguous runs queued, replaces stale watches across logical reconnects, and preserves canonical done, timeout, cancellation, and yielded session outcomes before reloading history and resuming FIFO delivery.

The live proof also exposed an alias boundary hidden by mocks: the durable main-session outbox is stored under global + agent, while a per-sender Gateway can keep its transcript at agent:<id>:main. Visible global outboxes now reconcile through the visible canonical Gateway route, preventing an already-delivered head from becoming unconfirmed and blocking later FIFO rows. Background outboxes retain their own routing.

The positive production delta (+207/-6 lines) is the watchdog capability, its isolated lifecycle owner, and the canonical visible-history reconciliation. The watchdog is scoped only to visible durable outboxes with blocked work and adds no protocol or configuration surface.

Carries forward the recovery direction from #42258 and #90618; contributor attribution is preserved in the commit trailer.

User Impact

Queued follow-ups recover automatically after missed terminal/session events instead of requiring another prompt or page intervention. Active runs remain protected from premature sends, reconnects preserve recovery, and main-session aliases no longer strand delivered queue heads.

Real Behavior Proof

Added a deterministic real-stack test at ui/src/e2e/chat-flow.real-gateway.e2e.test.ts. It uses:

  • production Control UI source in real Chromium via Playwright;
  • a real in-process Gateway over loopback WebSocket with token auth;
  • an isolated real OpenClaw config/session store;
  • a loopback OpenAI Responses SSE provider;
  • a transparent WebSocket fault proxy that intentionally drops the first run's terminal chat, session.message, and sessions.changed frames while preserving the connection sequence.

Observed after-fix trace (run IDs redacted):

DROP chat(final), session.message(idle), sessions.changed(idle)
REQ  agent.wait  { runId: <first-run-id>, timeoutMs: 50 }
RES  agent.wait  { status: "ok" }
REQ  chat.history { sessionKey: "agent:main:main", limit: 100 }
REQ  chat.history { sessionKey: "agent:main:main", limit: 1000 }
REQ  chat.send    { message: "REAL_GATEWAY_FIFO_FOLLOW_UP" }
UI   durable queue cleared; REAL_GATEWAY_SECOND_REPLY rendered

This first ran red against the prior patch: agent.wait and canonical history reload succeeded, but outbox reconciliation queried the persisted global alias, marked the delivered first row unconfirmed, and left the follow-up at sendAttempts: 0. The canonical visible-history fix makes the same real setup pass.

Exact-head CI passed checks-ui-e2e-real-gateway and uploaded control-ui-real-gateway-proof-1 for seven days. The 1.48 MB artifact contains the redacted JSON trace, before/after screenshots, and browser video.

Evidence

  • Real Control UI + Gateway proof: OPENCLAW_CAPTURE_UI_PROOF=1 OPENCLAW_UI_E2E_ARTIFACT_DIR=.artifacts/pr124054-real-proof node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.real-gateway.e2e.test.ts — 1 passed.
  • Complete real-Gateway browser lane: node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.real-gateway.e2e.test.ts ui/src/e2e/control-ui-auth-transports.e2e.test.ts — 3 passed.
  • Focused chat delivery suite: node scripts/run-vitest.mjs ui/src/pages/chat/chat-send.test.ts — 303 passed.
  • Workflow contract: node scripts/run-vitest.mjs test/scripts/ci-workflow-guards.test.ts -t 'gates current Control UI changes' — 1 passed.
  • Changed-file gate completed formatting, conflict/attribution/dependency guards, dead-code scans, i18n verification, and core-test/UI/root-test typechecks. Its delegated Crabbox startup was unavailable locally; the local fallback reached lint, the three reported proof-harness lint findings were fixed, and the final targeted core lint passed.
  • Earlier full Control UI unit suite: pnpm --dir ui test — 658 files passed, 9,464 tests passed, 1 skipped.
  • Earlier mocked browser follow-up suite — 13 passed.
  • Independent P1-depth OpenAI and Claude reviews: no remaining actionable findings before the real-stack addition.

@clawsweeper

clawsweeper Bot commented Aug 15, 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 the app: web-ui App: web-ui label Aug 15, 2026
@yanmo42
yanmo42 marked this pull request as ready for review August 15, 2026 06:22
@clawsweeper clawsweeper Bot added 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: 🦪 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 Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 12:52 PM ET / 16:52 UTC.

ClawSweeper review

What this changes

The PR adds a bounded Control UI outbox watchdog that queries an exact stalled run, reloads the visible transcript, and resumes FIFO follow-up delivery when terminal events were missed.

Regression provenance

Possible regression — suspected (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this PR open as the live fix path for the linked Control UI queue stall. No discrete correctness finding emerged; merge after the current-base result and remaining exact-head checks are green.

Priority: P1
Reviewed head: bf2f75fcc0e2262050a1c910ab2e46cd9f6268b2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A strong real-behavior proof and focused owner-boundary repair support a normal mergeable rating, subject to current-base CI completion.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR provides after-fix Chromium, real-Gateway, fault-injection evidence with an exact-run trace, visible recovered reply, and linked CI artifact.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR provides after-fix Chromium, real-Gateway, fault-injection evidence with an exact-run trace, visible recovered reply, and linked CI artifact.
Evidence reviewed 7 items Current-main gap: Current main has no outbox run-watch module, so the proposed watchdog behavior is not already implemented.
Recovery owner boundary: The PR fences recovery on the connected client, connection epoch, exact run, visible scope, and persisted outbox before reconciling lifecycle, reloading history, and draining.
Authoritative run contract: Gateway agent.wait returns pending for queued work and otherwise returns the retained terminal snapshot for the requested run; a no-snapshot short wait remains timeout/ambiguous.
Findings None None.
Security None None.

How this fits together

Control UI chat persists queued follow-ups in a durable browser outbox while the Gateway owns run state and transcript history. Normally terminal events release that queue; the new recovery path asks the Gateway for authoritative terminal state when those events never reach the browser.

flowchart LR
  User[Queued follow-up] --> Outbox[Durable chat outbox]
  Outbox --> Watchdog[Recovery watchdog]
  Watchdog --> Gateway[Gateway run status]
  Gateway --> Decision{Run terminal?}
  Decision -->|No| Watchdog
  Decision -->|Yes| History[Reload visible history]
  History --> Delivery[Resume FIFO delivery]
Loading

Before merge

  • Resolve merge risk (P1) - A mistaken terminal classification would clear local run state and release a FIFO follow-up while work is still active; this is why the exact agent.wait contract and the terminal-shape cases remain merge-critical.
  • Resolve merge risk (P1) - The bug fix adds production net +201 lines for a new timer and lifecycle bridge; the dedicated outbox owner is justified by its client/epoch/run fences, but it remains a larger-than-default repair surface.
  • Resolve merge risk (P1) - The branch is behind current main and several current checks remain in progress; validate the actual merge result rather than infer behavior from stale-base status.
  • Complete next step (P2) - No repair lane is needed because no discrete patch defect was found; the remaining action is normal current-base CI completion and maintainer merge review.
Agent review details

Security

None.

PR surface

Source +201, Tests +1004, Config +13. Total +1218 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 207 6 +201
Tests 5 1005 1 +1004
Docs 0 0 0 0
Config 1 14 1 +13
Generated 0 0 0 0
Other 0 0 0 0
Total 9 1226 8 +1218

Review metrics

Metric Value Why it matters
Production versus test delta production +207/-6 (net +201); tests/test support +1,005/-1; CI proof plumbing +14/-1 The production growth creates the fenced watchdog owner and canonical-history reconciliation; the much larger test addition covers failure ordering and real-browser behavior.

Merge-risk options

Maintainer options:

  1. Land after merge-result validation (recommended)
    Accept the bounded watchdog once the current-base merge result finishes green checks, preserving its exact-run and connection-epoch fences.

Technical review

Best possible solution:

Keep the durable-outbox-owned recovery flow, and merge it only after the merged result against current main passes its exact-head browser and required CI checks.

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

Yes—source-reproducible with high confidence: the added real-Gateway browser scenario drops terminal and idle session frames, then verifies the formerly stuck FIFO follow-up is sent only after authoritative recovery.

Is this the best way to solve the issue?

Yes. Recovery belongs to the durable outbox because it owns blocked FIFO work; an event-handler-only retry cannot run when the relevant events were missed, while changing Gateway protocol would be broader than needed.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: Missed terminal events can leave a normal Control UI follow-up silently blocked until the user intervenes.
  • merge-risk: 🚨 message-delivery: The watchdog decides when a durable FIFO row may be sent after an authoritative run-state query.
  • merge-risk: 🚨 session-state: The change projects Gateway terminal state into local run and session lifecycle state after event loss.
  • 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 (linked_artifact): The PR provides after-fix Chromium, real-Gateway, fault-injection evidence with an exact-run trace, visible recovered reply, and linked CI artifact.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix Chromium, real-Gateway, fault-injection evidence with an exact-run trace, visible recovered reply, and linked CI artifact.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Current lifecycle and durable-outbox code is attributed to this recent session/transcript repair. (role: recent chat/session contributor; confidence: high; commits: 30216f52fabe; files: ui/src/pages/chat/chat-outbox-drain.ts, ui/src/pages/chat/run-lifecycle.ts)
  • Peter Steinberger: Feature history records substantial contribution across the reviewed chat lifecycle and outbox surfaces, including the PR head's immediate mainline parent. (role: long-running chat lifecycle contributor; confidence: medium; commits: f24bd8a2a299; files: ui/src/pages/chat/chat-outbox-drain.ts, ui/src/pages/chat/chat-send-delivery.ts, ui/src/pages/chat/run-lifecycle.ts)

Rank-up moves

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

  • Let the current merge-result checks finish green before landing.

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 (3 earlier review cycles)
  • reviewed 2026-08-15T06:28:44.409Z sha c293dfa9bb733c14560638e93222a0d41f91c449 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-15T06:39:02.685Z sha 2a59d7463e82a55c100c8c46d0bd8bb2a7b83c0b :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-15T16:37:49.671Z sha df387dbf1bc9561d0b7bb16d30abf0d29d6b98dd :: needs maintainer review before merge. :: none

@yanmo42
yanmo42 force-pushed the fix/control-ui-stuck-queue branch 2 times, most recently from 2a59d74 to dc757aa Compare August 15, 2026 16:29
@yanmo42
yanmo42 force-pushed the fix/control-ui-stuck-queue branch from dc757aa to df387db Compare August 15, 2026 16:30
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 15, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 P2 Normal backlog priority with limited blast radius. 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 Aug 15, 2026
@yanmo42
yanmo42 force-pushed the fix/control-ui-stuck-queue branch from df387db to bf2f75f Compare August 15, 2026 16:39
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 15, 2026
@clawsweeper clawsweeper Bot added 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: 🐚 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. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix: queued chat follow-ups stay stuck after missed terminal events This is item 1/1 in the current shard. Shard 31/41.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@clawsweeper

Copy link
Copy Markdown
Contributor

Superseded by #126180.

The replacement preserves Ian Moog's commit authorship while narrowing recovery to one canonical lifecycle fact: the exact last terminal run ID is recorded by the Gateway and consumed by the Control UI to release only the matching settled run. This removes the browser-watchdog/fallback path and keeps queued-send recovery at the owning state boundary.

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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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 can stay stuck busy and stop flushing queued messages after a long run

2 participants