Skip to content

fix(agents): deliver subagent completions after parent turns end - #126122

Merged
steipete merged 1 commit into
mainfrom
steipete/qa-subagent-terminal-event
Aug 19, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/qa-subagent-terminal-event

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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-fallback QA 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

  • Pre-fix Node 24 repro on current origin/main: the exact refactor(canvas): make the panel a widget presenter #126030 private-QA invocation failed after 60 seconds with final 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).
  • Post-fix Node 24 repro: the same profile, concurrency, and scenario passed all five verdicts (visible, silent, fallback, restart, empty). Each expected terminal send count was 1; all task delivery statuses were delivered; 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.

@clawsweeper

clawsweeper Bot commented Aug 19, 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 the agents Agent runtime and tooling label Aug 19, 2026
@steipete
steipete marked this pull request as ready for review August 19, 2026 01:46
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 19, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 10:36 PM ET / August 19, 2026, 02:36 UTC.

ClawSweeper review

What this changes

The PR preserves a Gateway-instance resolver across detached subagent completion cleanup and requester-settle dispatch so terminal replies reach the originating conversation.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep 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
Reviewed head: 88362dae37951b9fa957063ebcef71a2532991b9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair is focused and source-backed with meaningful Gateway QA evidence; a rebased exact-head run is the remaining merge confidence step.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides after-fix ephemeral-Gateway QA evidence for all five affected completion outcomes and their recorded delivery status.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides after-fix ephemeral-Gateway QA evidence for all five affected completion outcomes and their recorded delivery status.
Evidence reviewed 6 items Current dispatch contract: The in-process dispatcher resolves the request scope first, then the supplied Gateway resolver, and rejects only when both are absent; this is the reported detached-cleanup failure boundary.
Resolver propagation: The PR forwards the lifecycle-owned resolver through announce flow, delivery, and direct agent dispatch, reaching the dispatcher that consumes it.
Fail-closed batching: A requester-settle batch supplies a resolver only when every child carries the identical captured resolver; mixed ownership returns no resolver.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_BUILD_PRIVATE_QA=1 OPENCLAW_ENABLE_PRIVATE_QA_CLI=1 node openclaw.mjs qa run --repo-root . --qa-profile smoke-ci --concurrency 10 --output-dir /tmp/openclaw-qa-subagent-fallback --scenario subagent-completion-direct-fallback

Result: FAIL (failed) — execution before step 1 run: live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

Assertions:

  • FAIL expect_output: visible
  • FAIL expect_output: delivered

How this fits together

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

Before merge

  • Resolve merge risk (P1) - The patch changes terminal message delivery across an in-memory ownership boundary; validate the recorded QA scenario again after rebasing onto current main.
  • Complete next step (P2) - Maintainer-authored, protected-label work should proceed through normal exact-head review rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source +18, Tests +15. Total +33 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 6 21 3 +18
Tests 2 18 3 +15
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 39 6 +33

Review metrics

Metric Value Why it matters
Production versus test LOC production +21/-3; tests +18/-3 The production growth is limited to forwarding the private lifecycle resolver through the existing dispatch path.

Merge-risk options

Maintainer options:

  1. Validate the rebased delivery path (recommended)
    Rebase onto current main and rerun the detached-completion QA scenario to prove terminal replies still deliver exactly once through the admitted Gateway instance.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto current main and attach redacted detached-completion QA output showing exact-once terminal delivery.

Technical review

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

Labels

Label changes:

  • add P1: Without this repair, successful detached subagents can fail to deliver their terminal reply after the parent turn ends.
  • add merge-risk: 🚨 message-delivery: The PR changes the Gateway context used for terminal subagent-reply dispatch.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix ephemeral-Gateway QA evidence for all five affected completion outcomes and their recorded delivery status.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix ephemeral-Gateway QA evidence for all five affected completion outcomes and their recorded delivery status.

Label justifications:

  • P1: Without this repair, successful detached subagents can fail to deliver their terminal reply after the parent turn ends.
  • merge-risk: 🚨 message-delivery: The PR changes the Gateway context used for terminal subagent-reply dispatch.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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): The PR body provides after-fix ephemeral-Gateway QA evidence for all five affected completion outcomes and their recorded delivery status.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix ephemeral-Gateway QA evidence for all five affected completion outcomes and their recorded delivery status.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current repair and the immediately preceding merged instance-binding and refactor work in this lifecycle path. (role: recent area contributor; confidence: high; commits: 88362dae3795, 2cd87d3d27c1, 6d4950365b42; files: src/agents/subagents/announce/subagent-announce-direct-delivery.ts, src/agents/subagents/registry/subagent-registry-lifecycle-announce-cleanup.ts, src/plugins/runtime/gateway-request-scope.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and publish the redacted result of the same detached-completion QA scenario.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready for 88362dae37951b9fa957063ebcef71a2532991b9:

  • Exact-head CI: 179 passing checks, 45 skipped, no failures or pending checks.
  • Detached-completion ephemeral-Gateway QA: visible, silent, fallback, restart, and empty outcomes all passed with exact-once terminal delivery/recording, no stale replay, and no metadata leakage.
  • Focused owner coverage: 3 files / 172 tests passed; pnpm check:changed passed.
  • Fresh Codex autoreview: clean, no accepted/actionable findings (0.98 correctness confidence).
  • Native review artifacts: validated READY FOR /prepare-pr, 0 findings.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 126122: passed in hosted_exact_or_recent_parent mode; prep and PR heads are byte-identical.

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.

@steipete
steipete merged commit f229770 into main Aug 19, 2026
293 of 294 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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: XS 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