Skip to content

fix(gateway): a queued message's run id finishes immediately and its reply arrives under another id - #165996

Merged
steipete merged 3 commits into
mainfrom
codex/stab-steer-identity
Oct 6, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/stab-steer-identity

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer decision (2026-10-05): approved. The run id returned for an input that is queued (a steer that falls back to the follow-up queue, or an explicit followup / collect send) stays that input's identity. It gets no terminal while queued, and terminates with the outcome of the execution that consumes it. Drops (queue cap) and cancellation before consumption terminate it immediately. No protocol or schema change.

What Problem This Solves

Fixes: when a message is queued behind a running turn, the run id returned by chat.send got an empty final right 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 final carries 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 final for the client run, and wrote an ok dedupe entry that agent.wait treated 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 accepted entry. 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):

Scenario main f986a7aaf15b this branch
followup, built-in runtime returned id final (empty) 0.1 s after queueing; reply published under another id at 33.8 s no early terminal; returned id final with the reply at 38.5 s; agent.wait resolves then
followup, Codex runtime - returned id final with the reply at 31.4 s
collect, two inputs both ids final (empty) at ~5 s; merged reply under another id at 29.6 s both ids terminal at 28.5 s when the merged turn finishes; reply published once (under the last input)
agent.wait after completion ok ok, stopReason: "stop" (the execution's outcome)

Tests (TMPDIR=/private/tmp/oc-steer-identity pnpm test <file> --maxWorkers=1):

chat-send-queued-identity.test.ts           11 passed  42.67 s
chat-send-prestart-steer.test.ts             3 passed  76.14 s
server.chat-queued-followup.test.ts          6 passed  55.87 s
chat-send-dispatch-errors.test.ts           20 passed  22.45 s
chat-send-late-followup.test.ts              6 passed   2.70 s
queue.collect.test.ts                       39 passed  10.31 s
progress-card-refresh.queued.test.ts         7 passed  10.69 s
chat-send-pending-input-withdrawal.test.ts  14 passed  42.60 s
production restored to main: 9 failures (both fallback cases emit the returned id's terminal before consumption; the accepted-steer control passes); collect outcome cases fail 3/3

Follow-up commit after exact-head CI (run 37431717307 hung its shard): server.chat.gateway-server-chat-b.test.ts still 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 in server.chat-abort-settlement.test.ts also exposed a real regression: cancelling a queued input published a generic aborted stop reason before the active owner's rpc outcome. 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.

72 files (every server.chat*, chat-send-*, queued-followup, queue*, and abort/settlement suite): 884 passed, 0 failed, 0 skipped (25 min 2 s)

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.md and 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 required chatAbortControllers map, 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 reviewed 05e3ad7e9306da7f2138d300e8413803f1fe7a75 with no findings. Revision 3 completed final head 403d2c9bdc43c2963f91bc2a4b357f126929b1fd with no findings or before-merge items. Exact-head CI run 37445003459 passed (45 successful jobs, 24 skipped).

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.
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL labels Oct 6, 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. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 5:50 AM ET / 09:50 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: 403d2c9bdc43c2963f91bc2a4b357f126929b1fd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused lifecycle repair with direct runtime evidence, meaningful regression coverage, and no blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded dev-Gateway before/after output exercises real queued followup and collect execution through the changed Gateway owners: original input IDs remain pending until execution finishes, receive the resulting terminal, and publish collected content once. The latest head changes only the abort-registry fixture, so this proof remains applicable. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded dev-Gateway before/after output exercises real queued followup and collect execution through the changed Gateway owners: original input IDs remain pending until execution finishes, receive the resulting terminal, and publish collected content once. The latest head changes only the abort-registry fixture, so this proof remains applicable. No stored-data contract changes.
Evidence reviewed 9 items Pinned introduction and review continuity: The introduced delta was reviewed from merge-base 2983dfc to the exact head. Since the previous completed review at 05e3ad7, the only change supplies chatAbortControllers in the queued-refresh fixture; production code and assertions are unchanged. Previous findings were empty.
Current main still needs the fix: Fetched main still broadcasts an empty final for successful queue admission and records the source dispatch's admission outcome rather than the consuming execution's outcome. The PR remains open and unmerged; the latest published release is v2026.9.8. No implemented-on-main closure is supported.
Queued identity and cancellation ownership: The adoption owner records accepted admission, binds consuming execution to the original client identity, and records one terminal outcome. Pre-adoption cancellation and overflow settle immediately; adopted cancellation waits for execution settlement. Exact-controller checks protect successor queue entries.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +121, Tests +395, Docs +19. Total +535 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 8 217 96 +121
Tests 10 828 433 +395
Docs 2 20 1 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 1065 530 +535

Review metrics

Metric Value Why it matters
Production versus test growth Net production +121 lines; tests and test support +395 lines The production growth has a stated lifecycle justification: per-input outcomes, collect fan-out, and cancellation ordering.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Premature queued-run completion breaks reply tracking and waiting in an existing agent workflow.
  • 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 (live_output): Recorded dev-Gateway before/after output exercises real queued followup and collect execution through the changed Gateway owners: original input IDs remain pending until execution finishes, receive the resulting terminal, and publish collected content once. The latest head changes only the abort-registry fixture, so this proof remains applicable. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded dev-Gateway before/after output exercises real queued followup and collect execution through the changed Gateway owners: original input IDs remain pending until execution finishes, receive the resulting terminal, and publish collected content once. The latest head changes only the abort-registry fixture, so this proof remains applicable. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction and review continuity: The introduced delta was reviewed from merge-base 2983dfc to the exact head. Since the previous completed review at 05e3ad7, the only change supplies chatAbortControllers in the queued-refresh fixture; production code and assertions are unchanged. Previous findings were empty. (src/gateway/server-methods/progress-card-refresh.queued.test.ts:113, 403d2c9bdc43)
  • Current main still needs the fix: Fetched main still broadcasts an empty final for successful queue admission and records the source dispatch's admission outcome rather than the consuming execution's outcome. The PR remains open and unmerged; the latest published release is v2026.9.8. No implemented-on-main closure is supported. (src/gateway/server-methods/chat-send-agent-dispatch.ts:687, a51a76bda63c)
  • Queued identity and cancellation ownership: The adoption owner records accepted admission, binds consuming execution to the original client identity, and records one terminal outcome. Pre-adoption cancellation and overflow settle immediately; adopted cancellation waits for execution settlement. Exact-controller checks protect successor queue entries. (src/gateway/server-methods/chat-send-turn-adoption.ts:68, 403d2c9bdc43)
  • Collected outcomes and preserved boundaries: Collected delivery sends progress and content to the last source while sending payload-free terminal outcomes to earlier sources, and waits for all recipients before surfacing delivery failure. Existing authorization grouping, operator authority, routing metadata, and lifecycle admission remain unchanged; no stored-data schema or plugin API changes are introduced. (src/auto-reply/reply/queue/delivery-context.ts:340, 403d2c9bdc43)
  • Recorded real behavior proof: The captured PR body records dev-Gateway runs using real OpenAI-backed agents: built-in followup changes from an empty terminal at 0.1 seconds and a reply under another ID to no early terminal and the original ID's reply at 38.5 seconds; collect completes both input IDs at 28.5 seconds and publishes content once. This directly exercises Gateway admission, queued execution, client events, and agent.wait. The additional Codex-runtime sample is supplemental; the changed ownership contract is implemented in OpenClaw's Gateway and queue owners. The latest head changes only a test fixture. (403d2c9bdc43)
  • Validation and accepted behavior: The captured body records approved queued-input identity semantics, 884 passing tests across 72 relevant suites, production-revert failures for identity and collect outcomes, and abort-regression failures when the cancellation fix is reverted. It also records the latest fixture's three failures before correction and seven passes afterward. These are contributor-reported validation results; this read-only review did not execute tests or another reviewer. (src/gateway/server.chat-abort-settlement.test.ts:92, 403d2c9bdc43)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-10-06T07:50:50.713Z sha 32925ec :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T09:39:09.696Z sha 05e3ad7 :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) October 6, 2026 07:59
@steipete
steipete disabled auto-merge October 6, 2026 08:49
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.
@steipete
steipete merged commit 602c0e8 into main Oct 6, 2026
134 of 136 checks passed
@steipete
steipete deleted the codex/stab-steer-identity branch October 6, 2026 10:01
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime 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. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant