Skip to content

fix(subagents): bound settle-wake deferrals to prevent indefinite parking - #124408

Merged
obviyus merged 7 commits into
openclaw:mainfrom
synthalorian:fix/issue-124343-settle-wake-deferral
Aug 27, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
synthalorian:fix/issue-124343-settle-wake-deferral

Conversation

@synthalorian

@synthalorian synthalorian commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A requester can yield after spawning a subagent. If that subagent finishes while one of its descendants stays active, the requester settle wake can defer forever. The user gets no final result and the task records no terminal delivery reason.

Root Cause

The durable requester settle-wake batch had no deferral bound. The submitted cap wrote another pending state instead of using the lifecycle completion owner. A late descendant wake could also replace the already blocked parent run and overwrite its delivery result.

Fix

  • Persist a bounded deferral count on the existing settle-wake batch.
  • Route the cap through the existing completion owner with one failed delivery reason.
  • Close later descendant delivery while descendants drain, then finish cleanup without a new requester wake.
  • Abort an accepted descendant wake if delivery ownership closes before replacement.

User Impact

The requester now gets a bounded, visible blocked task result instead of waiting forever. Late descendant completion cannot overwrite or duplicate that result.

Evidence

Live red on current main

On 5090935817e3, a real Telegram requester spawned a subagent and yielded. The subagent finished while its non-announcing descendant stayed active. After ten settle intervals, /tasks still showed pending delivery with no error or terminal outcome. The durable settle wake remained pending with another future deadline. Releasing the descendant later proved the held work was real.

Live green on final head

Hosted CI built merge candidate 5593dc27a9b2 from current main 608e365ce485 with exact PR head 0b5be69dc866 as its second parent. The same Telegram flow showed this result after ten settle intervals:

Tasks
Current session: 0 active · 1 total

1. settle-wake-parent-child
Subagent · blocked
requester settle wake deferred too many times

The durable task recorded failed delivery, terminal outcome blocked, and one error reason. Requester settle-wake state was absent. After the descendant was released, the task stayed failed and blocked, cleanup completed, and no replacement wake or duplicate requester result appeared.

Regression tests

node scripts/run-vitest.mjs src/agents/subagents/announce/subagent-announce.requester-settle-wake.test.ts src/agents/subagents/registry/subagent-registry-lifecycle.test.ts src/agents/subagents/registry/subagent-registry-requester-yield.test.ts src/agents/subagents/registry/subagent-registry.store.sqlite.test.ts
Test Files 4 passed
Tests 222 passed

OPENCLAW_E2E_SKIP_BUILD=1 node scripts/run-vitest.mjs src/agents/subagents/announce/subagent-announce.format.e2e.test.ts
Test Files 1 passed
Tests 85 passed

Fixes #124343

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Aug 16, 2026
@clawsweeper clawsweeper Bot added 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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 27, 2026, 12:49 PM ET / 16:49 UTC.

ClawSweeper review

What this changes

The PR adds a persisted cap to requester settle-wake deferrals, records failure when the cap is reached, and prevents stale descendant cleanup from re-opening closed delivery.

Regression provenance

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

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep open: the PR remains the active candidate fix for the linked completed-subagent delivery bug, but it still needs after-fix production-boundary behavior proof before merge.

Priority: P1
Reviewed head: 8703282d0c59ee1edff450fa7359edff2ecf4cd3

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has focused owner-boundary coverage and no confirmed correctness defect, but real behavior proof is still missing.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Only focused mocked test output is provided; add a redacted after-fix gateway or production-boundary trace showing the capped path reaches its durable blocked outcome. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Only focused mocked test output is provided; add a redacted after-fix gateway or production-boundary trace showing the capped path reaches its durable blocked outcome. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Introduced cap and terminal outcome: The PR increments persisted deferrals and completes the batch with a durable failed delivery at the tenth deferral.
Lifecycle owner records the blocked result: The wake lifecycle changes pending required completions to failed, persists the error, and marks the task delivery blocked before clearing the settle-wake state.
Current main still lacks the cap: The fetched current-main version of the settle-wake module has retry limits but no deferral limit or deferral counter, so the PR is not obsolete.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

$ node scripts/run-node.mjs --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 98.02 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ fun
… output truncated …
*             System tools (events, heartbeat, presence)
  tasks *              Inspect durable background tasks and TaskFlow state
  terminal             Open a local terminal UI (alias for tui --local)
  transcripts *        Inspect stored transcripts
  tui                  Open a terminal UI connected to the Gateway
  uninstall            Uninstall the gateway service + local data (CLI remains)
  update *             Update OpenClaw and inspect update channel status
  users *              Manage durable user profiles and email aliases
  webhooks *           Webhook helpers and integrations
  worker               Run the restricted cloud worker runtime
  worktrees *          Create, inspect, restore, and clean up managed worktrees

Examples:
  openclaw onboard
    Run guided setup for a local Gateway, workspace, auth, and channels.
  openclaw setup
    Create the baseline config, workspace, and session folders.
  openclaw configure
    Change models, Gateway, channels, plugins, skills, and health checks.
  openclaw status
    Check Gateway, channel, model, and recent-session status.
  openclaw doctor --fix
    Repair common config, service, plugin, and channel problems.
  openclaw channels add
    Add or update a chat channel account with guided prompts.
  openclaw channels status
    See connected messaging accounts and login state.
  openclaw --dev gateway
    Run a dev Gateway (isolated state/config) on ws://127.0.0.1:19001.
  openclaw gateway run --force
    Start the Gateway and replace anything bound to its port.
  openclaw models status
    Show model/provider auth health before running agents.
  openclaw plugins list
    Inspect enabled, disabled, and installed plugins.
  openclaw agent --to +15555550123 --message "Run summary" --deliver
    Run one agent turn through the Gateway and optionally deliver the reply.
  openclaw message send --channel telegram --target @mychat --message "Hi"
    Send via your Telegram bot.

Docs: docs.openclaw.ai/cli

Assertions:

  • PASS expect_output: Usage: openclaw [options] [command]

How this fits together

Subagent completion cleanup passes completion results to the requester through a durable settle-wake batch. This path either wakes the requester after descendants settle or records a terminal delivery outcome for the task lifecycle.

flowchart LR
  A[Subagent completes] --> B[Completion cleanup]
  B --> C[Requester settle-wake batch]
  C --> D{Descendants pending?}
  D -->|yes| E[Persist deferred wake]
  E --> F{Deferral cap reached?}
  F -->|yes| G[Record blocked delivery]
  F -->|no| C
  D -->|no| H[Wake requester]
  H --> I[Visible final or durable outcome]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Only focused mocked test output is provided; add a redacted after-fix gateway or production-boundary trace showing the capped path reaches its durable blocked outcome. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Only mocked/focused test output is supplied; no after-fix gateway or production-boundary trace shows the capped path reaching the recorded blocked outcome without leaving active descendants stranded.
  • Resolve merge risk (P1) - The bug fix adds 47 production lines across delivery and cleanup ownership; the state transition needs end-to-end evidence because it changes a completed task from indefinitely pending to durably blocked.
  • Complete next step (P2) - This open implementation PR already owns the concrete repair; the remaining merge blocker is contributor-supplied real behavior proof, not an automated code fix.
Agent review details

Security

None.

PR surface

Source +47, Tests +89. Total +136 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 52 5 +47
Tests 3 125 36 +89
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 177 41 +136

Review metrics

Metric Value Why it matters
Production vs test delta production +47/-5; tests +125/-36 The production increase carries terminal delivery closure through cleanup and wake ownership, so the new durable outcome needs boundary-level proof.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #124343
Summary: This PR is the open candidate fix for the canonical yielded settle-wake delivery report.

Members:

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

Merge-risk options

Maintainer options:

  1. Add capped-path runtime proof (recommended)
    Show a redacted after-fix gateway or production-boundary trace where repeated deferral reaches a recorded blocked delivery outcome and later descendant cleanup completes.

Technical review

Best possible solution:

Keep the cap in the settle-wake lifecycle owner and add a redacted after-fix gateway or production-boundary trace showing the capped batch becomes durably blocked while descendants can still settle normally.

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

Yes for the pre-fix defect: the linked report supplies a live gateway sequence, and current main has an unbounded defer path. The after-fix outcome has not yet been demonstrated through the production boundary.

Is this the best way to solve the issue?

Yes, as an acceptable lifecycle-owner mitigation: it replaces an indefinitely pending handoff with a recorded terminal failure. A boundary trace is still needed to verify that the complete cleanup sequence preserves this invariant.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against aa0647d06d27.

Labels

Label justifications:

  • P1: The affected path can silently withhold a completed subagent result from its requester until the cap records a terminal outcome.
  • merge-risk: 🚨 message-delivery: The PR changes whether required completion output is delivered or durably marked failed.
  • merge-risk: 🚨 session-state: The PR adds and clears persisted settle-wake and cleanup state across descendant completion.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only focused mocked test output is provided; add a redacted after-fix gateway or production-boundary trace showing the capped path reaches its durable blocked outcome. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • obviyus: Recent PR-head commits implement the delivery-closure and terminal settle-wake behavior. (role: recent lifecycle contributor; confidence: high; commits: 6835e9462e59, 95ed0cd8faa5, 8703282d0c59; files: src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts, src/agents/subagents/registry/subagent-registry-lifecycle-announce-cleanup.ts)
  • steipete: History and blame show the pre-existing wake lifecycle and completion-state handling originate in this area of current main. (role: prior lifecycle contributor; confidence: medium; commits: e66d7c5cac65; files: src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts, src/agents/subagents/registry/subagent-registry-lifecycle-announce-cleanup.ts)

Rank-up moves

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

  • Add a redacted after-fix gateway or production-boundary trace for the capped deferred-wake path.
  • Show that the recorded failure does not prevent later descendant cleanup from reaching its own terminal state.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-17T02:35:57.241Z sha 960cd1b4f340b424481fff6130269862e9ef6f2f :: needs real behavior proof before merge. :: [P1] Preserve the deferral count across batch reconstruction | [P1] Complete the batch when the deferral cap is reached
  • reviewed 2026-08-19T06:19:51.313Z sha 960cd1b4f340b424481fff6130269862e9ef6f2f :: needs real behavior proof before merge. :: [P1] Carry deferralCount through shared batch reconstruction | [P1] Complete the batch when the deferral cap is reached
  • reviewed 2026-08-21T19:42:01.330Z sha 960cd1b4f340b424481fff6130269862e9ef6f2f :: needs real behavior proof before merge. :: [P1] Preserve the counter when rebuilding a shared batch | [P1] Finish or hand off the batch at the deferral limit
  • reviewed 2026-08-21T20:27:40.080Z sha 960cd1b4f340b424481fff6130269862e9ef6f2f :: needs real behavior proof before merge. :: [P1] Carry the deferral count through shared batch state | [P1] Complete the batch at the deferral limit
  • reviewed 2026-08-22T17:55:22.745Z sha e679c7a :: needs real behavior proof before merge. :: [P1] Complete the batch at the deferral limit
  • reviewed 2026-08-22T18:57:33.086Z sha e679c7a :: needs real behavior proof before merge. :: [P1] Terminalize the batch when the deferral limit is reached
  • reviewed 2026-08-22T19:32:34.005Z sha e679c7a :: needs real behavior proof before merge. :: [P1] Terminalize the batch at the deferral cap
  • reviewed 2026-08-24T17:39:58.348Z sha d84302b :: needs real behavior proof before merge. :: [P1] Terminalize the batch at the deferral cap

@synthalorian
synthalorian force-pushed the fix/issue-124343-settle-wake-deferral branch from 7686712 to 8e1990e Compare August 16, 2026 20:33
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 16, 2026
@synthalorian
synthalorian force-pushed the fix/issue-124343-settle-wake-deferral branch from 4a099ad to 960cd1b Compare August 17, 2026 02:30
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper-recovery-stuck and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper-recovery-stuck labels Aug 17, 2026
…king

When a requester yields after spawning subagents, the settle-wake batch
can be deferred indefinitely if new work keeps getting spawned. This
leaves completed subagents with no delivery, no retry, and no recorded
reason.

Add a maximum deferral count (10) to the settle-wake batch. When reached,
the batch completes with a recorded error instead of parking forever.

Fixes openclaw#124343
readSharedBatchState omitted deferralCount, so the deferral bound was
unreachable — every batch reconstruction reset the counter to undefined.
Use Math.max across all batch states to preserve the highest deferral
count, matching the pattern used for attemptCount.

Addresses ClawSweeper review finding P1 on PR openclaw#124408.
@synthalorian
synthalorian force-pushed the fix/issue-124343-settle-wake-deferral branch from 960cd1b to e679c7a Compare August 22, 2026 17:48
@synthalorian

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 22, 2026
@obviyus
obviyus force-pushed the fix/issue-124343-settle-wake-deferral branch from 8703282 to 0b5be69 Compare August 27, 2026 17:10
@obviyus

obviyus commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks @synthalorian!

Proof: Exact-head CI run 33097032678 passed. On the fresh current-main merge candidate, a real Telegram requester yielded while a completed child retained a live descendant. /tasks showed the child as blocked with the bounded settle-wake reason. Releasing the descendant left the task failed and blocked, completed cleanup, and produced no replacement wake or duplicate requester result.

  • Bug: A yielded requester could wait forever with no final delivery reason while a descendant stayed active.
  • Fix: The lifecycle owner now records one blocked result at the deferral cap and rejects late descendant delivery.

Example

Before After
The completed child stayed pending forever with no reason. /tasks shows a bounded blocked result, and late descendant cleanup cannot overwrite it.

@obviyus
obviyus merged commit fdefa67 into openclaw:main Aug 27, 2026
257 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
Prevent yielded requesters from waiting forever when a completed child retains active descendants. The settle-wake lifecycle now records one blocked delivery at the deferral cap and fences late descendant cleanup from overwriting it.

Co-authored-by: synthclaw <[email protected]>
Co-authored-by: Ayaan Zaidi <[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 merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: yield-owned settle-wake parks a completed subagent forever — no delivery, no retry, no recorded reason

2 participants