Skip to content

fix(gateway): deliver queued WebChat replies after source completion - #116649

Merged
steipete merged 1 commit into
mainfrom
codex/openclaw-agent-delivery-20260730
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/openclaw-agent-delivery-20260730

Conversation

@steipete

@steipete steipete commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A WebChat answer queued behind an active turn could finish after its initiating chat request already terminalized. The reply then disappeared silently or reused a later same-session dispatcher, risking delivery under the wrong source.

Fix

Bind every queued reply batch to its originating Gateway admission and authoritative channel. Preserve ownership through queue collection, finalize through the existing WebChat transcript/broadcast owner, and settle delivery or record an explicit drop for unavailable, mismatched, duplicate, or failed work. Preserve queue-cap logging and cancellation ownership.

Storage boundary

No SQLite schema, migration, persistent-store design, or persistence-semantics changes; this reuses the current canonical transcript finalizer.

Proof

The absent queued-followup callback first failed on unmodified main. A real isolated Gateway with an authenticated Control UI WebSocket performed a real chat request, observed its original final, and then received the delayed answer as a second WebSocket final under its own run ID. All 247 Gateway, queue, followup, and lifecycle tests pass across five files; focused lint, formatting, and independent review are clean.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 31, 2026
@steipete
steipete marked this pull request as ready for review July 31, 2026 03:30
@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. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 25, 2026, 8:09 PM ET / August 26, 2026, 00:09 UTC.

ClawSweeper review

What this changes

The PR binds queued WebChat reply batches to their originating Gateway admission so a late queue drain is finalized to the original WebSocket client or explicitly dropped.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Needs changes before merge: the source-bound dispatcher is still lost by overflow retry cloning, and collect mode can collapse distinct Gateway admissions into the last admission’s dispatcher.

Priority: P1
Reviewed head: 724d25721c4fc0c644ab132ed0e6c0eb36bede8c

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The single-source Gateway proof is useful, but two P1 queue-owner gaps make the patch not ready to merge.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nonetheless describes an isolated authenticated Gateway WebSocket run, while the remaining blockers need new queue-path regressions.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nonetheless describes an isolated authenticated Gateway WebSocket run, while the remaining blockers need new queue-path regressions.
Evidence reviewed 5 items Overflow clone drops the new delivery owner: The retry-source reconstruction copies routing and lifecycle fields but omits the queued reply disposition; a later overflow retry therefore has no source dispatcher to invoke.
Collect batching retains only the last source disposition: The delivery-context key does not distinguish source-bound reply dispositions, while collected runtime metadata selects the final item’s disposition; same-device WebChat admissions can therefore be merged and finalized under the wrong source.
Boundary test proves only one captured callback: The added Gateway WebSocket test captures one queued callback and invokes it directly; it does not exercise overflow reconstruction or two same-owner queued admissions.
Findings 2 actionable findings [P1] Preserve the disposition in overflow retry sources
[P1] Do not collect distinct source-bound WebChat admissions
Security None None.

Live Verification

Command: pnpm test src/gateway/server.chat.gateway-server-chat.test.ts

Result: FAIL (failed) — step 1 run pnpm test src/gateway/server.chat.gateway-server-chat.test.ts: previous terminal command was still running after 30 seconds: "pnpm test src/gateway/server.chat.gateway-server-chat.test.ts"

$ node --import tsx scripts/test-projects.mts src/gateway/server.chat.gateway-server-chat.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-116649-sHOClh/target

Assertions:

  • FAIL expect_output: delivers a queued WebChat reply over the live Gateway WebSocket after its source ends

How this fits together

A WebChat request enters the Gateway and may be deferred into the follow-up queue while another turn runs. When the queued work completes, the queue must deliver its result through the original Gateway admission rather than a later session dispatcher.

flowchart TD
  A[WebChat request] --> B[Gateway admission]
  B --> C[Follow-up queue]
  C --> D[Source-bound delivery decision]
  D --> E[Transcript and WebSocket final]
  C --> F[Explicit dropped outcome]
Loading

Before merge

  • Preserve the disposition in overflow retry sources (P1) - createOverflowSummaryRetrySource rebuilds a queued item without queuedFollowupReplyDisposition. When a WebChat source is summarized and retried after overflow, the synthetic run has no source finalizer and falls back to the mutable dispatcher; copy the disposition and add a forced-overflow regression.
  • Do not collect distinct source-bound WebChat admissions (P1) - The collect key omits the source disposition, then collectRuntimeMetadata keeps only the last item’s callback. Two queued WebChat requests from the same device can collect into one run and route the aggregate final to the last source; partition by a stable admission key or process these sources individually.
  • Resolve merge risk (P1) - An overflowed WebChat turn loses its source-owned finalizer and can fall back to the mutable dispatcher that this PR is meant to avoid.
  • Resolve merge risk (P1) - Two collectable WebChat admissions from the same device can share one aggregate and send its final through only the last admission’s dispatcher.

Findings

  • [P1] Preserve the disposition in overflow retry sources — src/auto-reply/reply/queue/drain.ts:1012-1041
  • [P1] Do not collect distinct source-bound WebChat admissions — src/auto-reply/reply/queue/drain.ts:230-289
Agent review details

Security

None.

PR surface

Source +190, Tests +208. Total +398 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 9 231 41 +190
Tests 4 208 0 +208
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 439 41 +398

Review metrics

Metric Value Why it matters
Production versus test LOC production +231/-41 (net +190); tests +208/-0 The source-owned delivery boundary is substantial bug-fix growth, so its overflow and aggregation invariants need direct regression coverage before merge.

Merge-risk options

Maintainer options:

  1. Preserve each queued source binding (recommended)
    Copy the disposition through overflow retry construction and prevent collect mode from combining distinct Gateway admissions, with focused regressions for both paths.
  2. Pause the delivery change
    Do not merge until the finalizer’s ownership remains exact across overflow and aggregation paths.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve queued reply dispositions through overflow retry clones and partition collect batches by source admission; add focused overflow and same-owner collect regressions.

Technical review

Best possible solution:

Carry the source delivery binding through every queue clone and partition collect batches by a stable source-admission key unless one aggregate final is explicitly owned by all sources.

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

Yes, source inspection gives a high-confidence path: force queue overflow after a WebChat admission, or enqueue two same-device WebChat turns in collect mode, then observe the omitted or last-only disposition.

Is this the best way to solve the issue?

No. The single-source callback is the right owner boundary, but the implementation does not preserve that boundary through all queue transformations.

Full review comments:

  • [P1] Preserve the disposition in overflow retry sources — src/auto-reply/reply/queue/drain.ts:1012-1041
    createOverflowSummaryRetrySource rebuilds a queued item without queuedFollowupReplyDisposition. When a WebChat source is summarized and retried after overflow, the synthetic run has no source finalizer and falls back to the mutable dispatcher; copy the disposition and add a forced-overflow regression.
    Confidence: 0.99
  • [P1] Do not collect distinct source-bound WebChat admissions — src/auto-reply/reply/queue/drain.ts:230-289
    The collect key omits the source disposition, then collectRuntimeMetadata keeps only the last item’s callback. Two queued WebChat requests from the same device can collect into one run and route the aggregate final to the last source; partition by a stable admission key or process these sources individually.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The patch can still silently lose or mis-associate queued WebChat replies on active queue paths.
  • merge-risk: 🚨 message-delivery: The unresolved clone and collect paths can send a queued reply through the wrong dispatcher or no source dispatcher.
  • merge-risk: 🚨 session-state: Collect mode can associate an aggregate queued result with the last admission rather than the admission that owns it.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nonetheless describes an isolated authenticated Gateway WebSocket run, while the remaining blockers need new queue-path regressions.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/auto-reply/reply/queue.media-carrier.test.ts.
  • [P1] pnpm test src/auto-reply/reply/queue.collect.test.ts.
  • [P1] pnpm test src/gateway/server.chat.gateway-server-chat.test.ts.

What I checked:

  • Overflow clone drops the new delivery owner: The retry-source reconstruction copies routing and lifecycle fields but omits the queued reply disposition; a later overflow retry therefore has no source dispatcher to invoke. (src/auto-reply/reply/queue/drain.ts:1012, 724d25721c4f)
  • Collect batching retains only the last source disposition: The delivery-context key does not distinguish source-bound reply dispositions, while collected runtime metadata selects the final item’s disposition; same-device WebChat admissions can therefore be merged and finalized under the wrong source. (src/auto-reply/reply/queue/drain.ts:230, 724d25721c4f)
  • Boundary test proves only one captured callback: The added Gateway WebSocket test captures one queued callback and invokes it directly; it does not exercise overflow reconstruction or two same-owner queued admissions. (src/gateway/server.chat.gateway-server-chat.test.ts:334, 724d25721c4f)
  • Current main has not implemented this source-binding path: Current main contains neither the queued batch callback nor its disposition carrier in the entry and delivery paths, so the PR remains necessary. (src/auto-reply/reply/get-reply-run-execute.ts, c28d11f78014)
  • Feature-history provenance: Blame attributes the current queue delivery-context key to Peter Steinberger’s current-main commit, making that area the clearest routing point for the follow-up. (src/auto-reply/reply/queue/drain.ts:230, aa16e628a135)

Likely related people:

  • steipete: Current-main blame assigns the delivery-context key to Peter Steinberger, and the same area determines whether queued admissions may collect together. (role: recent queue-delivery contributor; confidence: high; commits: aa16e628a135; files: src/auto-reply/reply/queue/drain.ts, src/gateway/server-methods/chat-send-turn-adoption.ts)

Rank-up moves

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

  • Copy the source disposition through overflow retry reconstruction and prove it with a forced-overflow regression.
  • Separate collect batches by exact source admission, or deliberately define and prove an aggregate owner for every source.

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 (23 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-10T19:00:33.525Z sha cefbde2407262f4558e86142c7fdfef6fde77177 :: needs changes before merge. :: [P1] Carry the source disposition through overflow summaries
  • reviewed 2026-08-10T19:54:20.396Z sha 01a4e924b0be10f9a07916a685ba1b6ed9b5be9d :: needs changes before merge. :: [P1] Carry the disposition through overflow summaries
  • reviewed 2026-08-10T20:54:40.688Z sha 22788e3 :: found issues before merge. :: [P1] Preserve the disposition in overflow summaries
  • reviewed 2026-08-14T14:36:51.305Z sha 22788e3 :: found issues before merge. :: [P1] Carry the source disposition through overflow summaries
  • reviewed 2026-08-16T22:24:46.972Z sha 22788e3 :: found issues before merge. :: [P1] Preserve the disposition in overflow retries
  • reviewed August 18, 2026, 11:44 PM ET / August 19, 2026, 03:44 UTC sha unknown :: needs changes before merge. :: [P1] Preserve the disposition in overflow summaries
  • reviewed 2026-08-19T04:07:25.167Z sha 22788e3 :: found issues before merge. :: [P1] Preserve the disposition in overflow summaries
  • reviewed 2026-08-25T04:44:52.885Z sha 22788e3 :: found issues before merge. :: [P1] Preserve late-reply disposition through overflow summaries

@clawsweeper clawsweeper Bot added 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: 🦐 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: 🧂 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. 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. labels Aug 5, 2026
@steipete steipete self-assigned this Aug 9, 2026
@steipete
steipete force-pushed the codex/openclaw-agent-delivery-20260730 branch from f49969a to 0a73fdf Compare August 9, 2026 11:11
@openclaw-barnacle openclaw-barnacle Bot added size: S gateway Gateway runtime size: L and removed gateway Gateway runtime size: M size: S labels Aug 9, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. label Aug 10, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 10, 2026
@steipete
steipete force-pushed the codex/openclaw-agent-delivery-20260730 branch 4 times, most recently from 6e1766b to 22788e3 Compare August 10, 2026 20:47
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 19, 2026
@steipete
steipete force-pushed the codex/openclaw-agent-delivery-20260730 branch from 22788e3 to 724d257 Compare August 26, 2026 00:03
@steipete steipete changed the title fix(gateway): record late WebChat reply disposition fix(gateway): deliver queued WebChat replies after source completion Aug 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification on exact head 724d257: A WebChat reply produced after its original request completed lost its delivery and persistence owner. Preserve canonical delivery ownership until the asynchronous reply settles without duplicating persistence. Delayed assistant replies reach the authenticated WebSocket client and appear exactly once in durable chat history. 247 focused tests and an authenticated real Gateway/WebSocket conversation plus actual SQLite chat.history prove exactly one assistant row; exact CI and fresh full-branch P1 review pass. A reviewer suspected duplicate persistence; the real authenticated Gateway conversation and direct SQLite-backed chat.history conclusively disproved it. No SQLite schema changes.

@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

gateway Gateway runtime maintainer Maintainer-authored PR 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

1 participant