Repository navigation
fix(agents): prevent requester settle while child is still running - #120601
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 7:57 PM ET / 23:57 UTC. ClawSweeper reviewWhat this changesThe PR prevents a yielded requester from waking until every surviving frozen child has both terminal status and a finite end timestamp. Merge readinessKeep 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 Review scores
Verification
How this fits togetherRequester-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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +19, Tests +141. Total +160 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
Patrick-Erichsen
left a comment
There was a problem hiding this comment.
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.
|
Merged via squash.
|
…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]>
…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)
Summary
High Level TLDR
sessions_yieldcould 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 finiteexecution.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
batchRunIdsown membership, not liveness. The wake path treated membership as terminal proof, whilehasDescendantRunAwaitingSettleexcluded the triggering run. Separately,completeRequesterSettleWakeBatchre-dispatched remaining armed rows throughscheduleRequesterSettleWakewithout a terminality gate.The canonical lifecycle owner now refuses to schedule a row whose status is still
runningor 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
endedAtare required intentionally. A replayed lifecyclestartevent insrc/agents/subagent-registry-listener.tspreserves the existing execution object while restoringstatus: "running", so a real reordered state can contain an olderendedAtwhile the run is live.The redundant second registry listing was removed: no
awaitseparated 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:
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 --checkpassed.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 existingpackages/terminal-core/src/ansi.ts:194type error; this PR does not change that file or its dependency surface.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
4bed0b45ae98measured 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
Exact-head real Gateway proof
Exact head
098581226c26a06abdb78a2e59aff44f3fcd6bcbalso passed an ephemeral real-Gateway QA scenario with a mock provider and mock channel: Crabbox runrun_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
agentlifecycleendevent was then observed before the single wake and single outbound response, and both counts remained exactly one through the quiet window.