Repository navigation
fix: deliver subagent completions after busy parent turns - #136423
Conversation
Admit direct CLI turns through the shared session lane before placement claims. Preserve accepted completion execution budgets while queued, and revalidate run, source, and session owners before execution. Fixes #134186. Addresses turn admission in #135192. Reported by @svdwalt007 and @Tony-Clawbot; confirmed by @Isitjustmefromparis.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 3:39 PM ET / 19:39 UTC. ClawSweeper reviewWhat this changesThe branch queues local CLI, fallback, and cron turns through the requester session lane, fences queued work against lifecycle changes, and separates completion queue wait from execution timeout. Merge readinessKeep open. The branch uses the correct shared session-admission boundary for busy-parent completion delivery, but exact-head validation remains necessary before merge and the review environment could not fully materialize current-main objects from its offline partial clone. Priority: P1 Review scores
Verification
How this fits togetherSubagent completion delivery asks the Gateway to notify the requester session when delegated work finishes. Session admission serializes local CLI and embedded work for that requester so placement ownership and completion delivery cannot race an already-active turn. flowchart LR
A[Subagent completes] --> B[Completion announcement]
B --> C[Gateway turn request]
C --> D[Shared session lane]
D --> E[Placement and local CLI turn]
E --> F[Requester receives completion]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +176, Tests +488, Docs 0. Total +664 across 17 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep one shared session-admission flow with lifecycle fencing and independently bounded delivery deadlines, then validate the affected turn sources on the exact PR head. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: the branch supplies focused busy-parent and lifecycle-boundary coverage, though this read-only review did not execute those tests. Is this the best way to solve the issue? Yes: a common session-admission boundary repairs the owner-level race across direct CLI, fallback, and cron paths; a timer-retry-only change would retain the collision. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1e37a56c7528. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
Keep the lazy asynchronous CLI runtime contract when resolving native continuity inside the session lane. The existing delayed-binding regression catches model execution starting before lookup settlement.
Keep admission wait outside the execution budget while the cleanup owner enforces the existing delivery window. Honor explicit retries and retained optional announcements; cancel stale queued work before it can execute.
Reload the durable reply target after session admission and reject session ID or lifecycle revision changes before starting the CLI. Internal turns without a store target retain their in-memory path. Seed the existing durable-session fixture and type rejection callbacks explicitly. Both lifecycle replacement regressions fail before this fix. Reply routing, CLI dispatch, and admission coverage pass: 62 tests. Refs #134186, #135192.
Final-head live proofVerified The parent remained busy in a foreground 160-second Python wait. Claude's native hook rejected the initial shell Delivery assertions used received Exact-head focused admission/delivery/cleanup/lifecycle suites: 441 passed. The reply suite split preserved test bodies byte-for-byte and passed 18 tests. Full branch autoreview is clean at P0/P1. Runtime refresh and UI build passed. The final changed-file check is still running; CI is not yet green because main's unrelated This addresses the latest ClawSweeper request for current-head behavior evidence and focused results. Landing remains gated on completed validation and green CI. |
|
Ready to land at The repaired owner is Exact-head validation: Exact-head CI is green after retrying the failed security bootstrap and its aggregate gate. The first attempt's code/test jobs passed; pre-commit failed fetching a public hook before scanning. Main CI is also green. The latest ClawSweeper review found no actionable code findings; its remaining exact-head CI rank-up move is satisfied. Production: +369/-193 (+176). Tests: +643/-155 (+488, including moved tests). Docs: +5/-5. Production growth provides missing lifecycle/capacity retention, durable-target fencing, and independent delivery lifetime; it does not add a second queue/store. The separate late CLI-binding settlement refactor remains in progress. Pending-replay accounting stays tracked in #136513, and the other #135192 observations remain split into #136487–#136491. Discord oversized-message behavior was not claimed fixed. Reporter credit: @svdwalt007, @Tony-Clawbot, and @Isitjustmefromparis. No changelog, config/env option, schema/version, protocol bump, or dependency override was added. |
|
Merged via squash.
|
…36423) * fix: queue subagent completions behind busy parent turns Admit direct CLI turns through the shared session lane before placement claims. Preserve accepted completion execution budgets while queued, and revalidate run, source, and session owners before execution. Fixes openclaw#134186. Addresses turn admission in openclaw#135192. Reported by @svdwalt007 and @Tony-Clawbot; confirmed by @Isitjustmefromparis. * fix: await cron CLI binding after turn admission Keep the lazy asynchronous CLI runtime contract when resolving native continuity inside the session lane. The existing delayed-binding regression catches model execution starting before lookup settlement. * fix: fence queued CLI turns by their prepared lifecycle revision * fix: bound queued completions by their delivery deadline Keep admission wait outside the execution budget while the cleanup owner enforces the existing delivery window. Honor explicit retries and retained optional announcements; cancel stale queued work before it can execute. * fix: fence queued CLI replies by their prepared session lifecycle Reload the durable reply target after session admission and reject session ID or lifecycle revision changes before starting the CLI. Internal turns without a store target retain their in-memory path. Seed the existing durable-session fixture and type rejection callbacks explicitly. Both lifecycle replacement regressions fail before this fix. Reply routing, CLI dispatch, and admission coverage pass: 62 tests. Refs openclaw#134186, openclaw#135192. * test: split CLI admission coverage from session routing
…ne scenario (review feedback) The scenario claimed to prove deferred completion admission but did not establish the precondition that selects it. Holding the requester inside a foreground `exec` keeps its run ACTIVE, and an active embedded requester run always accepts an announce steer: `subagent-announce-direct-delivery.ts:280-322` attempts the wake first, with `steeringMode: "all"`, and returns `path: "steered"` on success; `subagent-announce-active-wake.ts:113-124` deletes `sourceReplyDeliveryMode` and retries when the queue refuses with `source_reply_delivery_mode_mismatch`, which is exactly the `message_tool_only` gate a direct-message completion sets. `supportsTranscriptCommitWait` is hardcoded `true` on the embedded handle (`run/attempt-stream-prepare.ts:668`) and `acceptingSteerMessages` stays true through tool execution, so no scenario-controllable state makes an embedded requester refuse. The completion could therefore be consumed by the original run, leaving step 5 without the later turn it requires. Deferred admission is the non-embedded requester case: when the wake is refused, delivery falls through to the gateway `agent` call keyed on the requester session, which serializes on `session:<requesterSessionKey>` through `session-placement-admission.ts` — the behavior merged in openclaw#136423 ("Admit direct CLI turns through the shared session lane before placement claims"). Establish that precondition instead of assuming it, and verify the distinct run rather than inferring it from tool ordering: - `execution.runtime: codex` pins the requester to the CLI harness whose in-flight turn is not an embedded steer target. The field is supported (`scenario-module-flow.ts:37`) and forces a dedicated isolated worker (`suite-planning.ts:333`, `suite-launch.runtime.ts:1336`), matching the existing runtime-pinned scenarios. - `runtimePairLane: core` is dropped. The scenario is runtime-pinned, so it is not runtime-pair coverage, and it should not be declared release coverage before it has run. This reverts the catalog count file to `origin/main`. - At the boundary where the requester's own reply reaches Telegram, the requester session must still show exactly one user message. An accepted steer commits its trigger as a user message while the held exec is still running, so this fails with a message naming the steered path instead of timing out on the missing later turn. - After that cursor, the requester must record exactly one user message, one message-tool send, and no spawn or exec — a distinct completion turn, not a continuation of the original run. - Prompt step 5 no longer conditions the send on "a later turn"; the obligation is unconditional and explicitly ordered after the requester's own reply. No production file is touched and production steering behavior is unchanged. Validation, in the topic worktree: `scenario-catalog*.test.ts` + `scenario-lane.test.ts` + `suite-planning*.test.ts` -> 23 files requested / 23 executed, 299 passed, EXIT 0; pack consumers (`coverage-report*`, `cli-scenario-selection`, `live-scenario-timeouts`, `agentic-parity-report*`, `evidence-summary*`, `confidence-report*`, `ci-smoke-plan`) -> 11 files requested / 11 executed, 323 passed, EXIT 0; `pnpm format:check` EXIT 0; `git diff --check` clean. The branch's TypeScript tree is now byte-identical to `origin/main`, so the diff is a single YAML file. Beads: openclaw-cy3n Co-Authored-By: Claude Opus 5 <[email protected]>


What Problem This Solves
Fixes #134186: a busy Claude CLI parent could reject its child's completion with
Session … already has an active turn claimafter an unavailable wake, includingno_active_run. Addresses the turn-claim/completion portion of #135192. Its independent migration, readiness, and ingress observations remain tracked in #136487, #136488, #136489, #136490, and #136491; the broader replay/dead-letter proposal remains #120422.Thanks @svdwalt007 and @Tony-Clawbot for the reports, and @Isitjustmefromparis for the independent confirmation.
Why This Change Was Made
Direct CLI turns now enter the same per-session admission lane as embedded and Codex turns before acquiring placement ownership. The lane retains queued run context and records capacity wait. Dequeue checks cancellation, runtime lifecycle, the exact placement provider, and the prepared durable session incarnation. Command and reply preparation reload session facts after admission; cron resolves its native binding inside the same boundary.
A newly accepted completion waits for its final result without spending execution timeout while queued. Execution start revalidates its source and arms the execution budget. The completion lifecycle separately owns the existing required-delivery 30-minute deadline and optional-delivery five-minute deadline, so a permanently busy parent cannot strand cleanup forever. Existing manual retry windows remain authoritative.
Claim release stays with exact turn settlement and forced-terminal cleanup. Those owners already release settled claims; a late finalizer must never release a successor's claim. This repair does not add claim-retry loops, another queue, or another store.
No new configuration, environment variables, schema, protocol version, dependencies, or compatibility path. No changelog change.
User Impact
An active requester still gets same-turn steering when supported. Otherwise, its completion waits for a follow-up turn after the parent releases its claim. Cancelled, replaced, or expired queued work cannot later execute through a replacement owner. Deadline expiry retains the existing visible blocked-result outcome.
The separate pre-existing duplicate-RPC replay accounting defect is tracked in #136513:
in_flightcan receive premature delivery credit. A result-only change would let retries steer an announcement into itself, so that issue needs a canonical same-id join rather than a partial fix here. The companion Discord oversized-message symptom was not reproduced or claimed fixed.Evidence
11fd22f91844cec74a82a077b4b9a9d605a1a05e, focused admission/delivery/cleanup/lifecycle coverage passed 441 tests. The split CLI reply suites passed 18 tests with moved test bodies verified byte-identical. Both durable reply revision cases had failed before the production correction.Final-head live proof
Inspected Control UI screenshots and event trace verify a real Claude CLI parent and child on
11fd22f91844cec74a82a077b4b9a9d605a1a05e, through an isolated loopback Gateway, synthetic data only:Received WebSocket
chatevents withstate=final, assistant role, distinct initial/announcement run IDs, and the same requester session establish delivery and order. Prompt text alone was not counted. The rejected active wake used requester-agent handoff successfully. The exactno_active_runcase is regression-covered, not claimed as the observed live wake reason (runtime_rejected).Review follow-through
ClawSweeper's accepted queue-deadline finding is addressed: lifecycle-owned cancellation bounds permanently queued delivery by its existing required or optional deadline, with failing-before/passing-after tests. The production-growth explanation, exact-head real behavior trace, and focused suites address the latest rank-up requests. The unrelated main lint failure from #133381 was repaired in aef65cc57490; exact-head validation and CI are now green. The final ClawSweeper review reports no actionable code findings and accepts the real behavior proof.