Repository navigation
refactor(subagents): check a Stop's caller authority once, then let the admitted kill finish - #205940
Conversation
…he admitted kill finish A subagent Stop re-checked its caller's authority before almost every step, including after its kill intent was recorded and after the run was aborted. A revocation in between made the Stop back out or report failure after the work was done. The kill scope now checks the caller while it selects the run tree and once more at admission. After that only the claimed row and session incarnation stay checked. This removes the per-run revocation decline path, the acceptance caller-failure path and the post-kill caller re-assertions.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: passed. What this changesThis PR checks caller authority at Stop admission and lets admitted cancellation finish while retaining run and session identity checks. Example: Stopping caller-control-run aborts the child, then the caller loses authority.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored draft open: it addresses false Stop failures through the existing cancellation owner, and no introduced correctness defect was found. Reviewed head: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway and subagents-tool Stop requests enter the subagent registry's kill scope, which selects owned descendants, interrupts captured execution and commands, persists cancellation, and publishes the outcome. flowchart TD
A[Gateway or subagents tool] --> B[Select tree and admit caller]
B --> C[Capture exact execution]
C --> D[Interrupt and drain cleanup]
D --> E[Settle existing registry claim]
E --> F[Publish Stop result]
Technical reviewBest possible solution: Keep admission in the existing kill scope and let its captured cancellation finish under the retained run, session, persistence, and cleanup owners. Do we have a high-confidence way to reproduce the issue? Current-main source reasserts caller authority after cancellation effects, and the author reports matching red-on-main, green-on-head regressions; this read-only review did not execute them. Is this the best way to solve the issue? The patch removes the repeated policy decision at its existing owner, updates affected consumers' expectations, and preserves exact-target and cleanup contracts without adding another control path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ea27b2143ecd. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -110, Tests -12, Docs +5. Total -117 across 11 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 26, 2026, 7:27 AM ET / 12:27 UTC. |
|
Merged via squash auto-merge.
|
…he admitted kill finish (openclaw#205940) * refactor(subagents): check a Stop's caller authority once, then let the admitted kill finish A subagent Stop re-checked its caller's authority before almost every step, including after its kill intent was recorded and after the run was aborted. A revocation in between made the Stop back out or report failure after the work was done. The kill scope now checks the caller while it selects the run tree and once more at admission. After that only the claimed row and session incarnation stay checked. This removes the per-run revocation decline path, the acceptance caller-failure path and the post-kill caller re-assertions. * test(subagents): expect admitted native Stops to finish after caller revocation
…he admitted kill finish (#205940) * refactor(subagents): check a Stop's caller authority once, then let the admitted kill finish A subagent Stop re-checked its caller's authority before almost every step, including after its kill intent was recorded and after the run was aborted. A revocation in between made the Stop back out or report failure after the work was done. The kill scope now checks the caller while it selects the run tree and once more at admission. After that only the claimed row and session incarnation stay checked. This removes the per-run revocation decline path, the acceptance caller-failure path and the post-kill caller re-assertions. * test(subagents): expect admitted native Stops to finish after caller revocation (cherry picked from commit 438f743) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
When someone stops a sub-agent, OpenClaw kept re-asking during the Stop whether that caller still had authority over the run. The question came up again before each step, after the kill intent was already recorded, after the run was interrupted, and before the result was published. If the answer changed at any of those points, the Stop backed out with "ownership changed; retry".
That had two bad results:
sessions.abortreported that nothing was stopped and the collector stayed queued.The repository rule (AGENTS.md, "Choose good compromises") is to check authority once, when work starts, and let a started request finish. Revocation applies to the next request. #202442 and #204249 already removed in-run authority re-checks elsewhere. Kill is the largest remaining place that still does it.
User Impact
docs/tools/subagents/operations.md("Stopping") now states when authority is checked.Why This Change Was Made
withSubagentKillScopeowns admission. It checks the caller while selecting the run tree and once more right before running the kill. After that itsassertCurrentchecks only the registry write source, not the caller. It also stops calling the caller'sprepareRead, because that read prepares the caller's authority check (the subagents tool's version callsassertSelection()). Each tree's own session and registry read preparation is unchanged. The descendant-refresh special case that let already-accepted outcomes past a revoked caller is deleted, because there is no revoked caller after admission.mutateSubagentRunForKilllosesdeclineRevokedCancellationand its five call sites (three in preparation, two in the run phase). It also loses theacceptance.callerFailurepaths and the post-claim branches that settled or released the claim after a revocation.createSubagentKillAcceptancedropsassertCallerCurrentand its recorded caller failure. It keeps only native-owner checks when cancelling commands.markSubagentRunTerminated.assertCancellationCurrentbecomesassertClaimCurrent(the claimed row and session incarnation only).settleSubagentKillno longer re-asserts the caller after the kill.killLatestSubagentRunno longer re-asserts it while cancelling the run's commands.Size: production code is +39 −149 across 5 files (tests +52 −64). Complexity from the same scanner (
scb-check) before and after:mutateSubagentRunForKillCC 154 → 132,withSubagentKillScopeCC 140 → 134, and the runtime'scancellationclosure CC 40 → 35.Not in this PR: the session-incarnation fence (
ownsSessionIncarnation,releaseChangedSession) is still re-checked in flight. The kill claim already recordssessionIdandlifecycleRevision, so the next step makes the claim the single identity check. That changes what a session reset during a kill reports, so it gets its own PR and proof.Open overlap: #194275 changes
subagent-control-kill-scope.tsandsubagent-control-kill.ts, and #189391 changessubagent-control-kill-scope.ts. Either will need a rebase.Evidence
subagent-control.concurrency.test.ts"refuses a Stop revoked before admission and finishes one revoked %s":{ found: true, killed: true }, the run is aborted, the admission is interrupted once, and no kill intent is left behind.session-utils.queued-collector.test.ts, scenariosessions.abort exact=false parent-retired: the Stop that retires its own parent turn now stops the collector (respondtrue, collector no longer queued).subagent-control.accepted-stop.test.ts: an accepted Stop whose caller is revoked mid-settlement resolves and publishesonResultonce instead of rejecting.subagent-control.commands.test.ts:postaccept-revokedreportsok, andlate-revoked-evictedno longer carries the revocation in its error. The cleanup failure still reportserror.subagent-control.worker.test.ts: a caller that retires after the kill claim commits gets a completed kill. A replaced session incarnation still releases the claim, because that identity check is kept.subagent-control.concurrency.test.ts"an admitted Stop never waits on caller facts requested while …": caller facts are not read after admission.src/agents/subagents: 1,331 passed and 1 skipped. The only failures in that run were the 5 cases of the last concurrency test above, which was then rewritten; that file now passes 12/12.ERR_SPAWN_BROKER_UNAVAILABLEand no assertion failures. Those files pass when run alone (8 files, 70 tests).pnpm tsgo:coreandpnpm tsgo:test:srcare clean, as are oxfmt, oxlint on the changed files andgit diff --check.subagents-tool,chat-abort-runtimeandchat-abort-descendantscallers as source context:scoped-clean, no findings, confidence 0.84.244964d: PR CI'schecks-node-changed-compact-large-33shard showed that two spawn production-boundary helpers still expected the old contract. They now expect admitted native Stops to finish: "separates native stop acceptance from caller revocation" (after interruption, already interrupted) and theconsumed-active-revokedcustody case, which reportsokwithkilled: 1. With main's production code those three fail, and they pass here.subagent-spawn.production-boundary.test.tspasses 140/141. The one failure,preserves routed native Stop authority … (consumed-session), fails the same way with main's production code (abortedexpected false, received true). It is the existing order-dependent failure on main described in refactor(subagents): retire finished child rows by one rule instead of two handed-off flags #205482.244964d: thechecks-fast-baseline-ratchetsjob ran for 47 minutes and stopped inside "Run baseline ratchets". The step never reported a result, and GitHub returnsBlobNotFoundfor its log, so the runner was lost. Locally,pnpm check:baseline-ratchets --base origin/main --no-merge-baseon the PR merged with current main passes every ratchet: max-lines, assertion-safety, session-identity, runtime-process-lifecycle, mock-exports, and test-lines (net −12 against a 400 allowance). Only the failed jobs were rerun, as an infrastructure recovery.