Repository navigation
fix(gateway): a queued message's run id finishes immediately and its reply arrives under another id - #165996
Conversation
Keep queue admission nonterminal in chat events and run waits. Associate the consuming followup with its original client run, fan out collected outcomes without repeating reply content, and settle rejected or canceled pending inputs through queue custody.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 5:50 AM ET / 09:50 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR keeps queued chat inputs pending under their original run IDs, delivers collected execution outcomes to every input, and preserves cancellation outcomes. Merge readiness✅ Ready for maintainer review The PR remains necessary: current main still completes queued inputs prematurely. No actionable introduced defect was found, and the latest fixture correction preserves the previously reviewed production behavior and valid runtime proof. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway accepts chat inputs and queues them behind active agent turns. Its queued-turn lifecycle connects later execution results to the run IDs observed by clients for replies, waiting, and cancellation. flowchart TD
A[Chat input and run ID] --> B[Gateway admission]
B --> C[Follow-up or collect queue]
C --> D[Consuming agent execution]
D --> E[Reply and outcome settlement]
E --> F[Original client run IDs]
C --> G[Cancellation or overflow]
G --> F
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +121, Tests +395, Docs +19. Total +535 across 20 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep queued-input identity and terminal settlement in the existing adoption owner, with collected content published once and every consumed input receiving its execution outcome. Do we have a high-confidence way to reproduce the issue? Yes: queue a chat.send follow-up behind an active turn and observe the returned run ID's premature empty final on current main. Source confirms that path, and the captured body supplies before/after live observations; this reviewer did not execute it. Is this the best way to solve the issue? Yes: repairing the existing queued lifecycle and collect delivery owner is a focused solution that preserves accepted steering, routing, and protocol contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a51a76bda63c. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Keep the acknowledged active abort reason when queued custody terminates an input before detached dispatch settles. Reuse that projection for queued settlement so agent.wait retains the same cancellation outcome. Replace obsolete queue-time terminal expectations with pending, consuming-run completion, drop, replay, and exactly-once abort coverage. Release held dispatch and queue custody from cleanup so a failed assertion cannot strand the shared Gateway chat fixture and cascade into history test timeouts. Validated with the complete abort settlement and chat-b suites, scoped types, lint, formatting, and independent full-branch review. A production-only revert reproduces both queued abort reason regressions. Remaining sibling suites are running separately; no publication is performed by this commit.
The queued refresh fixture omitted the required chatAbortControllers map. Cancellation then threw before releasing retained admission. Reproduce the three CI failures and retain all seven existing assertions; the completed fixture passes them without a production change.
|
Merged via squash.
|
…reply arrives under another id (openclaw#165996) * fix(gateway): retain queued steer input run identities Keep queue admission nonterminal in chat events and run waits. Associate the consuming followup with its original client run, fan out collected outcomes without repeating reply content, and settle rejected or canceled pending inputs through queue custody. * fix(gateway): preserve queued abort outcomes during dispatch settlement Keep the acknowledged active abort reason when queued custody terminates an input before detached dispatch settles. Reuse that projection for queued settlement so agent.wait retains the same cancellation outcome. Replace obsolete queue-time terminal expectations with pending, consuming-run completion, drop, replay, and exactly-once abort coverage. Release held dispatch and queue custody from cleanup so a failed assertion cannot strand the shared Gateway chat fixture and cascade into history test timeouts. Validated with the complete abort settlement and chat-b suites, scoped types, lint, formatting, and independent full-branch review. A production-only revert reproduces both queued abort reason regressions. Remaining sibling suites are running separately; no publication is performed by this commit. * test(gateway): supply queued refresh abort registry The queued refresh fixture omitted the required chatAbortControllers map. Cancellation then threw before releasing retained admission. Reproduce the three CI failures and retain all seven existing assertions; the completed fixture passes them without a production change.
What Problem This Solves
Fixes: when a message is queued behind a running turn, the run id returned by
chat.sendgot an emptyfinalright away. The queued message later ran and published its reply under a different run id. Clients waiting on the returned id (agent.wait, the SDK, the Control UI) saw "done" before the message had even started, and never saw its reply under that id.User Impact
User impact: a queued follow-up or collected message now finishes under the run id the client received. Its
finalcarries the actual reply, or an error or abort if that is the outcome. In collect mode, every merged input finishes when the merged turn finishes, and the reply is published once. Cancelling a queued input before it runs still withdraws only that input. Accepted steering (injected into the running turn) is unchanged.Why This Change Was Made
At follow-up admission, chat-send dispatch (and its dispatch-error sibling) deliberately broadcast
finalfor the client run, and wrote anokdedupe entry thatagent.waittreated as terminal. The follow-up execution then ran under a fresh id, and collect kept only its last source callback.The turn-adoption lifecycle now owns the queued input's identity. Queueing writes a non-terminal
acceptedentry. When the consuming execution starts, its runtime run id is mapped onto the client id through the existing chat-run mapping. The late-reply finalizer publishes under the client id, and the queued terminal is recorded from the execution's completion. Collect fans the completion out to every consumed input, while the content owner publishes once. Queue-cap drops and pre-consumption cancellation record their own terminal; cancellation after consumption waits for execution settlement.Evidence
Live (dev Gateway, OpenAI-backed agents; a two-tool-call turn is running when the input is queued):
f986a7aaf15bfollowup, built-in runtimefinal(empty) 0.1 s after queueing; reply published under another id at 33.8 sfinalwith the reply at 38.5 s;agent.waitresolves thenfollowup, Codex runtimefinalwith the reply at 31.4 scollect, two inputsfinal(empty) at ~5 s; merged reply under another id at 29.6 sagent.waitafter completionokok,stopReason: "stop"(the execution's outcome)Tests (
TMPDIR=/private/tmp/oc-steer-identity pnpm test <file> --maxWorkers=1):Follow-up commit after exact-head CI (run 37431717307 hung its shard):
server.chat.gateway-server-chat-b.test.tsstill asserted the replaced queue-time terminal ("chat.send terminalizes the client run when a followup is queued"). It now verifies pending admission, completion under the original run id, drops, replay, and guaranteed cleanup; the old assertion stranded retained session work and caused the ten follow-on chat/history timeouts. The stronger abort coverage inserver.chat-abort-settlement.test.tsalso exposed a real regression: cancelling a queued input published a genericabortedstop reason before the active owner'srpcoutcome. The owner-held reason is now preserved, and tests verify withdrawal, exactly one aborted event, and stable results through later dispatch settlement. Reverting only that production fix reproduces both queued-abort failures.Core types, scoped lint, format,
git diff --check, and the import-cycle check pass. Autoreview of the branch (both commits) was scoped-clean through P2.docs/concepts/queue-steering.mdand the client run-id docs are updated.Production +238/-97, tests +815/-432, docs +11/-1. The growth is per-input terminal ownership, collect fan-out, and cancellation/publication ordering.
L9b exact-head CI found an incomplete test fixture in
progress-card-refresh.queued.test.ts(CI run 37443795891, job 112204139371): its cast Gateway context omitted the requiredchatAbortControllersmap, so the three cancellation cases threw before checking admission release. The fixture now supplies the map used by real Gateway contexts; production code and assertions are unchanged. Local reproduction: 3 failed / 4 passed before; 7 passed afterward (13.49 s Vitest, 18.72 s wrapper). Scoped lint, formatting, and diff whitespace checks pass. Independent autoreview of the complete production candidate and the subsequent one-line fixture correction found no actionable issues through P2. ClawSweeper revision 2 reviewed05e3ad7e9306da7f2138d300e8413803f1fe7a75with no findings. Revision 3 completed final head403d2c9bdc43c2963f91bc2a4b357f126929b1fdwith no findings or before-merge items. Exact-head CI run 37445003459 passed (45 successful jobs, 24 skipped).