Skip to content

fix(subagents): preserve completion handoff across overlapping waves - #136390

Merged
obviyus merged 4 commits into
openclaw:mainfrom
aldiz1711:fix/requester-settle-overlapping-waves
Sep 3, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
aldiz1711:fix/requester-settle-overlapping-waves

Conversation

@aldiz1711

@aldiz1711 aldiz1711 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A completed child could lose its requester completion handoff when a valid descendant wave from the same requester agent stayed active across the stale settle-wake deferral cap. Repeated lifecycle callbacks could also consume the stale budget before the persisted retry deadline.

Why This Change Was Made

The requester-settle lifecycle now applies the stale cap only when no live descendant belongs to the same requester agent. The registry query uses the same direct-root ownership boundary as the existing unsettled-descendant query, so unrelated agents in a global session do not reset the stale budget. The deferral owner checks nextAttemptAt before changing durable state on both deferral paths.

The bounded ten-deferral terminal outcome for genuinely ended-but-unsettled blockers remains unchanged. Current main's sibling model-route aggregation remains intact.

User Impact

Long-running same-requester descendant waves stay pending until they drain, then deliver one synthesized requester wake. Stale ended-but-unsettled batches still produce their bounded terminal outcome. Foreign agent work in a global session cannot keep another agent's stale batch alive.

Evidence

  • Red baseline: current main 644e14a6ab75, using the requester-settle regression scenario, terminalized the frozen child after the active-overlap loop consumed the stale cap.
  • Green exact head: 5a4668186a5e, with 43 requester-settle tests, 4 registry-scope tests, and 3 requester-wake product-flow tests passing.
  • Real Gateway proof: Blacksmith Testbox run 33723908881 passed the isolated mock-provider subagent fanout lifecycle with a separate Gateway state directory and port.
  • Exact-head CI: watcher run 33724496015 is green.
  • Focused checks: formatting, Oxlint, and git diff --check pass. The host does not run OpenClaw typecheck or build lanes; exact-head CI owns those checks.

Contributor intent and the original Han-authored commits are preserved.

The stale-settle deferral cap counted live descendants and terminalized completed siblings during valid long-running waves. Keep active overlap pending, reserve the cap for ended-but-unsettled blockers, and enforce the persisted retry deadline in both deferral paths.
@clawsweeper

clawsweeper Bot commented Sep 2, 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: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 2:50 AM ET / 06:50 UTC.

ClawSweeper review

What this changes

The PR distinguishes active same-agent descendant work from stale unsettled work when delaying a requester’s consolidated subagent completion wake.

Regression provenance

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

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: current main still consumes the stale-deferral budget for active overlap, while this focused owner-scoped repair preserves the bounded stale outcome and has no blocking correctness finding.

Priority: P1
Reviewed head: 5a4668186a5ec30b5e7a0e28e44e555b66a897ed

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused lifecycle repair with aligned ownership boundaries, strong regression coverage, and recorded Gateway behavior proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The changed production owner is requester-settle delivery: the supplied isolated Gateway trace drives its active-overlap path through a QA channel transport, records red budget consumption before the fix, then records 11 deadline-respecting green checks, one synthesized requester wake after drain, and cleared durable state. The trace was captured at behavior-changing commit 9bd96cb; later supplied commits are merge/test updates.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The changed production owner is requester-settle delivery: the supplied isolated Gateway trace drives its active-overlap path through a QA channel transport, records red budget consumption before the fix, then records 11 deadline-respecting green checks, one synthesized requester wake after drain, and cleared durable state. The trace was captured at behavior-changing commit 9bd96cb; later supplied commits are merge/test updates.
Evidence reviewed 6 items Current-main defect remains: Current main increments the deferral count before any active-descendant distinction and has no deadline early-return in this helper, so an active overlap can still consume the stale cap.
Owner-boundary repair: The PR centralizes the requester-agent scope already used by the settle predicate and applies it to the active-descendant query; the delivery owner then resets the stale budget only while relevant active work exists.
Lifecycle caller and persistence owner: The registry schedules the wake as tracked root work and passes lifecycle-owned transition and completion callbacks, so the PR changes the decision before durable state is persisted rather than compensating downstream.
Findings None None.
Security None None.

How this fits together

The subagent registry tracks descendant execution and delivery state. When a requester yields, the settle-wake lifecycle consults that state to either defer a consolidated completion wake or record a bounded failed delivery outcome.

flowchart LR
  A[Subagent completion] --> B[Registry snapshot]
  B --> C[Requester settle-wake]
  C --> D{Same-agent work active?}
  D -->|Yes| E[Keep batch pending]
  D -->|No, stale blocker| F[Count bounded deferrals]
  E --> G[One requester completion wake]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The patch adds net 24 production lines to durable requester-settle state; the shared ownership-scope helper and deadline guard are justified by the new active-versus-stale distinction, but a regression here could still suppress or prematurely terminalize a completion handoff.
  • Resolve merge risk (P1) - Exact-head CI is still incomplete in the supplied status, so normal merge gating has not yet independently validated the final branch head.
Agent review details

Security

None.

PR surface

Source +24, Tests +145. Total +169 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 42 18 +24
Tests 3 165 20 +145
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 207 38 +169

Review metrics

Metric Value Why it matters
Production versus tests production +42/-18 (net +24); tests +165/-20 (net +145) Production growth adds the owner-scoped query and deadline guard; the larger test delta covers active overlap, global-session ownership, and stale-cap behavior.

Root-cause cluster

Relationship: canonical
Canonical: #136390
Summary: This PR is the focused correction for the over-broad deferral cap; the related merged work shares the lifecycle area but addresses a distinct failure mode.

Members:

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

Merge-risk options

Maintainer options:

  1. Await exact-head lifecycle validation (recommended)
    Let the current exact-head checks complete before merging this durable requester-settle state change.

Technical review

Best possible solution:

Retain the owner-scoped active-overlap distinction and deadline guard, then merge only once the normal exact-head checks confirm that both active handoff and stale bounded-failure paths remain intact.

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

Yes, source establishes the path: current main increments the stale budget whenever descendants remain unsettled, while the supplied isolated Gateway trace reports the same active-overlap failure. This read-only review did not execute the harness.

Is this the best way to solve the issue?

Yes: the settle-wake decision owns both the durable retry deadline and the stale-versus-active distinction, and sharing the existing requester-agent filter with the active query avoids a parallel policy path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: A normal overlapping subagent wave can prematurely terminalize a requester completion handoff.
  • merge-risk: 🚨 session-state: The PR changes persisted requester-settle retry, deferral, and terminalization conditions.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The changed production owner is requester-settle delivery: the supplied isolated Gateway trace drives its active-overlap path through a QA channel transport, records red budget consumption before the fix, then records 11 deadline-respecting green checks, one synthesized requester wake after drain, and cleared durable state. The trace was captured at behavior-changing commit 9bd96cb; later supplied commits are merge/test updates.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is requester-settle delivery: the supplied isolated Gateway trace drives its active-overlap path through a QA channel transport, records red budget consumption before the fix, then records 11 deadline-respecting green checks, one synthesized requester wake after drain, and cleared durable state. The trace was captured at behavior-changing commit 9bd96cb; later supplied commits are merge/test updates.

Evidence

What I checked:

Likely related people:

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

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 (3 earlier review cycles)
  • reviewed 2026-09-02T15:46:08.317Z sha cef8c86 :: needs real behavior proof before merge. :: [P1] Scope active descendants to the requester agent
  • reviewed 2026-09-02T16:40:11.330Z sha 9bd96cb :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-02T19:47:40.726Z sha 9bd96cb :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 2, 2026
@aldiz1711

Copy link
Copy Markdown
Contributor Author

Isolated Gateway/lifecycle proof for exact head 9bd96cb3dd88

This addresses the requested real-behavior proof. The harness ran an owned real Gateway process with an isolated state directory and free port, deterministic mock provider, QA channel transport through the Gateway, and test-only control hooks. The live Gateway/profile was not touched.

RED at merge base e29d55a6c058

The old behavior consumes stale budget on the first lifecycle check while the later same-agent wave is still active:

{
  "status": "red",
  "scenario": "active-overlap",
  "head": "e29d55a6c058f48310abeb2509f903ed0b090401",
  "gateway": "ephemeral-real-process",
  "transport": "qa-channel-through-gateway",
  "provider": "mock-openai",
  "isolatedState": true,
  "facts": {
    "observedDeferralChecks": 1,
    "staleDeferralCounts": [1, 1],
    "deliveryStatuses": ["pending", "pending"],
    "activeLaterWaveStillRunning": true
  }
}

GREEN: active later wave

The candidate survives more than ten production requester-settle checks without consuming the stale cap, then emits exactly one visible wake after drain:

{
  "status": "pass",
  "scenario": "active-overlap",
  "head": "9bd96cb3dd88b82b9d624d6fb4534085bdd92fa6",
  "gateway": "ephemeral-real-process",
  "transport": "qa-channel-through-gateway",
  "provider": "mock-openai",
  "isolatedState": true,
  "facts": {
    "observedDeferralChecks": 11,
    "distinctRetryDeadlines": 11,
    "staleDeferralCountAfterEveryCheck": 0,
    "visibleRequesterWakes": 1,
    "finalBatchWakeStateCleared": true
  }
}

GREEN: stale ended-but-unsettled blocker

The bounded failure remains visible through Gateway tasks.list, and durable settle state is cleared:

{
  "status": "pass",
  "scenario": "stale-cap",
  "head": "9bd96cb3dd88b82b9d624d6fb4534085bdd92fa6",
  "gateway": "ephemeral-real-process",
  "transport": "gateway-tasks-rpc",
  "provider": "mock-openai",
  "isolatedState": true,
  "facts": {
    "failedBatchRows": 2,
    "error": "requester settle wake deferred too many times",
    "taskStatuses": ["completed", "completed"],
    "deliveryStatuses": ["failed", "failed"],
    "allTasksTerminal": true,
    "requesterSettleStateCleared": true
  }
}

Validation

  • Focused requester-settle/registry suite: 4 files, 67 tests passed.
  • Full changed-file gate on all six touched files: passed formatting, lint, typecheck, plugin SDK export guard, DB-first guard, and import-cycle/architecture guards.
  • Standalone git diff --check: passed.
  • Checkout remained clean at exact head before and after proof.

One unrelated upstream CI shard is currently red in test/scripts/plugin-npm-security-scan.test.ts:813 because the hosted worker could not measure RSS; this fork PR author does not have permission to rerun upstream Actions. A maintainer rerun is needed for the exact-head CI gate.

@aldiz1711

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 2, 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 proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 2, 2026
@aldiz1711

Copy link
Copy Markdown
Contributor Author

Maintainer CI rerun requested for exact head 9bd96cb3dd88.

The only failing test shard is unrelated to this six-file subagent diff:

  • checks-node-compact-small-56
  • test/scripts/plugin-npm-security-scan.test.ts:813
  • expected process-limit failure, received Plugin npm security scanner could not measure RSS.

A targeted local rerun of writes sanitized exact-identity reports for timeout, heap, and RSS failures passes. I attempted gh run rerun 33655568980 --failed, but GitHub rejects reruns from this fork PR author because upstream repository admin permission is required.

Failed job: https://github.com/openclaw/openclaw/actions/runs/33655568980/job/100341952655

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 3, 2026
@obviyus
obviyus merged commit f5e6bd8 into openclaw:main Sep 3, 2026
232 checks passed
@obviyus

obviyus commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks @aldiz1711!

Proof: A real isolated Gateway fanout run passed on Blacksmith Testbox, and exact-head CI passed on run 33724496015.

  • Bug: A valid same-requester descendant wave consumed the stale settle-wake cap and could terminalize a completed child before its handoff reached the requester.
  • Fix: Requester-agent-owned live descendants now reset the stale budget, the persisted retry deadline is enforced before deferral, and foreign agents in global sessions remain outside that overlap decision.
Before After
Active overlap could clear the completed child handoff at the stale cap. Active overlap stays pending until drain, then emits one requester wake.
Repeated callbacks could consume the cap before nextAttemptAt. The deadline gates both deferral paths.
Foreign global-session work could affect another requester. The active count uses the requester-agent ownership boundary.

Source head: 5a4668186a5

Landed as: f5e6bd872c9

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
…penclaw#136390)

## What Problem This Solves

A completed child could lose its requester completion handoff when a valid descendant wave from the same requester agent stayed active across the stale settle-wake deferral cap. Repeated lifecycle callbacks could also consume the stale budget before the persisted retry deadline.

## Why This Change Was Made

The requester-settle lifecycle now applies the stale cap only when no live descendant belongs to the same requester agent. The registry query uses the same direct-root ownership boundary as the existing unsettled-descendant query, so unrelated agents in a global session do not reset the stale budget. The deferral owner checks `nextAttemptAt` before changing durable state on both deferral paths.

The bounded ten-deferral terminal outcome for genuinely ended-but-unsettled blockers remains unchanged. Current main's sibling model-route aggregation remains intact.

## User Impact

Long-running same-requester descendant waves stay pending until they drain, then deliver one synthesized requester wake. Stale ended-but-unsettled batches still produce their bounded terminal outcome. Foreign agent work in a global session cannot keep another agent's stale batch alive.

## Evidence

- Red baseline: current main `b3841af9b841`, using the requester-settle regression scenario, terminalized the frozen child after the active-overlap loop consumed the stale cap.
- Green exact head: `5a4668186a5e`, with 43 requester-settle tests, 4 registry-scope tests, and 3 requester-wake product-flow tests passing.
- Real Gateway proof: Blacksmith Testbox run [33723908881](https://github.com/openclaw/openclaw/actions/runs/33723908881) passed the isolated mock-provider subagent fanout lifecycle with a separate Gateway state directory and port.
- Exact-head CI: watcher run [33724496015](https://github.com/openclaw/openclaw/actions/runs/33724496015) is green.
- Focused checks: formatting, Oxlint, and `git diff --check` pass. The host does not run OpenClaw typecheck or build lanes; exact-head CI owns those checks.

Contributor intent and the original Han-authored commits are preserved.

Co-authored-by: Han <han@localhost>
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: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants