Skip to content

fix: deliver finished child results while siblings wait for messages - #200967

Merged
steipete merged 1 commit into
mainfrom
codex/sweeper-owed-settle-batches
Nov 18, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sweeper-owed-settle-batches

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Finished subagent results can remain pending indefinitely when a yielded batch also contains children paused to wait for a message. Restart recovery restores the owed results, but the batch never attempts delivery.

User Impact

Ready results can reach the requester or settle through the existing visible permanent-failure path. Message-waiting children remain resumable and retain their future completion; saved child results remain readable. No expiry, schema, or protocol changes.

Why This Change Was Made

The frozen-batch gate in src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:165 on the base required every surviving member to pass isRequesterSettleMemberReady, which always rejects sessions_yield. An ended message wait therefore blocked every ready sibling without a dispatch attempt. The killed member already follows the intentional non-delivery path.

Keep the existing dispatch owner and select the ready members once every other member is an ended message wait. The lifecycle failure fallback (subagent-registry-lifecycle-wake.ts:338) must exclude those waits too, so a preparation failure cannot consume their future wakes. Both paths share the liveness owner's predicate. Running children and pauses waiting on descendants still hold the batch. Overlapping cohorts retain the existing changed-batch permanent-failure handling and saved result payloads.

The change was rebased onto main after #200924 merged before editing the shared dispatch file. The simplification pass retained the two existing settlement boundaries and one integration regression; no new owner, timer, or policy was added. Production delta: +29/-13 lines; regression: +213 lines; docs: +4/-2 lines.

Evidence

The regression models 89 restored rows, 68 distinct members in overlapping 33-member batches, the success/error/no-outcome mix, prior deliveries and unavailable sinks, nine message waits, and a killed child. It exercises real SQLite persistence/restore, restart custody, the sweeper, lifecycle dispatch, descendant checks, and durable settlement, with fixture session I/O and the external delivery sink replaced.

Red on base 38439333e1f49667c8fc7fe572a10637f36af211: the first sweep fails with expected "vi.fn()" to be called at least once; the owed batch never reaches delivery. The same regression is green with the fix: ready rows clear their wakes through delivery or recorded permanent failure, saved results remain readable, and all nine message waits keep their wakes.

  • 211 tests passed across all 18 sweeper/settle and affected lifecycle test files (157.72s wrapper).
  • Targeted agents/sessions typecheck, type-aware lint on the four TypeScript files, format on all five files, and git diff --check passed.
  • Codex autoreview of the full local candidate against the base above, now committed as 3a57f8426e625372c2d53fb3508e1182fb718297: scoped-clean through P2, no accepted/actionable findings. Supporting owner code was supplied; the reviewer did not execute tests.

Reproduction: node scripts/run-vitest.mjs src/agents/subagents/registry/subagent-registry-sweeper-owed-batches.test.ts --maxWorkers=1. PR CI supplies broad proof.

@clawsweeper

clawsweeper Bot commented Nov 18, 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 18, 2026
@steipete
steipete marked this pull request as ready for review November 18, 2026 03:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T03:38:25.369399Z 3a57f84 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a57f8426e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const admittedBatch = (pauseNotice ? [runId] : (admittedWake?.batchRunIds ?? [runId])).flatMap(
(id) => {
const member = params.runs.get(id);
return member && (pauseNotice || !isEndedSubagentMessageWait(member)) ? [member] : [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow failure settlement to persist the reduced batch

When preparation fails before onBeforeDispatch rewrites the ready members' batchRunIds, this filter excludes message waits from admittedBatch but leaves them in the persisted frozen cohort. The error handler then calls completeBatch(admittedBatch, ...), and prepareRequesterBatch in subagent-completion-mutation.kernel.ts rejects that settlement because an omitted member still has a wake in the same generation. Consequently, the intended permanent-failure path only logs a persistence rejection and leaves the ready results pending indefinitely. Update the storage settlement contract alongside this selection change so it can settle offered results without consuming the waits.

AGENTS.md reference: AGENTS.md:L55-L55

Useful? React with 👍 / 👎.

params.onDescendantsPending?.();
return false;
}
settledBatch = settledBatch.filter(isRequesterSettleMemberReady);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Talk final attachments when splitting a yielded cohort

For a Talk consult that yields a batch containing both ready results and message waits, the final attachment is promoted with the full frozen batchRunIds in subagent-registry-requester-yield.ts. After this filter, both transferRequesterFinalAttachment and finalizeRequesterFinalAttachment receive only the ready subset, but getCurrentAttachment in requester-final-attachment.ts requires exact batch membership and therefore rejects both calls. The continuation can finish successfully without appending its answer to the Talk requester, and retiring the ready rows prevents a later completion from matching the original attachment either. Migrate the attachment owner to the partial-cohort behavior rather than changing only the dispatch selection.

AGENTS.md reference: AGENTS.md:L55-L55

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR delivers finished child results while message-waiting siblings retain their future completion wakes.

Example: A requester yields for child-a and child-b; child-a finishes while child-b waits for a message.

  • Before: Child-a's result remains pending because child-b prevents the frozen batch from settling.
  • After: Child-a's result is offered to the requester while child-b remains resumable.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The useful regression supports the core diagnosis, but complete-cohort consumers remain broken and shipped-entry-point proof is absent; persisted requesterSettleWake.batchRunIds behavior also lacks a latest-stable upgrade demonstration.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 4 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A requester can remain idle indefinitely with a completed child's result while another child waits for information from that requester.
Reason: The deadlock has concrete workflow impact, and maintainer authorship establishes direction for the message-wait exception.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open: this maintainer-directed PR addresses a current delivery deadlock, but selecting partial cohorts leaves four existing settlement and continuation contracts inconsistent.

Priority: P1
Reviewed head: 3a57f8426e625372c2d53fb3508e1182fb718297

Before merge

  • Allow failure settlement to commit the reduced cohort (P2) - For a frozen batch [ready, waiting], a preparation failure before onBeforeDispatch now sends only [ready] to completeBatch while its persisted batchRunIds still contain waiting. prepareRequesterBatch in subagent-completion-mutation.kernel.ts:303-314 rejects that outcome because waiting retains a wake in the same generation. The lifecycle catch then logs a persistence rejection and leaves the ready result pending instead of recording the promised permanent failure. Update the durable settlement contract alongside this filter so offered results can settle without consuming the message wait.
  • Preserve Talk final attachments across partial delivery (P2) - A Talk consult that yields [ready, waiting] promotes its final attachment using both run IDs in subagent-registry-requester-yield.ts. This filter makes transferRequesterFinalAttachment and createRequesterSettleBatchCompletion pass only [ready], but requester-final-attachment.ts:68-74 requires exact membership. Both calls therefore miss the attachment, so a successful requester continuation can finish without appending its final answer to Talk. Coordinate the attachment owner's cohort transition with the selected delivery wave.
  • Adapt follow-up successors before selecting a partial cohort (P2) - When a sessions_send follow-up target spawns two children and yields, promoteFollowupYield retains both children in SessionFollowupCompletion. If one child finishes and the other waits for a message, getFollowupForCohort still returns that owner for the ready subset, but followup.successor(settledBatch, ...) throws because session-followup-completion.ts:174 requires the original cohort length. This happens before delivery and prevents the follow-up from resuming. Teach the existing follow-up owner how the partial wave retains and transfers its result obligation.
  • Retain captured management authority for the ready wave (P2) - For an authorized requester that yields [ready, waiting], captureRequesterContinuationCaller now receives [ready] while requester-cron-authority.ts retains authority for both members. withRequesterCronAuthority:451-455 rejects that membership mismatch and runs without its captured dispatch scope; Gateway admission consequently cannot consume the original cron-management entitlement. The resumed turn loses capabilities needed to finish an authorized automation-management request. Transfer the existing authority to valid partial waves without broadening the original requester, generation, or permissions.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Allow failure settlement to commit the reduced cohort — src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts:340-343
  • [P2] Preserve Talk final attachments across partial delivery — src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:177
  • [P2] Adapt follow-up successors before selecting a partial cohort — src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:177

Tests

  • Missing end-to-end proof: Supply redacted Gateway output showing automatic ready-sibling delivery, continuation and later completion of the waiting child, plus a latest-stable upgrade preserving pending cohorts and saved results.
Agent review details

How this fits together

The subagent registry retains child execution and delivery state; lifecycle scheduling selects completion cohorts and passes them through Gateway admission into requester turns.

flowchart TD
  A[Child completion or message wait] --> B[Persistent subagent registry]
  B --> C[Lifecycle wake scheduler]
  C --> D[Ready cohort selection]
  D --> E[Requester mailbox and Gateway]
  E --> F[Requester continuation]
  F --> G[Durable settlement and final attachment]
Loading

Technical review

Best possible solution:

Coordinate partial-cohort handling across the existing settlement, follow-up, authority, and final-attachment owners while preserving paused children’s eventual completions.

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

Current-main source establishes the two-child deadlock, and the PR reports a regression failing on its pinned base and passing on its head; this read-only review executed no target code.

Is this the best way to solve the issue?

The shared predicate is appropriately small, but filtering dispatch membership alone is incomplete because downstream owners still enforce the original complete cohort.

Full review comments:

  • [P2] Allow failure settlement to commit the reduced cohort — src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts:340-343
    For a frozen batch [ready, waiting], a preparation failure before onBeforeDispatch now sends only [ready] to completeBatch while its persisted batchRunIds still contain waiting. prepareRequesterBatch in subagent-completion-mutation.kernel.ts:303-314 rejects that outcome because waiting retains a wake in the same generation. The lifecycle catch then logs a persistence rejection and leaves the ready result pending instead of recording the promised permanent failure. Update the durable settlement contract alongside this filter so offered results can settle without consuming the message wait.
    Confidence: 0.99
  • [P2] Preserve Talk final attachments across partial delivery — src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:177
    A Talk consult that yields [ready, waiting] promotes its final attachment using both run IDs in subagent-registry-requester-yield.ts. This filter makes transferRequesterFinalAttachment and createRequesterSettleBatchCompletion pass only [ready], but requester-final-attachment.ts:68-74 requires exact membership. Both calls therefore miss the attachment, so a successful requester continuation can finish without appending its final answer to Talk. Coordinate the attachment owner's cohort transition with the selected delivery wave.
    Confidence: 0.99
  • [P2] Adapt follow-up successors before selecting a partial cohort — src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:177
    When a sessions_send follow-up target spawns two children and yields, promoteFollowupYield retains both children in SessionFollowupCompletion. If one child finishes and the other waits for a message, getFollowupForCohort still returns that owner for the ready subset, but followup.successor(settledBatch, ...) throws because session-followup-completion.ts:174 requires the original cohort length. This happens before delivery and prevents the follow-up from resuming. Teach the existing follow-up owner how the partial wave retains and transfers its result obligation.
    Confidence: 0.99
  • [P2] Retain captured management authority for the ready wave — src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:177
    For an authorized requester that yields [ready, waiting], captureRequesterContinuationCaller now receives [ready] while requester-cron-authority.ts retains authority for both members. withRequesterCronAuthority:451-455 rejects that membership mismatch and runs without its captured dispatch scope; Gateway admission consequently cannot consume the original cron-management entitlement. The resumed turn loses capabilities needed to finish an authorized automation-management request. Transfer the existing authority to valid partial waves without broadening the original requester, generation, or permissions.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • node scripts/run-vitest.mjs src/agents/subagents/registry/subagent-registry-sweeper-owed-batches.test.ts src/agents/subagents/registry/subagent-registry-lifecycle-wake.retry.test.ts src/agents/subagents/announce/subagent-announce.requester-settle-dispatch.test.ts src/agents/subagents/completion/session-followup-completion.test.ts src/agents/subagents/requester-cron-authority.test.ts src/agents/subagents/requester-final-attachment.test.ts --maxWorkers=1
  • pnpm tsgo:core
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4881c9b adds src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts:193 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4881c9bbda01; files: src/agents/subagents/announce/subagent-announce.requester-settle-wake.ts)
  • Ayaan Zaidi: Raw commit d919bfb adds docs/tools/subagents/announce.md:39 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d919bfbb4d89; files: docs/tools/subagents/announce.md)
  • Vito Cappello: Raw commit 7d12927 adds src/agents/subagent-announce.requester-settle-wake.ts:274 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 7d129279a44e; files: src/agents/subagent-announce.requester-settle-wake.ts)

PR surface

Source +16, Tests +213, Docs +2. Total +231 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 29 13 +16
Tests 1 213 0 +213
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 246 15 +231

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.

Review metrics

Metric Value Why it matters
Production versus regression code Production +29/-13; tests +213/-0 The regression's persistence and restart composition protects a distinct failure, and the shared predicate serves two production callers.

Labels

Label changes:

  • add P1: The underlying deadlock silently strands completed child results and prevents delegated workflows from continuing.
  • add merge-risk: 🚨 message-delivery: Partial cohorts can fail durable settlement, lose Talk final attachment delivery, or be rejected by the follow-up continuation owner.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The underlying deadlock silently strands completed child results and prevents delegated workflows from continuing.
  • merge-risk: 🚨 message-delivery: Partial cohorts can fail durable settlement, lose Talk final attachment delivery, or be rejected by the follow-up continuation owner.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 17, 2026, 10:52 PM ET / November 18, 2026, 03:52 UTC.

@steipete
steipete merged commit bb28b72 into main Nov 18, 2026
207 of 210 checks passed
@steipete
steipete deleted the codex/sweeper-owed-settle-batches branch November 18, 2026 04:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc pushed a commit that referenced this pull request Nov 18, 2026
Apply hosted file-count bounds during weighted balancing instead of slicing already-balanced stripes into stranded tails. Preserve the 77-row hourly nondist cap, runner and worker limits, time budgets, and complete selected inventory.

The scheduled manifest reproduced 78 > 77 after inventory growth in #200967. Expanded GitHub/hybrid regressions and all 174 focused planner tests pass; Codex autoreview is clean. check:changed passes except unrelated main unused exports attributed to #200533, #193550, #198455, and #200817.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
…1002)

Apply hosted file-count bounds during weighted balancing instead of slicing already-balanced stripes into stranded tails. Preserve the 77-row hourly nondist cap, runner and worker limits, time budgets, and complete selected inventory.

The scheduled manifest reproduced 78 > 77 after inventory growth in openclaw#200967. Expanded GitHub/hybrid regressions and all 174 focused planner tests pass; Codex autoreview is clean. check:changed passes except unrelated main unused exports attributed to openclaw#200533, openclaw#193550, openclaw#198455, and openclaw#200817.
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Apply hosted file-count bounds during weighted balancing instead of slicing already-balanced stripes into stranded tails. Preserve the 77-row hourly nondist cap, runner and worker limits, time budgets, and complete selected inventory.

The scheduled manifest reproduced 78 > 77 after inventory growth in #200967. Expanded GitHub/hybrid regressions and all 174 focused planner tests pass; Codex autoreview is clean. check:changed passes except unrelated main unused exports attributed to #200533, #193550, #198455, and #200817.

Backport to beta.2 preparation; exact reviewed adapted patch. Focused parent proof: 35 tests; nine-file type-aware lint; 18-file format. Tooling typecheck retains the same two pre-existing cron UI errors as baseline. No release qualification.

(cherry picked from commit af50b8e)
(cherry picked from commit c7ccc5e)
Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
obviyus added a commit that referenced this pull request Nov 21, 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]>
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]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…penclaw#200967)

Release adaptation: Split reviewed partition cluster: ended-message waits retain custody while ready siblings settle; exact reviewed owed-batch regression retained.

(cherry picked from commit bb28b72)

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

Copy link
Copy Markdown

Hello, what are your suggestions for me to genuinely show you the asset I can be? I mean that positive btw, I have and will continue to give my best when I have access or (allowed) to participate. Highly restrictive. I apologize again for behaviors. Was told outcomes yesterday all fake, my goals still are working, learning, and moving forward with positive adjustment hope.

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]>
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 merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

2 participants