Skip to content

fix(agents): prevent requester settle while child is still running - #120601

Merged
Patrick-Erichsen merged 2 commits into
openclaw:mainfrom
VACInc:fix/requester-settle-live-child
Aug 10, 2026
Merged

Patrick-Erichsen merged 2 commits into
openclaw:mainfrom
VACInc:fix/requester-settle-live-child

Conversation

@VACInc

@VACInc VACInc commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

sessions_yield could wake a requester while a frozen child was still running. This refresh moves the primary terminality gate to requester-wake scheduling, keeps a matching admission backstop, and preserves the existing behavior where retired batch rows do not strand surviving siblings.

What Problem This Solves

A yielded requester could receive an "all subagents settled" continuation while its only frozen child still had execution.status: "running" and no finite execution.endedAt. The triggering run is intentionally excluded from the descendant-drain query, and the lifecycle rearm loop could schedule any armed row without checking whether that row had ended.

The earlier revision also introduced a silent-failure regression: if a sweeper retired one frozen member before delivery, admission aborted the entire batch instead of dropping the vanished row and settling the surviving members.

Why This Change Was Made

Root Cause

Frozen batchRunIds own membership, not liveness. The wake path treated membership as terminal proof, while hasDescendantRunAwaitingSettle excluded the triggering run. Separately, completeRequesterSettleWakeBatch re-dispatched remaining armed rows through scheduleRequesterSettleWake without a terminality gate.

The canonical lifecycle owner now refuses to schedule a row whose status is still running or whose finite end timestamp is absent. Frozen-batch admission applies the same rule to every surviving row in its single current registry snapshot. Missing or generation-mismatched rows are filtered, preserving the pre-existing retire-and-continue behavior.

Both status and endedAt are required intentionally. A replayed lifecycle start event in src/agents/subagent-registry-listener.ts preserves the existing execution object while restoring status: "running", so a real reordered state can contain an older endedAt while the run is live.

The redundant second registry listing was removed: no await separated it from the first listing, so production could not change between the two snapshots. The former test only made the mock return different arrays synchronously and did not prove runtime behavior.

Scope remains inside requester-settle scheduling and admission. There are no config, protocol, persistence-schema, delivery-retry, channel, or stale-run-policy changes.

User Impact

Yielded requesters remain parked while any surviving frozen child is live. After the child reaches its real terminal lifecycle state, the requester is woken exactly once. If a frozen sibling was legitimately retired meanwhile, the remaining terminal siblings still complete the batch instead of leaving the requester silently stranded.

Evidence

The closest feasible production-owner proof uses the real in-memory subagent registry and lifecycle controller with the existing mocked Gateway RPC delivery seam. It creates a yielded frozen row, injects the previously faulty wake attempt while that real row is live, emits the production lifecycle terminal event, and observes delivery at the Gateway boundary.

{
  "harness": "production registry and lifecycle with mocked Gateway RPC delivery",
  "running": {
    "executionStatus": "running",
    "requesterWakeCalls": 0
  },
  "terminal": {
    "executionStatus": "terminal",
    "requesterWakeCalls": 1
  },
  "verdict": "PASS"
}

The focused regression command and copied result were:

$ node scripts/run-vitest.mjs src/agents/subagent-announce.requester-settle-wake.test.ts src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-registry.lifecycle-retry-grace.e2e.test.ts src/agents/subagent-registry-requester-yield.test.ts src/agents/embedded-agent-runner/run/attempt.sessions-yield.test.ts
Test Files  5 passed (5)
Tests       204 passed (204)
[test] passed 3 Vitest shards

The real-registry trace is asserted by keeps a frozen live child asleep until its real registry row becomes terminal. The scheduler-owner unit test independently proves a persisted wake is not resumed before the row becomes terminal. Unit coverage also proves running-with-end and terminal-without-end rejection plus successful completion when a frozen sibling has been retired.

Verification

  • git diff --check passed.
  • The five focused files above passed: 204 tests across unit-fast, agents-core, and E2E shards.
  • Final isolated boundary rerun passed: 1 selected E2E test, 10 skipped.
  • node scripts/check-changed.mjs -- <five touched files> attempted the required Testbox route, but no configured provider was ready. The documented trusted-source local fallback passed conflict markers, env/max-lines ratchets, attribution, re-export, duplication, dependency, formatting, Plugin SDK, deprecated-API, plugin-boundary, patch, dead-export, and test-temp gates. It then stopped at the unrelated existing packages/terminal-core/src/ansi.ts:194 type error; this PR does not change that file or its dependency surface.
  • Final autoreview was clean with no accepted/actionable findings; secret scan was clean.

Performance was sampled on Linux with Node 25.9.0 using the same focused terminal-wake test, one warmup, and five whole-process samples. Prior head 4bed0b45ae98 measured 5.38, 5.29, 5.20, 5.23, and 5.07 seconds (mean 5.23, median 5.23). The refreshed code measured 5.26, 6.17, 5.43, 6.31, and 5.25 seconds (mean 5.68, median 5.43). This import-dominated benchmark ran while the shared host carried unrelated heavy checks, so the 0.20-second median difference is within observed host noise; it does not support an isolated latency claim. The production refresh itself is net -8 lines versus the prior PR head.

Production LOC for the complete PR is +20/-1 (net +19): scheduler ownership plus admission backstop. Tests are +155/-14. Relative to the prior PR head, production is +16/-24 (net -8) and tests are +108/-30.

What was not tested

  • No authenticated live channel or operator Gateway was touched. The registry/lifecycle failure is deterministic, and this proof stops at the mocked Gateway RPC delivery seam.
  • No private operational identifiers, chat context, or live artifacts were copied into this public PR.
  • The full changed gate could not finish because Testbox/broker capacity was unavailable and the trusted local fallback encountered the unrelated terminal-core type error above. Exact-head GitHub CI remains the merge-ref proof for the lanes after that point.

Exact-head real Gateway proof

Exact head 098581226c26a06abdb78a2e59aff44f3fcd6bcb also passed an ephemeral real-Gateway QA scenario with a mock provider and mock channel: Crabbox run run_d0b4ebc99754.

{
  "whileChildRunning": {
    "requesterWakeCount": 0,
    "requesterOutboundCount": 0
  },
  "terminalBoundary": {
    "gatewayEvent": "agent",
    "stream": "lifecycle",
    "phase": "end"
  },
  "afterTerminal": {
    "requesterWakeCount": 1,
    "requesterOutboundCount": 1
  },
  "afterQuietWindow": {
    "windowMs": 3000,
    "requesterWakeCount": 1,
    "requesterOutboundCount": 1
  },
  "verdict": "PASS"
}

The scenario exercised the actual Gateway, in-memory task ledger, subagent lifecycle controller, requester wake path, and outbound channel delivery. The controlled mock provider kept the child request in flight until release; no requester wake or outbound message occurred while the child was running. A real Gateway agent lifecycle end event was then observed before the single wake and single outbound response, and both counts remained exactly one through the quiet window.

@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. labels Aug 8, 2026
@clawsweeper clawsweeper Bot added 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. 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. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 7:57 PM ET / 23:57 UTC.

ClawSweeper review

What this changes

The PR prevents a yielded requester from waking until every surviving frozen child has both terminal status and a finite end timestamp.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for maintainer merge review: current main lacks the terminality checks, while this PR repairs the same-row lifecycle gap with no blocking correctness or security finding.

Priority: P1
Reviewed head: 098581226c26a06abdb78a2e59aff44f3fcd6bcb

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with strong lifecycle and Gateway-boundary evidence.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR supplies an exact-head ephemeral Gateway trace through the real registry and lifecycle controller, showing no wake while live and exactly one wake after terminal transition.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR supplies an exact-head ephemeral Gateway trace through the real registry and lifecycle controller, showing no wake while live and exactly one wake after terminal transition.
Evidence reviewed 6 items Current-main gap: Frozen batch selection accepts rows by wake state and generation only, while the descendant query excludes the triggering row; a running triggering child can therefore be treated as settled.
Lifecycle owner: Current main schedules a persisted requester wake without requiring terminal status or a finite end timestamp.
Patch owner-boundary repair: The PR gates both scheduler admission and frozen-batch selection on terminal status plus a finite end timestamp, retaining filtering of legitimately retired rows.
Findings None None.
Security None None.

How this fits together

Requester-settle wake-up resumes a yielded requester after child-run lifecycle work completes. It reads the subagent registry and then sends one Gateway wake request to continue the requester session.

flowchart LR
  A[Child lifecycle event] --> B[Subagent registry]
  B --> C[Requester-settle scheduler]
  C --> D{Terminal status and end time?}
  D -- No --> E[Requester remains yielded]
  D -- Yes --> F[Frozen batch admission]
  F --> G[Gateway requester wake]
Loading

Before merge

  • Resolve merge risk (P1) - This changes session-state scheduling: a regression in either terminality gate could resume a requester early or leave it yielded, so merge review should preserve both the scheduler and frozen-batch checks.
Agent review details

Security

None.

PR surface

Source +19, Tests +141. Total +160 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 20 1 +19
Tests 3 155 14 +141
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 175 15 +160

Review metrics

Metric Value Why it matters
Production vs regression coverage production +20/-1; tests +155/-14 The added production logic is limited to the lifecycle owner and admission backstop, with broader regression coverage for the concurrency boundary.

Stored data model

Persistent data-model change detected: serialized state: src/agents/subagent-registry-lifecycle.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Land with terminality gates intact (recommended)
    Accept the bounded session-state risk after confirming the merge result retains both scheduler admission and frozen-batch terminality checks.

Technical review

Best possible solution:

Land the focused owner-boundary fix with both terminality gates and its lifecycle-to-Gateway regression coverage intact.

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

Yes: freeze a yielded child while it remains running, then invoke the requester-settle path; current main excludes that triggering child from the descendant check and has no equivalent terminality gate.

Is this the best way to solve the issue?

Yes: gating at the lifecycle scheduler and frozen-batch admission is the narrowest maintainable repair; either gate alone leaves a direct or replayed admission path unprotected.

AGENTS.md: found and applied where relevant.

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

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 yielded requester can otherwise resume before its active child run has truly settled.
  • merge-risk: 🚨 session-state: The PR changes durable requester wake scheduling relative to child lifecycle state.
  • 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 (linked_artifact): The PR supplies an exact-head ephemeral Gateway trace through the real registry and lifecycle controller, showing no wake while live and exactly one wake after terminal transition.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies an exact-head ephemeral Gateway trace through the real registry and lifecycle controller, showing no wake while live and exactly one wake after terminal transition.

Evidence

What I checked:

Likely related people:

  • Patrick-Erichsen: The PR timeline records assignment and a recent review-related comment from this person. (role: assigned reviewer and recent discussion participant; confidence: medium; files: src/agents/subagent-announce.requester-settle-wake.ts, src/agents/subagent-registry-lifecycle-requester-wake.ts)
  • Peter Steinberger: Current-main history after the PR base includes adjacent agent lifecycle and retention changes. (role: recent adjacent contributor; confidence: medium; commits: 0f6de6a75181, ce53f7e82e25; files: src/agents/subagent-announce.requester-settle-wake.ts, src/agents/subagent-registry-lifecycle.test.ts)

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-08-08T14:39:05.445Z sha 4bed0b4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-09T00:46:25.810Z sha 0985812 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-09T23:50:57.274Z sha 0985812 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 9, 2026
@VACInc

VACInc commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Aug 9, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@Patrick-Erichsen Patrick-Erichsen self-assigned this Aug 9, 2026
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 9, 2026

@Patrick-Erichsen Patrick-Erichsen 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.

Maintainer review complete at exact head 0985812. The scheduler-owner terminality gate and frozen-batch admission backstop are the best bounded fix. Exact-head CI is green; real Gateway proof shows 0 wakes while running and exactly 1 after terminal completion; ClawSweeper reports proof sufficient with no findings.

@Patrick-Erichsen
Patrick-Erichsen merged commit 7d12927 into openclaw:main Aug 10, 2026
280 of 282 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…penclaw#120601)

* fix(agents): keep requester settle attached to live children

* fix(agents): gate requester settle on terminal children

---------

Co-authored-by: VACInc <[email protected]>
tomorrowflow pushed a commit to tomorrowflow/openclaw that referenced this pull request Aug 16, 2026
…penclaw#120601)

* fix(agents): keep requester settle attached to live children

* fix(agents): gate requester settle on terminal children

---------

Co-authored-by: VACInc <[email protected]>
(cherry picked from commit 7d12927)
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: S 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