Repository navigation
fix(agents): deliver subagent completions after parent turns end - #126122
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 10:36 PM ET / August 19, 2026, 02:36 UTC. ClawSweeper reviewWhat this changesThe PR preserves a Gateway-instance resolver across detached subagent completion cleanup and requester-settle dispatch so terminal replies reach the originating conversation. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open for normal maintainer review: this is a focused repair for a current-main detached-completion delivery failure, and no blocking patch defect was found. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — execution before step 1 Assertions:
How this fits togetherSubagent completions outlive their parent turn and must send a terminal reply through the Gateway instance that admitted the work. The in-memory resolver bridges lifecycle cleanup to the direct announcement dispatcher without persisting Gateway state. flowchart LR
A[Parent agent turn] --> B[Subagent registration]
B --> C[Gateway instance binding]
C --> D[Detached completion cleanup]
D --> E[Direct announcement dispatch]
E --> F[Originating conversation]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +18, Tests +15. Total +33 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Retain the exact captured resolver through both individual cleanup and requester-settle paths, then verify exact-once terminal delivery on the rebased head. Do we have a high-confidence way to reproduce the issue? Yes: the current direct dispatcher rejects detached calls without a request scope or instance resolver, and the PR supplies a focused ephemeral-Gateway QA reproduction path. Is this the best way to solve the issue? Yes: carrying the existing lifecycle-owned resolver is the narrow owner-boundary repair and avoids a global active-Gateway fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 23da04ba8af4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready for
ClawSweeper outcome: no patch findings and proof sufficient. I am explicitly skipping its optional rebase-and-rerun rank-up move: this exact head already contains the published post-rebase QA proof, all exact-head checks are green, subsequent main drift is unrelated app/test work, and the native prepare gate validated the merge candidate without changing the PR head. No fresh ClawSweeper review is required because the latest review is under 12 hours old and there has been no post-review behavior change. |
|
Merged via squash.
|
Related: #126030
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where a native subagent could complete successfully after its parent turn ended, but its terminal reply would never reach the originating conversation. The detached completion retried until the task remained without a recorded delivery outcome, and the
subagent-completion-direct-fallbackQA scenario timed out after 60 seconds.PR #126030 recorded the reproducible main-owned failure and exact private-QA invocation in its “Known main-owned failures” section.
Why This Change Was Made
Detached completion delivery now retains the exact Gateway instance resolver captured when the subagent was registered and carries it through lifecycle cleanup, requester-settle wake, and direct announcement dispatch. A settle batch only reuses a resolver when every child belongs to that same instance; mixed-owner batches fail closed instead of guessing an active Gateway.
This restores the instance-binding design from #126062 that was accidentally disconnected by #126071 and subsequently removed as apparently unused by #126084. It does not add a global active-instance fallback, change the Gateway protocol, or change storage/config schemas.
Production LOC: +21/-3 (net +18). Tests: +18/-3 (net +15). The production growth is the ownership chain required to carry the existing exact-instance resolver from its lifecycle producer to the dispatcher.
AI-assisted: Codex. The implementation and evidence were inspected locally before publication.
User Impact
Subagent completions that arrive after the parent turn has finished are delivered exactly once again. Visible, silent, fallback, restart-recovered, and intentionally empty completions all reach a recorded terminal outcome without leaking internal metadata or replaying old payloads after Gateway restart.
No screenshot is attached because this is channel-delivery lifecycle behavior. The repo-native QA scenario exercises the mock provider, ephemeral Gateway, real transport boundary, task ledger, restart, and QA bus end to end.
Evidence
origin/main: the exact refactor(canvas): make the panel a widget presenter #126030 private-QA invocation failed after 60 seconds withfinal bus-event kinds=[inbound-message,outbound-message]. Gateway logs showed three rejected retries:In-process gateway dispatch requires a gateway request scope or instance binding (method: agent).visible,silent,fallback,restart,empty). Each expected terminal send count was 1; all task delivery statuses weredelivered; restart replay and unexpected-payload counts were 0; silence/internal metadata leak flags were false.PATH=/opt/homebrew/opt/node@24/bin:$PATH OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build qaRuntime— pass.PATH=/opt/homebrew/opt/node@24/bin:$PATH node scripts/run-vitest.mjs src/agents/subagents/announce/subagent-announce-delivery.test.ts src/agents/subagents/announce/subagent-announce-delivery.runtime.test.ts src/agents/subagents/registry/subagent-gateway-context-binding.test.ts— pass after rebase, 3 files / 172 tests across 2 shards.PATH=/opt/homebrew/opt/node@24/bin:$PATH pnpm check:changed— pass, including core/core-test typecheck, lint, formatting, dead-export, import-cycle, database-first, and architecture guards..agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output— clean; no accepted/actionable findings, patch judged correct at 0.98 confidence.