Repository navigation
fix(subagents): resume nested orchestrators after sessions_yield - #140137
Conversation
…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).
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs real behavior proof before merge. Reviewed September 7, 2026, 1:08 AM ET / 05:08 UTC. ClawSweeper reviewWhat this changesResumes 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 Review scores
Verification
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +26, Tests +218, Docs +102. Total +346 across 15 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel 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
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
…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.
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.
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. 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.
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. 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.
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Dependency graph guard clearedThis PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh
|
|
Maintainer review of head 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 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. |
|
Merged via squash.
|
What Problem This Solves
Closes #139963. Related: #140405.
Fixes an issue where nested orchestrators stayed paused after
sessions_yieldeven 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, butsubagent-announce.requester-settle-wake.tsdiscarded 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_settleprovenance, and Gateway admission uses the existing paused-run adoption operation for that continuation. Ordinary announcements andsessions_sendremain 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.mdnames 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.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.pnpm check:changed: passed. Exact-head CI and Dependency Guard: passed. NativeOPENCLAW_TESTBOX=1 scripts/pr prepare-run 140137passed on this head using the hosted CI/Testbox gates.Focused commands (using one Vitest worker):
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.