Repository navigation
fix(subagents): reconcile transport-ambiguous dispatch instead of misreporting an accepted run - #130586
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 27, 2026, 9:04 AM ET / 13:04 UTC. ClawSweeper reviewWhat this changesThe branch retries an out-of-process subagent agent-dispatch once after a transport-ambiguous failure, reusing the existing idempotency key for native and ACP spawning. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked until stronger real behavior proof is added - 7 items remain The PR addresses a real P1 subagent-dispatch problem, but the current head still turns a provisional Gateway reservation into an accepted child run and can double an unreachable-Gateway timeout. The latest comment describes a pending-state/polling repair that is not present in the reviewed head. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — step 1 Assertions:
How this fits togetherSubagent spawning asks Gateway to admit an agent run, then records that child as active for the parent. Gateway’s idempotency cache temporarily reserves a run before asynchronous admission has settled, so callers must distinguish a settled accepted run from a pending reservation. flowchart LR
Parent[Parent agent] --> Spawn[Subagent spawn]
Spawn --> Dispatch[Gateway agent dispatch]
Dispatch --> Reservation[Provisional idempotency reservation]
Reservation --> Admission[Admission settles]
Admission --> Result[Accepted child or error]
Result --> Registry[Parent child-run registry]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +24, Tests +77. Total +101 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Expose provisional cached admission as pending at the Gateway boundary, then reconcile only until a short bounded deadline for a settled final result before registering the child. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: a transport timeout followed by an immediate same-key replay reaches the accepted-shaped provisional reservation before asynchronous admission has settled. Is this the best way to solve the issue? No—the immediate replay is not sufficient because it conflates a reservation with final acceptance; Gateway must retain that distinction and the spawn side must use a short bounded reconciliation window. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9bd50c803cce. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
761ecd7 to
56c3c86
Compare
|
Addressed the P1 finding and unified the fix across both runtimes. The reconcile moved from the native-only path to the shared subagent gateway seam ( Added a regression test driving the @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
56c3c86 to
d86c41a
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
d86c41a to
d04fc54
Compare
|
Fixed the P1: a same-key replay no longer certifies an unadmitted provisional reservation as an accepted child run. Root cause (the #130164 ACP sibling P1 extension). On a transport-ambiguous dispatch the reconciler re-dispatches the same idempotency key. But the Gateway writes a provisional Discriminator. A provisional reservation payload has Changes.
Coverage. Gateway regression asserts a provisional replay is tagged @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
d04fc54 to
a964513
Compare
a964513 to
b12d576
Compare
…dy-accepted run A subagent dispatch over the gateway (native or ACP) that times out or closes before the ack is received does not prove the run never landed: the gateway can accept and start the agent run before the caller sees the ack. A same-key replay returns that already-accepted run instead of starting a duplicate. The shared out-of-process dispatch seam in subagent-spawn-gateway.ts therefore reconciles an agent-method dispatch on a transport-unavailable error: it replays the identical idempotency key once and surfaces the recovered accepted run rather than misreporting a dispatch error. Reconciliation is scoped to agent dispatches only (native and ACP share this seam); cleanup and other non-agent methods retry nothing. Regression tests cover the native (subagent-spawn.test.ts) and ACP (acp-spawn.test.ts) flows: first dispatch timeout, replay returns the accepted run, and the caller surfaces it instead of concluding the child never started.
b12d576 to
8cab6fb
Compare
8cab6fb to
64be0ae
Compare
64be0ae to
1e9ed74
Compare
|
Thanks @ZengWen-DT! Proof: On an isolated real Gateway, I dropped the first accepted WebSocket acknowledgement. The parent replayed the same idempotency key, recovered the same run, returned
Example
|
A lost Gateway acknowledgement could hide a subagent run that was already accepted. Reuse the existing idempotency key, wait only while admission is explicitly provisional, and reject terminal replay results before child registration. Co-authored-by: ZengWen-DT <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #130164
What Problem This Solves
A
sessions_spawncall can lose its Gateway acknowledgement after the Gateway has already accepted the child run. The parent then reportsstatus: "error"even though the child exists and is running.The same-key replay also has a provisional state. Before admission settles, the Gateway reserves the run ID. That reservation must not be registered as an active child until it becomes a settled acceptance.
Why This Change Was Made
The child launch already carries one stable idempotency key. The Gateway dedupe record is the authoritative owner for that key.
The shared out-of-process spawn seam now reconciles only transport-ambiguous
agentdispatches. Native and ACP spawns use this same path.acceptedorin_flightreplay returns the existing run.The Gateway now exposes only
admissionPending: truefor provisional replay. It does not expose the internal reservation ID.User Impact
timeoutor another terminal result is not registered as active.Evidence
Red — exact current main
8e4075371039: An isolated real Gateway accepted and recorded one WebSocketagentdispatch. A frame proxy dropped only the accepted acknowledgement. The parent returnedstatus: "error", while a same-key replay returned the same authoritative run ID. The parent registry was empty.Green — production-identical head
64be0ae2137f: The same isolated Gateway scenario sent twoagentframes with one idempotency key. The parent returnedstatus: "accepted". Gateway replay returned the same run ID asin_flight. The parent registry contained exactly one running child, and the controlled provider completed exactly one child turn. Final head1e9ed747a902changes only the matching Gateway test assertion.Terminal control — production-identical head
64be0ae2137f: A real Gateway replay first returnedadmissionPending: true. A real abort then settled that same run totimeout. The parent returned a visible retry error and registered no child. Final head1e9ed747a902changes only the matching Gateway test assertion.Sanitized current-head Gateway trace
{ "accepted_replay": { "request_1": { "method": "agent", "idempotencyKey": "same-key" }, "response_1": { "status": "accepted", "runId": "run-a", "action": "dropped" }, "request_2": { "method": "agent", "idempotencyKey": "same-key" }, "response_2": { "status": "in_flight", "runId": "run-a" }, "parent": { "status": "accepted", "runId": "run-a" }, "registry": [{ "runId": "run-a", "status": "running" }], "providerRequests": 1 }, "provisional_to_terminal": { "request_1": { "method": "agent", "idempotencyKey": "same-key" }, "transport": "response dropped", "request_2": { "method": "agent", "idempotencyKey": "same-key" }, "response_2": { "status": "in_flight", "runId": "run-b", "admissionPending": true }, "control": { "method": "chat.abort", "aborted": true, "runId": "run-b" }, "request_3": { "method": "agent", "idempotencyKey": "same-key" }, "response_3": { "status": "timeout", "runId": "run-b" }, "parent": { "status": "error", "retryVisible": true }, "registry": [] } }Telegram was not used as the proof surface. Telegram tool calls have an in-process Gateway context, while this defect exists only on the out-of-process WebSocket dispatch path.
Regression support: