Skip to content

fix(subagents): reconcile transport-ambiguous dispatch instead of misreporting an accepted run - #130586

Merged
obviyus merged 2 commits into
openclaw:mainfrom
ZengWen-DT:fix/130164-spawn-ambiguous-dispatch
Aug 27, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
ZengWen-DT:fix/130164-spawn-ambiguous-dispatch

Conversation

@ZengWen-DT

@ZengWen-DT ZengWen-DT commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130164

What Problem This Solves

A sessions_spawn call can lose its Gateway acknowledgement after the Gateway has already accepted the child run. The parent then reports status: "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 agent dispatches. Native and ACP spawns use this same path.

  • A settled accepted or in_flight replay returns the existing run.
  • An explicit provisional replay waits with an absolute 6.4-second deadline and 800 ms per-call pacing.
  • A genuine Gateway rejection, another transport failure, or a terminal replay does not retry or register a child.
  • Cleanup and non-agent Gateway calls never retry.

The Gateway now exposes only admissionPending: true for provisional replay. It does not expose the internal reservation ID.

User Impact

  • A lost acknowledgement no longer makes a running child invisible to its parent.
  • The same idempotency key cannot start a duplicate child.
  • A child that settles to timeout or another terminal result is not registered as active.
  • No configuration, storage, timeout option, compatibility path, or new public API was added.

Evidence

Red — exact current main 8e4075371039: An isolated real Gateway accepted and recorded one WebSocket agent dispatch. A frame proxy dropped only the accepted acknowledgement. The parent returned status: "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 two agent frames with one idempotency key. The parent returned status: "accepted". Gateway replay returned the same run ID as in_flight. The parent registry contained exactly one running child, and the controlled provider completed exactly one child turn. Final head 1e9ed747a902 changes only the matching Gateway test assertion.

Terminal control — production-identical head 64be0ae2137f: A real Gateway replay first returned admissionPending: true. A real abort then settled that same run to timeout. The parent returned a visible retry error and registered no child. Final head 1e9ed747a902 changes 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:

node scripts/run-vitest.mjs src/agents/subagents/spawn/subagent-spawn.test.ts src/agents/subagents/spawn/acp-spawn.test.ts src/gateway/agent-turn/agent-request-preflight.test.ts
# 173 passed

node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/subagents/spawn/acp-spawn.test.ts src/agents/subagents/spawn/subagent-spawn-gateway.ts src/agents/subagents/spawn/subagent-spawn.test.ts src/gateway/agent-turn/agent-request-preflight.test.ts src/gateway/agent-turn/agent-turn-service.ts
# passed

git diff --check
# passed

@clawsweeper

clawsweeper Bot commented Aug 27, 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 agents Agent runtime and tooling size: S labels Aug 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 27, 2026, 9:04 AM ET / 13:04 UTC.

ClawSweeper review

What this changes

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

Possible 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
Reviewed head: b12d5762b4b3bc049582a9ab5a77abce177a4375

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The PR has a well-defined reported failure and useful transport evidence, but the current patch retains a P1 false-acceptance path and lacks proof for the required pending-state behavior.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The supplied live trace demonstrates recovery of a settled accepted record, but not the current-head provisional-to-final reconciliation required to prevent a rejected admission being reported as accepted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied live trace demonstrates recovery of a settled accepted record, but not the current-head provisional-to-final reconciliation required to prevent a rejected admission being reported as accepted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current PR retry: The changed out-of-process path immediately repeats the same dispatch after a transport-unavailable error, with no provisional-result discriminator or bounded retry wallet.
Provisional reservation precedes admission: Gateway stores an accepted-shaped dedupe entry containing reservationId before asynchronous routing and admission complete.
Replay misclassifies reservation: Any accepted-shaped cache entry, including one with reservationId, is replayed as in_flight with a runId; the native spawn path then treats any runId as accepted and registers the child.
Findings 2 actionable findings [P1] Keep provisional reservations out of accepted child registration
[P2] Use a bounded reconciliation timeout
Security None None.

Live Verification

Command: pnpm run openclaw -- --help

Result: FAIL (failed) — step 1 expect_output Usage:: expected terminal output was not visible within 30 seconds: "Usage:"

$ node scripts/run-node.mjs -- --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 60.56 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.4s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ 
… output truncated …
                                                              │
│  Ask someone experienced to help before enabling tools or exposing it to the internet.     │
│                                                                                            │
│  Recommended safer setup                                                                   │
│  - Use pairing or allowlists; require mentions in group chats.                             │
│  - Shared inboxes: use separate gateways and credentials; separate OS users or hosts       │
│    provide stronger isolation.                                                             │
│  - Use a sandbox and give tools only the permissions they need.                            │
│  - Shared inboxes: isolate DM sessions (session.dmScope: per-channel-peer) and keep tool   │
│    access minimal.                                                                         │
│  - Keep secrets outside the agent's reachable filesystem.                                  │
│  - Use the strongest available model for bots with tools or shared/public inboxes.         │
│                                                                                            │
│  Run regularly                                                                             │
│  openclaw security audit --deep                                                            │
│  openclaw security audit --fix                                                             │
│                                                                                            │
│  Learn more at https://docs.openclaw.ai/gateway/security                                   │
│                                                                                            │
├────────────────────────────────────────────────────────────────────────────────────────────╯
│
◆  I understand this is personal-by-default and shared/multi-user use requires lock-down. Continue?
│  ● Yes
│  ○ No
└

Assertions:

  • FAIL expect_output: Usage:

How this fits together

Subagent 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]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied live trace demonstrates recovery of a settled accepted record, but not the current-head provisional-to-final reconciliation required to prevent a rejected admission being reported as accepted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep provisional reservations out of accepted child registration (P1) - The replay at this line runs immediately after a timeout. Gateway reserves an accepted-shaped cache entry before asynchronous admission, and its replay path returns that reservation as in_flight with a run ID. Native and ACP then treat the run ID as accepted and register the child, so a later rejection is still reported as a running child. Preserve a pending discriminator and wait only for a settled result before registration.
  • Use a bounded reconciliation timeout (P2) - Both attempts invoke dispatchAgentRequest with the same original timeout. When Gateway is genuinely unreachable, native spawning can wait a second 60–300 second dispatch timeout (ACP another 10 seconds) before returning an error, contrary to the stated unchanged unreachable-Gateway behavior. Reconcile with a short dedicated polling/retry budget.
  • Resolve merge risk (P1) - A lost acknowledgement during a still-provisional reservation can register a native or ACP child as accepted even when Gateway later rejects admission.
  • Resolve merge risk (P2) - A permanently unreachable Gateway receives a second full timeout: native dispatches can wait another 60–300 seconds, and ACP another 10 seconds, before returning the original error class.
  • Improve patch quality - Implement and regression-test provisional-versus-settled Gateway replay handling for both native and ACP spawning.
  • Improve patch quality - Add redacted current-head isolated-Gateway output that loses the first acknowledgement while admission is pending and proves either final acceptance recovery or final rejection without child registration.

Findings

  • [P1] Keep provisional reservations out of accepted child registration — src/agents/subagents/spawn/subagent-spawn-gateway.ts:165-180
  • [P2] Use a bounded reconciliation timeout — src/agents/subagents/spawn/subagent-spawn-gateway.ts:165-180
Agent review details

Security

None.

PR surface

Source +24, Tests +77. Total +101 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 4 +24
Tests 2 77 0 +77
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 105 4 +101

Review metrics

Metric Value Why it matters
Production versus tests production +24/-4, tests +77/-0 The new production retry path needs its additional state distinction and timeout bound to justify the positive bug-fix growth.

Merge-risk options

Maintainer options:

  1. Preserve pending admission state before retrying (recommended)
    Update Gateway replay and the shared spawn seam so a provisional reservation cannot be registered as an accepted child, and bound reconciliation to a short dedicated wallet.

Technical review

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

  • [P1] Keep provisional reservations out of accepted child registration — src/agents/subagents/spawn/subagent-spawn-gateway.ts:165-180
    The replay at this line runs immediately after a timeout. Gateway reserves an accepted-shaped cache entry before asynchronous admission, and its replay path returns that reservation as in_flight with a run ID. Native and ACP then treat the run ID as accepted and register the child, so a later rejection is still reported as a running child. Preserve a pending discriminator and wait only for a settled result before registration.
    Confidence: 0.99
  • [P2] Use a bounded reconciliation timeout — src/agents/subagents/spawn/subagent-spawn-gateway.ts:165-180
    Both attempts invoke dispatchAgentRequest with the same original timeout. When Gateway is genuinely unreachable, native spawning can wait a second 60–300 second dispatch timeout (ACP another 10 seconds) before returning an error, contrary to the stated unchanged unreachable-Gateway behavior. Reconcile with a short dedicated polling/retry budget.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: The patch can make a rejected subagent admission appear as an active child run to its parent.
  • merge-risk: 🚨 session-state: Both native and ACP paths can register a child run from a provisional Gateway cache entry.
  • merge-risk: 🚨 availability: The retry repeats the caller’s full timeout when the Gateway is actually unreachable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied live trace demonstrates recovery of a settled accepted record, but not the current-head provisional-to-final reconciliation required to prevent a rejected admission being reported as accepted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/agent-turn/agent-request-preflight.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/subagents/spawn/subagent-spawn.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/subagents/spawn/acp-spawn.test.ts.
  • [P1] pnpm tsgo:core.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Recent history includes the spawn-family refactor and Gateway subagent completion work adjacent to the affected seam. (role: recent Gateway and subagent-path contributor; confidence: high; commits: 2cd87d3d27c1, 1ced7441eb6a, 8430fc0e3b86; files: src/agents/subagents/spawn/subagent-spawn-gateway.ts, src/gateway/agent-turn/agent-turn-service.ts)
  • Josh Avant: The admission/replay path carries the subagent execution-lineage work introduced in the current Gateway architecture. (role: execution-lineage feature contributor; confidence: medium; commits: 916aca13f340; files: src/agents/subagents/spawn/subagent-spawn-gateway.ts)

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 (6 earlier review cycles)
  • reviewed 2026-08-27T02:16:59.661Z sha 761ecd746fc7e15a2602f7f705ef8baeaf82a7e6 :: needs real behavior proof before merge. :: [P1] Reconcile the ACP sessions_spawn launch as well
  • reviewed 2026-08-27T03:05:06.846Z sha 56c3c86e265323bda9ed7fa224e8bb2deed5e443 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T07:45:39.517Z sha 56c3c86e265323bda9ed7fa224e8bb2deed5e443 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T08:49:49.447Z sha d86c41aebb20594f3ccb837c240f44b7c401279f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T09:34:26.329Z sha d86c41aebb20594f3ccb837c240f44b7c401279f :: found issues before merge. :: [P1] Do not report a provisional reservation as an accepted child run
  • reviewed 2026-08-27T12:37:23.715Z sha d04fc5431beb95d2f0e563e90443d199b189c5e6 :: needs real behavior proof before merge. :: [P1] Wait between provisional replay attempts

@ZengWen-DT
ZengWen-DT force-pushed the fix/130164-spawn-ambiguous-dispatch branch from 761ecd7 to 56c3c86 Compare August 27, 2026 02:58
@ZengWen-DT

Copy link
Copy Markdown
Contributor Author

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 (src/agents/subagents/spawn/subagent-spawn-gateway.ts), which both native and runtime="acp" spawn dispatch route through. The replay is guarded to method === "agent" dispatch calls, so cleanup and other non-dispatch sessions.* calls are never retried.

Added a regression test driving the runtime="acp" dispatch with the same transport-ambiguous fault, asserting the accepted ACP run is surfaced after exactly one replay (acp-spawn.test.ts, 78 passed alongside native subagent-spawn.test.ts 72 passed). The PR now covers both sibling paths in one canonical seam rather than a one-sided native-only fix.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Aug 27, 2026
@ZengWen-DT

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
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 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 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 27, 2026
@ZengWen-DT
ZengWen-DT force-pushed the fix/130164-spawn-ambiguous-dispatch branch from 56c3c86 to d86c41a Compare August 27, 2026 08:42
@ZengWen-DT

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
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 merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 27, 2026
@ZengWen-DT
ZengWen-DT force-pushed the fix/130164-spawn-ambiguous-dispatch branch from d86c41a to d04fc54 Compare August 27, 2026 12:30
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: S labels Aug 27, 2026
@ZengWen-DT

Copy link
Copy Markdown
Contributor Author

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 accepted dedupe reservation (carries reservationId) before asynchronous admission completes (agent-turn/agent-dedupe-lifecycle.ts reserve()), and replayAgentTurnIfCached emitted any cached accepted record — provisional or final — as in_flight with a runId. So a timed-out first dispatch whose admission later rejects was surfaced and registered as an accepted child.

Discriminator. A provisional reservation payload has reservationId; a final-admission record (agent-turn/agent-run-admission-phase.ts) omits it. Admission overwrites the entry on settle, so the signal self-corrects.

Changes.

  • agent-turn/agent-turn-service.ts: a cached provisional replay is now returned as in_flight with admissionPending: true; settled final-accept replays stay plain in_flight.
  • subagent-spawn-gateway.ts (shared native+ACP seam): reconciliation now polls with a short bounded wallet (800ms × 8) and only returns a settled non-provisional replay as accepted; an unresolved provisional reservation — or a genuinely unreachable gateway — returns the original error instead of certifying acceptance. This also removes the P2 second full 60–300s wait on an unreachable gateway.

Coverage. Gateway regression asserts a provisional replay is tagged admissionPending while a settled one is not; spawn regression asserts a delayed-reject reservation is never registered as an accepted child.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
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 status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@ZengWen-DT
ZengWen-DT force-pushed the fix/130164-spawn-ambiguous-dispatch branch from d04fc54 to a964513 Compare August 27, 2026 12:51
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed gateway Gateway runtime size: M labels Aug 27, 2026
@ZengWen-DT
ZengWen-DT force-pushed the fix/130164-spawn-ambiguous-dispatch branch from a964513 to b12d576 Compare August 27, 2026 12:58
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 27, 2026
…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.
@obviyus
obviyus force-pushed the fix/130164-spawn-ambiguous-dispatch branch from b12d576 to 8cab6fb Compare August 27, 2026 15:52
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 27, 2026
@obviyus
obviyus force-pushed the fix/130164-spawn-ambiguous-dispatch branch from 8cab6fb to 64be0ae Compare August 27, 2026 16:04
@obviyus
obviyus force-pushed the fix/130164-spawn-ambiguous-dispatch branch from 64be0ae to 1e9ed74 Compare August 27, 2026 16:29
@obviyus
obviyus merged commit bcb5403 into openclaw:main Aug 27, 2026
457 of 459 checks passed
@obviyus

obviyus commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

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 accepted, and registered exactly one running child. A provisional replay that was then aborted settled to timeout; the parent returned a retry error and registered no child. Exact-head CI passed in run 33093640488.

  • Bug: A lost acknowledgement could make a running subagent look like a failed spawn, or make a terminal run look active.
  • Fix: The shared spawn boundary now waits only for explicit provisional admission, accepts only a settled active run, and reuses the existing idempotency key.

Example

Before After
Gateway accepted the child, but the parent returned status: error after the acknowledgement was lost. The parent reconciles the same key and returns the one accepted child run.
A provisional run later settled to timeout, but the parent could register it as active. Terminal reconciliation returns a visible retry error and leaves the child registry empty.

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

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sessions_spawn returns "Unable to connect" to the caller while the dispatch actually lands and runs (false-negative dispatch)

2 participants