Skip to content

fix(subagents): resume nested orchestrators after sessions_yield - #140137

Merged
steipete merged 7 commits into
openclaw:mainfrom
gaoanze888:fix/nested-requester-yield-batch-wake
Sep 7, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
gaoanze888:fix/nested-requester-yield-batch-wake

Conversation

@gaoanze888

@gaoanze888 gaoanze888 commented Sep 6, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Closes #139963. Related: #140405.

Fixes an issue where nested orchestrators stayed paused after sessions_yield even though their workers had finished. Cron-spawned orchestrators exposed the same shared failure without an interactive parent to nudge them. The cron report is from @BottaniCals; this finishes @gaoanze888's existing repair and preserves the contributor's commits and credit.

Why This Change Was Made

Yield settlement transferred completion responsibility to requesterSettleWake, but subagent-announce.requester-settle-wake.ts discarded every nested batch at its depth guard. Gateway task tracking separately excluded every inter-session request, so a dispatched continuation could run without adopting the paused task or retaining its original requester.

Explicit yield batches now dispatch internally at any requester depth. The settlement owner emits subagent_settle provenance, and Gateway admission uses the existing paused-run adoption operation for that continuation. Ordinary announcements and sessions_send remain independent; the older descendant-wake path retains its own replacement operation. Completion classification, history projection, and the QA mock provider recognize the settlement label.

The design in docs/concepts/subagent-yield-handoff.md names the execution, settlement, admission, and delivery owners and their ordering, bounds, and finalization rules. Keeping old callbacks alive would use closed execution authority and finalized channel drafts. Removing the cron root exclusion would create a competing scheduler delivery path, so that exclusion remains.

User Impact

Operators who allow nested spawning can let an orchestrator yield, receive its workers' results, and complete the original task, including when cron spawned the orchestrator. No new configuration, schema, dependency, or public SDK surface is required.

Channel-visible progress across yield remains documented follow-up work: it needs a settlement publisher and a handoff to the admitted successor. Cron's existing active-run observer and bounded synthesis grace remain unchanged. The separate finalized-cron pending-delivery observation still needs reproduction and scheduler-lifecycle proof.

Evidence

Head: 3c03bf6f8583e491e2577a4c8bf15bec37c4c9ee.

The original owner code was reproduced at b39b6276cac298ce4562182f1b42335e03042397. The nested wake cases failed while normal controls passed; Gateway continuation cases for both normal and cron parents retained the old paused run ID. After the repair, the existing harnesses verify internal nested wake delivery, current generation ownership, duplicate dispatch suppression, Gateway adoption, successful final result delivery to the original parent, and idempotent request replay.

  • Registry, settlement, cron, and QA regressions: 147 passed across five files. After relocating the nested cases into the existing dispatch harness to meet its sibling file's line limit, the dispatcher was rechecked against the original owner (both nested cases failed with zero wakes), then the full dispatch harness passed 12 tests with the fix.
  • Focused Gateway continuation matrix: 6 passed, covering normal/cron parents and settlement/ordinary-announcement/session-send inputs. Model execution and announcement transport are synthetic; admission, adoption, and registry finalization are real. The command exited 0; local Vitest emitted a worker-shutdown timeout warning.
  • History and provenance cases passed, including hidden settlement inputs and removal of stale settlement/synthesis pairs. Documentation MDX checks passed for both changed pages, and the canonical docs parser resolved the linked anchor.
  • Existing real-runtime Gateway/QA-channel E2E: 1 passed, exit 0. Its synthetic HTTP provider drove one sessions_yield, two child model requests, a distinct successor, exactly one visible original-requester completion, and zero duplicates after both a quiet window and Gateway restart. This exercises plugin-initiated follow-up adoption, not automatic nested settlement; it complements the six-case settlement matrix and does not claim a single full nested cron end-to-end run.
  • The opt-in live provenance probe now recognizes both valid subagent completion owners. It was typechecked; no live provider execution is claimed.
  • Independent Codex autoreview: scoped-clean through P2, no accepted actionable findings.
  • pnpm check:changed: passed. Exact-head CI and Dependency Guard: passed. Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 140137 passed on this head using the hosted CI/Testbox gates.

Focused commands (using one Vitest worker):

OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_TEST_PROJECTS_PARALLEL=1 node scripts/run-vitest.mjs src/agents/subagents/announce/subagent-announce.requester-settle-wake.test.ts src/agents/subagents/announce/subagent-announce.requester-settle-dispatch.test.ts src/agents/subagents/registry/subagent-registry-requester-yield.test.ts src/cron/isolated-agent/subagent-followup.test.ts extensions/qa-lab/src/subagent-forked-context.test.ts
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/server-methods/agent.test.ts -t 'followups to a yielded orchestrator'
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/qa-lab/src/plugin-subagent-self-yield-followup.e2e.test.ts -t 'announces to the original requester only after the follow-up run ends'
pnpm check:changed
git diff --check
Scope Added Removed Net
Production (including the QA mock provider) 39 13 +26
Tests and test support 285 67 +218
Documentation 105 3 +102

The production growth connects existing lifecycle owners and preserves presentation semantics for the distinct settlement event. The contributor's duplicated test setup was consolidated into the existing harnesses, with stronger continuation and original-parent completion assertions.

…penclaw#139963)

When a nested subagent requester (depth >= 1) explicitly yielded while its
child was running, the yield-batch wake was armed but never dispatched.
The depth guard in maybeWakeRequesterAfterAllChildrenSettled unconditionally
skipped wake dispatch for any requester at depth >= 1, even when the requester
had an armed yield batch (requesterYieldedAfterDelivery = true). The wake entry
was cleared as fulfilled with zero dispatches, leaving the yielded requester
stalled.

Gates the depth skip on !requesterYieldedAfterDelivery so that a yielded
nested requester receives its owed wake dispatch (same shape as a root
requester). Also sets requesterIsSubagent based on actual depth so the nested
wake routes session-internally instead of to an external channel.

Regression tests in a new split file verify:
- A nested yielded requester is woken with exactly one dispatch, with
  requesterIsSubagent=true and requireVisibleReply=true.
- A nested orchestrator without a yield is still left to the descendant-settle
  wake (preserves existing behavior).
@clawsweeper

clawsweeper Bot commented Sep 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 in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Sep 6, 2026
@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Sep 6, 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 P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 7, 2026, 1:08 AM ET / 05:08 UTC.

ClawSweeper review

What this changes

Resumes yielded nested subagents after their children finish, preserves completion delivery to the original parent, and updates related tests, history handling, and lifecycle documentation.

Merge readiness

⛔ Blocked before merge - 3 items remain

The repair remains necessary on current main, and the earlier adoption findings are addressed. The stronger Gateway tests are useful, but real runtime proof remains incomplete; the protected security label also prevents automatic closure.

Priority: P2
Reviewed head: 3c03bf6f8583e491e2577a4c8bf15bec37c4c9ee

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and the regression coverage is stronger, but synthetic execution and transport leave the required runtime proof incomplete.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The supplied head-specific evidence exercises real Gateway admission, paused-run adoption, and registry finalization, but substitutes model execution and announcement transport. It does not yet show the settlement-to-successor-to-parent flow in a real setup. 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 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The supplied head-specific evidence exercises real Gateway admission, paused-run adoption, and registry finalization, but substitutes model execution and announcement transport. It does not yet show the settlement-to-successor-to-parent flow in a real setup. 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 7 items Current main still has both blocking gates: At the fetched main revision, requester settlement still excludes every nested requester, and Gateway task tracking still excludes all inter-session input. The central repair is therefore not already implemented.
Latest release retains the nested-depth exclusion: The supplied latest release, v2026.9.2, clears nested settlement batches without dispatching their continuation.
Prior adoption findings addressed: Settlement now uses distinct subagent_settle provenance. Only that inter-session input selects paused-run adoption; ordinary announcements and sessions_send remain untracked. The existing adoption operation preserves the original requester and settlement obligation.
Findings None None.
Security None None.

How this fits together

The subagent registry tracks delegated work and schedules continuations when children finish. Gateway admission reconnects the resumed execution to its paused task so its result can reach the original interactive or cron parent.

flowchart TD
  A[Interactive or cron parent] --> B[Nested orchestrator yields]
  B --> C[Workers finish]
  C --> D[Registry settlement batch]
  D --> E[Gateway admits continuation]
  E --> F[Paused task adopts new execution]
  F --> G[Completion returns to original parent]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied head-specific evidence exercises real Gateway admission, paused-run adoption, and registry finalization, but substitutes model execution and announcement transport. It does not yet show the settlement-to-successor-to-parent flow in a real setup. 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.
  • Resolve merge risk (P1) - The changed continuation path replaces a paused execution while retaining its completion audience; real execution and transport have not yet demonstrated that this handoff produces one completion at the original parent.
  • Complete next step (P2) - Add after-fix evidence from a real setup showing automatic nested resumption and one completion to the original parent. Terminal output or redacted logs count; screenshots or recordings are welcome when they show the flow. Remove credentials, IP addresses, phone numbers, and private endpoints. Updating the PR body should trigger re-review; otherwise ask a maintainer to comment @clawsweeper re-review.
Agent review details

Security

None.

PR surface

Source +26, Tests +218, Docs +102. Total +346 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 5 39 13 +26
Tests 8 285 67 +218
Docs 2 105 3 +102
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 429 83 +346

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #139963
Summary: This PR is the candidate repair for the nested settlement defect; the cron report also contains separate scheduler-delivery observations.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Verify the complete continuation handoff (recommended)
    Provide redacted runtime evidence that a yielded nested orchestrator resumes, retains its original parent, and delivers exactly one completion through the real production path.

Technical review

Best possible solution:

Keep settlement and paused-run adoption with their existing lifecycle owners, supported by real Gateway evidence of resumed execution and original-parent completion.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: with nested spawning enabled, an explicitly yielded requester reaches main's unconditional depth exclusion and loses its settlement wake. This review did not execute the reproduction.

Is this the best way to solve the issue?

Yes, the patch connects the existing settlement and adoption owners without creating a competing continuation mechanism; the new provenance distinction preserves ordinary inter-session behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fd5c985d50a3.

Labels

Label justifications:

  • P2: This repairs silent stalls in the supported but opt-in nested delegation workflow.
  • merge-risk: 🚨 session-state: The patch changes paused-run adoption and completion ownership across executions, while end-to-end runtime evidence remains outstanding.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied head-specific evidence exercises real Gateway admission, paused-run adoption, and registry finalization, but substitutes model execution and announcement transport. It does not yet show the settlement-to-successor-to-parent flow in a real setup. 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

What I checked:

Likely related people:

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

Rank-up moves

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

  • Add redacted after-fix output showing automatic nested resumption, preserved parent identity, and one parent completion through the real Gateway and delivery path.

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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-06T14:20:02.980Z sha 9e18b88 :: needs real behavior proof before merge. :: [P1] Restrict paused-run adoption to the owed settlement continuation | [P2] Mock the production registry module with a hoisted spy
  • reviewed 2026-09-06T14:34:46.619Z sha cc37527 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T14:41:51.943Z sha cc37527 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T14:57:38.192Z sha 4c93f6b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T15:04:04.567Z sha 4c93f6b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T15:11:28.467Z sha 529e694 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T21:08:02.106Z sha 529e694 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T22:15:04.613Z sha 529e694 :: needs real behavior proof before merge. :: none

…low-up admission

Resolve P1 bot review finding: the nested requester's settle wake dispatches
an inter_session follow-up turn, but resolveGatewayAgentTaskTrackingMode
returned 'none' for inter_session provenance — skipping
registerPluginSubagentRunFromGateway and its adoptPausedSubagentRunForFollowUp
call. The paused middle run was never adopted, so its requesterSettleWake was
lost and the original requester never received its completion.

Fix: when inter_session provenance targets a session with a paused
sessions_yield run, return 'plugin_subagent' so admission calls
adoptPausedSubagentRunForFollowUp before the turn starts. The adoption
replaces the paused run with this turn's runId and preserves its
requesterSettleWake (with preserveRequesterSettleWake: true), ensuring
completion propagates to the original requester when the continuation ends.

Adds unit tests for the inter_session paused-run adoption gate.
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 6, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 6, 2026
gaoanze888 added 2 commits September 6, 2026 22:26
Address P1+P2 bot review findings:

P1: Restrict the inter_session paused-run adoption to sourceTool ===
'subagent_announce' (the settlement continuation wake). Ordinary
inter_session messages (e.g. sessions_send) must remain untracked per
docs/tools/subagents.md — sending a status question to a yielded child
must not adopt and replace its paused run.

P2: Fix the mock path from ../../../ (nonexistent) to ../../ (correct
relative to src/gateway/server-methods/) and use vi.hoisted() pattern.
Add regression test for sessions_send that must NOT trigger adoption.
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 6, 2026
@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Sep 6, 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:

Uses the real in-memory subagent registry (addSubagentRunForTests) to
verify that resolveGatewayAgentTaskTrackingMode returns plugin_subagent
when a paused sessions_yield run is registered — no vi.mock on
getLatestLiveSubagentRunByChildSessionKey. 4 tests, all passing.
@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Sep 6, 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:

The real-registry test passes { internal: {} } as the client, which is
missing the required 'connect' property of GatewayClient. Use the same
'as Parameters<...>["client"]' cast as the inter-session-adoption test.
@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Sep 6, 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:

@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Sep 6, 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:

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 3c03bf6f8583e491e2577a4c8bf15bec37c4c9ee

@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Maintainer review of head 3c03bf6f8583e491e2577a4c8bf15bec37c4c9ee: the reported code findings are resolved; the remaining proof request is addressed with complementary owner and runtime evidence.

The existing real ephemeral Gateway and QA-channel test passed:

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/qa-lab/src/plugin-subagent-self-yield-followup.e2e.test.ts -t 'announces to the original requester only after the follow-up run ends'

Result: 1 passed, exit 0. Its synthetic HTTP provider produced one sessions_yield, two child model requests, a distinct successor, one visible completion to the original requester, and zero duplicate replies after the quiet window and Gateway restart. The test took 70.8 seconds; the wrapper including the isolated runtime build took 453.3 seconds.

This runtime test enters through plugin follow-up adoption. Automatic nested settlement is separately covered by the original-source failing dispatcher cases and the six-case normal/cron Gateway matrix, which passes adoption, original-requester completion, and replay assertions. I accept this combined proof for the bounded owner repair and defer a new single full-chain nested cron fixture; neither a live external provider run nor that complete end-to-end chain is claimed. Channel progress publication and the separate finalized-cron pending-delivery observation remain documented follow-ups.

Exact-head CI and native hosted preparation passed. The file labeler also removed the stale security and unrelated subsystem labels after the PR base projection was corrected; no security override was used. The PR body now includes these results and limitations.

@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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 docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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.

[Bug]: nested subagent requester's yield-batch wake is armed but never dispatched, then cleared

3 participants