Skip to content

fix(subagents): wake a yielded requester for each ready child result - #203176

Merged
obviyus merged 5 commits into
mainfrom
fix/requester-yield-partial-wake
Nov 21, 2026
Merged

obviyus merged 5 commits into
mainfrom
fix/requester-yield-partial-wake

Conversation

@obviyus

@obviyus obviyus commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A requester that calls sessions_yield after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own sessions_yield while a background command runs, held every finished result back.

Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no announce:requester-settle:… run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were terminal/ok with delivery.status: pending and a pending requesterSettleWake (batchRunIds = all 3, rearmGeneration: 1). The third row was still running. The gate in subagent-announce.requester-settle-wake.ts returned false unless every frozen member passed isRequesterSettleMemberReady. #200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class.

Change

Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same rearmGeneration, and wake the parent again when they finish. Each result is delivered once.

  • Settle wake: removed the all-or-nothing gate and the message-wait exception (isEndedSubagentMessageWait is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake.
  • Wake message: a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call sessions_yield to wait; otherwise act on the ready results without reporting the batch as finished.
  • Lifecycle failure path: offeredBatch now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded.
  • Yield transfer: when a child ended before the yield and a sibling is still running, afterRelease now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended.
  • Followup owners (sessions_send wait-for-reply, agent-step, nested agent-run-subagent): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. successor() accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure.
  • Automation authority: a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority.
  • Silent waits: while siblings are still working, the parent may stay silent (NO_REPLY) and wait. Such a turn is not treated as a missing visible reply, so it is not retried.
  • Goal return: an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once.
  • isRequesterSettleMemberReady moved to subagent-run-liveness.ts, its only owner, and replaces the deleted message-wait predicate.
  • Docs: tools/subagents/announce.md and concepts/subagent-yield-handoff.md.

Product decisions, under the rules "no stranded user" and "no false done":

  • A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings.
  • A followup caller gets one reply, after all results are in. The session itself is still woken for each result.

Evidence

Regression test (subagent-registry.requester-wake.e2e.test.ts, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it.

  • Base eb7ca3d33375: both cases red (expected [] to have a length of 1: no wake).
  • Head: both cases green.

Owner tests: cron authority (requester-cron-authority.test.ts: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (subagent-announce.requester-settle-followup.test.ts: early partition runs with no followup successor, last partition carries it). Goal partition (goal-continuation.test.ts: early partition does not resume the Goal, last partition resumes it once).

Updated tests that asserted the all-at-once rule: requester-settle-cross-turn (paused member), subagent-control.worker progress card (one wake per result; the card retires once), requester-wake-settlement (stopped child).

Real-Gateway E2E, incident shape. Scratch ocx src Gateway under env -i, OpenAI gpt-5.5 on the OpenClaw runtime. Parent spawns alpha (replies at once) and beta (exec with background: true running sleep 90, then sessions_yield), then yields.

alpha ended first parent wake beta yielded beta ended second parent wake
base 19:47:10 19:48:53 (one combined run, after beta) 19:47:13 19:48:50 none
head 19:40:08 19:40:11 (announce:requester-settle:…:<alpha>:yield-1) 19:40:12 19:41:55 19:41:59 (…:<beta>:yield-1)

The parent's replies on head were alpha: ALPHA-RESULT-7, then alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9. The live Peanutto launchd pid and openclaw.json hash did not change.

Live sibling suites (subagent-yield-pause, subagent-followup-yield, subagent-yield-resume, real OpenAI gpt-5.5): the same tests fail on base eb7ca3d33375 and on this branch, with the same assertions (missing completion.resultText after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (test/gateway-*-restart*.e2e.test.ts) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions).

Gates: pnpm tsgo:core, pnpm check:test-types, oxlint and oxfmt on the changed files. Every test file in src/agents/subagents and goal-continuation.test.ts was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base.

Size

Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of batchRunIds, requesterYieldBatch, the frozen branch and selectConnectedSettledSubagentWave found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code.

Accepted edge cases

  • If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today.
  • A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion.

Merge danger

  • Two-way door. No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran.
  • Blast radius: requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session.

A requester that yielded after spawning several completion children was woken
only when every member of the frozen batch was ready, so a sibling that kept
running or exec-yielded hid finished results for hours. Deliver the ready
members as a partition; members still working keep their wake and generation
and wake the requester again. Followup callers and Goal returns continue on
the partition that leaves nothing pending.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR delivers ready child results to a yielded requester while unfinished siblings retain their later completion wakes.

Example: A parent yields after spawning alpha and beta; alpha finishes while beta runs a background sleep.

  • Before: Alpha's result waits until beta finishes, then both arrive together.
  • After: Alpha wakes the parent first; beta wakes it later without repeating alpha's result.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and supported by shipped-entry-point evidence, with one confirmed consumer-test failure preventing a clean validation verdict.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records the changed settlement owner exercised through an isolated real Gateway and model: alpha wakes the yielded parent before beta finishes, and beta later creates its own wake with the expected replies; regression evidence also covers a result completed before yield.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Finished child reports remain hidden from a yielded parent while a sibling keeps working.
Reason: The maintainer-authored direction addresses a concrete production stall and preserves one-reply follow-up behavior; it needs no further product approval.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR addresses a demonstrated requester stall, but an existing Gateway consumer test still asserts the replaced batching behavior and fails on the reviewed head.

Priority: P1
Reviewed head: b0d044c68f5abe079dddadb6e060ffe7f1a69224

Before merge

  • [P2] Update the Gateway consumer test for partitioned wakes (P2) - When the sibling finishes while the other child is paused, the new selection correctly dispatches that sibling and clears its wake. This consumer test still requires both wakes to remain pending, no dispatch before resumption, and one combined final dispatch. The exact-head CI failure reports the resulting undefined wake in expectSharedRequesterCohort. Update this scenario to assert the early sibling delivery, preservation and replacement of the paused child's remaining obligation, and a second delivery containing only the resumed child's result; retain its persistence and SQLite-boundary assertions.

Findings

  • [P2] [P2] Update the Gateway consumer test for partitioned wakes — src/gateway/server-methods/sessions.send-yield-resume.test.ts:268-275
Agent review details

How this fits together

The subagent registry retains child completion obligations, and the settlement owner converts eligible results into requester mailbox inputs while coordinating follow-up replies and Goal continuation.

flowchart TD
  A[Child execution results] --> B[Registry completion obligations]
  B --> C[Ready partition selection]
  C --> D[Requester mailbox]
  D --> E[Requester continuation]
  C --> F[Unfinished sibling wakes]
  E --> G[Followup and Goal settlement]
Loading

Technical review

Best possible solution:

Keep the existing owners and partition implementation, and update the Gateway consumer regression to verify separate, nonduplicated deliveries across child resumption.

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

Current-main source exposes the blocking gate, and the PR supplies matching base/head Gateway observations plus two reported red-on-base, green-on-head registry regressions; no target code was executed during this review.

Is this the best way to solve the issue?

Partitioning at the existing settlement owner addresses the blocking cause, and the follow-up, Goal, lifecycle-failure, and pre-yield changes serve that same invariant without introducing another manager or storage format.

Full review comments:

  • [P2] [P2] Update the Gateway consumer test for partitioned wakes — src/gateway/server-methods/sessions.send-yield-resume.test.ts:268-275
    When the sibling finishes while the other child is paused, the new selection correctly dispatches that sibling and clears its wake. This consumer test still requires both wakes to remain pending, no dispatch before resumption, and one combined final dispatch. The exact-head CI failure reports the resulting undefined wake in expectSharedRequesterCohort. Update this scenario to assert the early sibling delivery, preservation and replacement of the paused child's remaining obligation, and a second delivery containing only the resumed child's result; retain its persistence and SQLite-boundary assertions.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Frozen-batch readiness and completion messaging changes intended behavior with a stated reason (fix(agents): prevent requester settle while child is still running #120601: Prevent an all-settled continuation while a frozen child is still running; the later message-wait repair retained that restriction for running siblings.)
  • Follow-up successor cohort matching keeps the original intent (b580769: Retain one same-process follow-up result across yielded successor executions; accepting the final subset preserves that single-reply contract under partitioning.)
  • Goal return settlement keeps the original intent (d79b0a4: Resume an admitted Goal after committed child settlement while preserving the existing continuation checks; removing completed partition members allows the final partition to retain this role.)
  • Requester-yield release scheduling keeps the original intent (ac7fd54: Keep watched child follow-ups owned through requester yield and receipt publication; scheduling an already-finished member after release preserves that ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/server-methods/sessions.send-yield-resume.test.ts --maxWorkers=1
  • pnpm check:test-types
  • git diff --check

What I checked:

PR surface

Source +22, Tests +221, Docs +7. Total +250 across 16 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 8 70 48 +22
Tests 6 246 25 +221
Docs 2 12 5 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 328 78 +250

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P1: The documented production incident leaves completed child reports unavailable to the yielded requester until unrelated work finishes or the user intervenes.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The documented production incident leaves completed child reports unavailable to the yielded requester until unrelated work finishes or the user intervenes.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 21, 2026, 11:42 AM ET / 16:42 UTC.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 349a7f324e510b26d97d2d05efcf2597e9ea00cf
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/subagents/requester-cron-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Nov 21, 2026
@obviyus
obviyus merged commit 09d956b into main Nov 21, 2026
139 checks passed
@obviyus
obviyus deleted the fix/requester-yield-partial-wake branch November 21, 2026 19:29
@obviyus

obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 09d956b.

  • Bug: a parent that yielded on several completion children was woken only once every child was ready. A sibling that kept running or exec-yielded hid finished results, for about 2 h in the incident.
  • Fix: each finished result now wakes the parent. Siblings that are still working keep their wake and wake the parent again when they finish. Each result is delivered once. Followup callers, Goal returns and automation authority continue on the last partition.
  • Proof: a regression test through the real wake path, red on base and green with the fix. Real-Gateway E2E with an exec-yielded sibling: the parent was woken 3 s after the first child finished (base: about 100 s later, only after the sibling ended). Local ClawSweeper review was clean and CI was green on the exact head.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…penclaw#203176)

## Problem

A requester that calls `sessions_yield` after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own `sessions_yield` while a background command runs, held every finished result back.

Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no `announce:requester-settle:…` run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were `terminal`/`ok` with `delivery.status: pending` and a pending `requesterSettleWake` (`batchRunIds` = all 3, `rearmGeneration: 1`). The third row was still `running`. The gate in `subagent-announce.requester-settle-wake.ts` returned `false` unless every frozen member passed `isRequesterSettleMemberReady`. openclaw#200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class.

## Change

Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same `rearmGeneration`, and wake the parent again when they finish. Each result is delivered once.

- **Settle wake:** removed the all-or-nothing gate and the message-wait exception (`isEndedSubagentMessageWait` is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake.
- **Wake message:** a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call `sessions_yield` to wait; otherwise act on the ready results without reporting the batch as finished.
- **Lifecycle failure path:** `offeredBatch` now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded.
- **Yield transfer:** when a child ended before the yield and a sibling is still running, `afterRelease` now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended.
- **Followup owners** (`sessions_send` wait-for-reply, `agent-step`, nested `agent-run-subagent`): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. `successor()` accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure.
- **Automation authority:** a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority.
- **Silent waits:** while siblings are still working, the parent may stay silent (`NO_REPLY`) and wait. Such a turn is not treated as a missing visible reply, so it is not retried.
- **Goal return:** an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once.
- `isRequesterSettleMemberReady` moved to `subagent-run-liveness.ts`, its only owner, and replaces the deleted message-wait predicate.
- Docs: `tools/subagents/announce.md` and `concepts/subagent-yield-handoff.md`.

Product decisions, under the rules "no stranded user" and "no false done":
- A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings.
- A followup caller gets one reply, after all results are in. The session itself is still woken for each result.

## Evidence

**Regression test** (`subagent-registry.requester-wake.e2e.test.ts`, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it.
- Base `60d77af57e31`: both cases red (`expected [] to have a length of 1`: no wake).
- Head: both cases green.

**Owner tests:** cron authority (`requester-cron-authority.test.ts`: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (`subagent-announce.requester-settle-followup.test.ts`: early partition runs with no followup successor, last partition carries it). Goal partition (`goal-continuation.test.ts`: early partition does not resume the Goal, last partition resumes it once).

**Updated tests that asserted the all-at-once rule:** `requester-settle-cross-turn` (paused member), `subagent-control.worker` progress card (one wake per result; the card retires once), `requester-wake-settlement` (stopped child).

**Real-Gateway E2E**, incident shape. Scratch `ocx src` Gateway under `env -i`, OpenAI `gpt-5.5` on the OpenClaw runtime. Parent spawns `alpha` (replies at once) and `beta` (`exec` with `background: true` running `sleep 90`, then `sessions_yield`), then yields.

| | alpha ended | first parent wake | beta yielded | beta ended | second parent wake |
|---|---|---|---|---|---|
| base | 19:47:10 | **19:48:53** (one combined run, after beta) | 19:47:13 | 19:48:50 | none |
| head | 19:40:08 | **19:40:11** (`announce:requester-settle:…:<alpha>:yield-1`) | 19:40:12 | 19:41:55 | 19:41:59 (`…:<beta>:yield-1`) |

The parent's replies on head were `alpha: ALPHA-RESULT-7`, then `alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9`. The live Peanutto launchd pid and `openclaw.json` hash did not change.

**Live sibling suites** (`subagent-yield-pause`, `subagent-followup-yield`, `subagent-yield-resume`, real OpenAI `gpt-5.5`): the same tests fail on base `60d77af57e31` and on this branch, with the same assertions (missing `completion.resultText` after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (`test/gateway-*-restart*.e2e.test.ts`) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions).

**Gates:** `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on the changed files. Every test file in `src/agents/subagents` and `goal-continuation.test.ts` was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base.

## Size

Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of `batchRunIds`, `requesterYieldBatch`, the frozen branch and `selectConnectedSettledSubagentWave` found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code.

## Accepted edge cases

- If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today.
- A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion.

## Merge danger

- **Two-way door.** No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran.
- **Blast radius:** requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…203102)

(cherry picked from commit 2e1d67c)

Release adaptation: Stable merged read owner retained; terminal-delivery filtering moved to its query; main-only benchmark and helper omitted.

Companion audit: #203176 and #203222 selected in lane; #204260, #204178 and #203839 not selected (not a prerequisite).

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…203176)

## Problem

A requester that calls `sessions_yield` after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own `sessions_yield` while a background command runs, held every finished result back.

Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no `announce:requester-settle:…` run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were `terminal`/`ok` with `delivery.status: pending` and a pending `requesterSettleWake` (`batchRunIds` = all 3, `rearmGeneration: 1`). The third row was still `running`. The gate in `subagent-announce.requester-settle-wake.ts` returned `false` unless every frozen member passed `isRequesterSettleMemberReady`. #200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class.

## Change

Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same `rearmGeneration`, and wake the parent again when they finish. Each result is delivered once.

- **Settle wake:** removed the all-or-nothing gate and the message-wait exception (`isEndedSubagentMessageWait` is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake.
- **Wake message:** a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call `sessions_yield` to wait; otherwise act on the ready results without reporting the batch as finished.
- **Lifecycle failure path:** `offeredBatch` now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded.
- **Yield transfer:** when a child ended before the yield and a sibling is still running, `afterRelease` now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended.
- **Followup owners** (`sessions_send` wait-for-reply, `agent-step`, nested `agent-run-subagent`): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. `successor()` accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure.
- **Automation authority:** a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority.
- **Silent waits:** while siblings are still working, the parent may stay silent (`NO_REPLY`) and wait. Such a turn is not treated as a missing visible reply, so it is not retried.
- **Goal return:** an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once.
- `isRequesterSettleMemberReady` moved to `subagent-run-liveness.ts`, its only owner, and replaces the deleted message-wait predicate.
- Docs: `tools/subagents/announce.md` and `concepts/subagent-yield-handoff.md`.

Product decisions, under the rules "no stranded user" and "no false done":
- A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings.
- A followup caller gets one reply, after all results are in. The session itself is still woken for each result.

## Evidence

**Regression test** (`subagent-registry.requester-wake.e2e.test.ts`, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it.
- Base `eb7ca3d33375`: both cases red (`expected [] to have a length of 1`: no wake).
- Head: both cases green.

**Owner tests:** cron authority (`requester-cron-authority.test.ts`: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (`subagent-announce.requester-settle-followup.test.ts`: early partition runs with no followup successor, last partition carries it). Goal partition (`goal-continuation.test.ts`: early partition does not resume the Goal, last partition resumes it once).

**Updated tests that asserted the all-at-once rule:** `requester-settle-cross-turn` (paused member), `subagent-control.worker` progress card (one wake per result; the card retires once), `requester-wake-settlement` (stopped child).

**Real-Gateway E2E**, incident shape. Scratch `ocx src` Gateway under `env -i`, OpenAI `gpt-5.5` on the OpenClaw runtime. Parent spawns `alpha` (replies at once) and `beta` (`exec` with `background: true` running `sleep 90`, then `sessions_yield`), then yields.

| | alpha ended | first parent wake | beta yielded | beta ended | second parent wake |
|---|---|---|---|---|---|
| base | 19:47:10 | **19:48:53** (one combined run, after beta) | 19:47:13 | 19:48:50 | none |
| head | 19:40:08 | **19:40:11** (`announce:requester-settle:…:<alpha>:yield-1`) | 19:40:12 | 19:41:55 | 19:41:59 (`…:<beta>:yield-1`) |

The parent's replies on head were `alpha: ALPHA-RESULT-7`, then `alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9`. The live Peanutto launchd pid and `openclaw.json` hash did not change.

**Live sibling suites** (`subagent-yield-pause`, `subagent-followup-yield`, `subagent-yield-resume`, real OpenAI `gpt-5.5`): the same tests fail on base `eb7ca3d33375` and on this branch, with the same assertions (missing `completion.resultText` after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (`test/gateway-*-restart*.e2e.test.ts`) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions).

**Gates:** `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on the changed files. Every test file in `src/agents/subagents` and `goal-continuation.test.ts` was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base.

## Size

Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of `batchRunIds`, `requesterYieldBatch`, the frozen branch and `selectConnectedSettledSubagentWave` found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code.

## Accepted edge cases

- If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today.
- A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion.

## Merge danger

- **Two-way door.** No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran.
- **Blast radius:** requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 09d956b)

Release adaptation: Kept stable QA Gateway fixture lifecycle; filtered intentionally silent partial-result wakes.

Companion audit: #203222 selected. #204249, #204069, #204048, #203892, #202513, #198960 not applicable (refactors/test cleanup); #204260, #204178, #204098, #204089, #203839, #203271 missing in lane and not prerequisites.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot added a commit that referenced this pull request Nov 24, 2026
…203176)

Baseline adaptation: Implement stable requester/cron partition custody, exact retry and settlement in existing payload; delegated Goal-return prerequisite is absent and excluded.

(cherry picked from commit 09d956b)

Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit b3f8e0a7abcb4d09eca90dd4c21bc1b1ac2892bb)
(cherry picked from commit f66d0cc36e8169d78d45e376404b8059736b1e32)
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Preserve the existing requester restart reason in announce classification so unconsumed completed results remain pending for startup custody. Existing consumption receipts prevent replay; permanent refusals, explicit cancellation, and ambiguous sends retain their policies.

(cherry picked from commit b8b06c4)

Follow-ups: fca5133 fix: preserve child completion inputs across Gateway restarts (#208367) [not selected for this narrow backport]; b7967b2 fix: deliver a saved child answer after a Gateway crash (#207706) [not selected for this narrow backport]; 17e2ec9 fix: tell the user when a finished subagent's report can't start in their chat (#207194) [not selected for this narrow backport]; 811f999 refactor(subagents): centralize completion delivery decisions (#206383) [not selected for this narrow backport]; 50a6774 fix: retain channel requester when child completion resumes parent [separately ordered lane row]; d2699a8 chore: carry and enforce participant limits on admitted runs (#204847) [not selected for this narrow backport]; 57dd84b fix(agents): settle every undelivered child completion into history; drop delivery dispositions (#204260) [separately ordered lane row]; cded11f fix(agents): deliver a child's end state as parent history, not a turn obligation (#204178) [not selected for this narrow backport]; 92e92d7 fix: preserve restarted child results and gateway test ownership (#203839) [not selected for this narrow backport]; 09d956b fix(subagents): wake a yielded requester for each ready child result (#203176) [not selected for this narrow backport]; 9f35510 fix: retain child results behind live requester turns (#203198) [separately ordered lane row]; c23cd7f fix: preserve private child results during restart (#203156) [separately ordered lane row]

Release adaptation: Keep stable requester fixture setup and insert the two consumed/unconsumed restart cases without moving its existing lost-yield test.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
(cherry picked from commit 9f35510)

Companion audit: #203222 fixes yield settlement after cleanup, #203176 wake scheduling, #203839 restart fixtures, #208469 newer perf harness; remaining same-path commits change orchestration or history delivery and are not inputs to stable expiry ownership.

Co-authored-by: RomneyDa <[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 docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant