Repository navigation
Conversation
A subagent Stop issued from a source's own cleanup excluded the caller's operation but not its raw source, so settleQueued awaited the caller's own settlement until the 15s drain deadline and then reported success. Mirror settleSubagentKillSources: exclude the current turn input from the queued drain wait.
|
🦞👀 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. |
|
I independently investigated #189376 and found this PR during the final duplicate check, so I have not opened a competing PR. There is a complementary fix available in 2254cd9d96, intended to be cherry-picked on top of your self-source exclusion. It does not change At the current head The regression uses the real controller and SQLite-backed registry: an original source is being drained, its RPC source is replaced, and the final drain of the replacement expires under a fake clock. On base Validation on my combined branch:
The aggregation change must not land before the self-source guard: otherwise it correctly exposes the old self-join as an error and the existing self-disposal case fails. This is controller/SQLite/RPC boundary proof, not live LLM/channel E2E or CI evidence for your branch. The full accepted-stop file took 107.11s wall time (101.20s Vitest duration); its existing replacement-fixture case still accounts for about 15s. Changes were prepared with Codex assistance. |
RED on the base: Stop issued inside the source's own raw cleanup waited out SESSION_CONTROLLER_DRAIN_TIMEOUT_MS and still reported success. GREEN with the settleQueued self-input exclusion.
|
Codex review: needs maintainer review before merge. What this changesExclude the Stop caller’s own controller source from the final subagent cleanup drain. Example: Stop runs inside a source’s cleanup while that source’s settlement remains pending.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR makes a focused repair to a cleanup self-join still present on current main, with no actionable patch findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSubagent cancellation selects owned runs, stops their work, joins controller cleanup, and returns cancellation results to tools and session-reset callers. flowchart TD
A[Stop or session reset] --> B[Subagent kill selection]
B --> C[Kill scope]
C --> D[Source settlement]
D --> E[Final queued drain]
E --> F[Cancellation result]
E --> G[Skip caller source only]
Technical reviewBest possible solution: Apply the existing self-input predicate at the final drain while preserving external cleanup joins and current ownership checks. Do we have a high-confidence way to reproduce the issue? The existing after-turn self-disposal row and main’s final drain establish the circular wait; contributor-supplied standalone traces show the matching base/candidate differential, without executing target code during this review. Is this the best way to solve the issue? This is the smallest complete repair for the reported self-join: it reuses the same source-identity predicate as the earlier settlement owner and changes no cancellation authority. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7e825b4d3840. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +4, Tests +65. Total +69 across 2 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: No label changes. Label justifications:
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 HistoryReview history (10 earlier review cycles; latest 8 shown)
Reviewed November 8, 2026, 12:38 AM ET / 05:38 UTC (Revision 11). |
The issue's post-fix expectation allows asserting that no drain-deadline error occurs once the self source is excluded.
|
Re-review request — the reviewed head was Two points on the earlier review:
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…ed clock Replace the wall-clock race guard with a fake drain clock so the regression controls time rather than measuring scheduling, and leaves no timer scheduled after a passing run.
|
New evidence class — the defect is measurable in the repository's own shipped test suite, on a row that predates this PR. Row: The row loses exactly one Added to the PR body as §1b, alongside the controlled-clock regression (§1) and the Gateway product-path artifact (§2). @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Consolidated decision packet (no new asks of the bot — this is for a maintainer). One-line case: the repo's own test row Patch: adds the existing Why the bot's remaining ask cannot be met: it wants terminal output of "Stop awaited during pending raw disposal" through the production boundary. That state requires the kill to be issued from inside the source's own async context while its disposal is held. No shipped entry produces it — Two options, your call: (a) accept the layered evidence — controlled-clock differential + project-owned row timing + Gateway product trace — as satisfying the gate for this defect class; or (b) name the artifact shape you would accept and I'll build it. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Final evidence record: shipped-entry reachability map for this defect. No new asks and no re-review request — nothing here changes the branch. The review has been holding on two things: whether a shipped entry can produce the stalled self-join, and whether one can show the drain-deadline error being swallowed. I traced both to source and ran two controlled probes inside the repository's own Gateway product fixture. Neither state is reachable from a shipped entry, so no base-vs-head product artifact exists for either half. All line references are current head 1. Kill-tree selection is strictly downward. Roots are only runs listed for the scope key — 2. Only three production sites bind a controller source, and none issues that kill. 3. Every shipped Stop entry is guarded away from its own session. The 4. The drain deadline is reached only on the deferred-custody path, which already reports. 5. Probes run today, inside that product fixture with the child's cleanup held pending, on a controlled clock. 6. No shipped knob shortens the window. What this leaves. The defect is a lifecycle-ordering contract break whose only observable consequence today is the repository's own shipped row waiting out one full drain window: |
|
Proof gate addressed — new §4 Standalone production-boundary trace in the PR body. Responding to the single
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
New evidence class added (§5 of the PR body). Requesting one fresh review on that basis — not a status ping. Revision 10 cleared every contributor-facing item (
Head, diff, labels and exact-head CI are unchanged: this is a body-only evidence addition (52 pass / 61 path-scoped skips / 0 failures). Reason for a second review inside 24 h: a genuinely new evidence class (independent built base/candidate trees plus the shipped entry point), not a repeated request. No further re-requests will be made unless a review names a concrete item. Limits are restated in §5: this remains an in-process production-boundary observation, not a Gateway-level user-flow differential. No shipped CLI can produce the held-disposal state — §2 shows the reachable Gateway self-cancel variant aborts the live turn and releases the source settlement promptly on base as well. Scratch paths are redacted; no credentials, IPs, phone numbers, or non-public endpoints appear. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Closes #189376
What Problem This Solves
Fixes: a subagent Stop issued from a source's own raw cleanup waits out the 15-second session-controller drain deadline and then reports success. The cleanup itself is waiting on Stop, so the two await each other until the deadline fires.
User Impact
Stop from a subagent's own cleanup path returns promptly instead of stalling ~15 s. The queued-drain error is no longer incurred on this path at all (asserted below), per the issue's post-fix expectation.
Why This Change Was Made
settleQueued(post-kill settlement walk) excluded the caller's current operation from the queued drain but not the caller's own raw source, then awaitedcapturedExecution.execution.input.settlement.promisefor that self input. The sibling source-settlement owner (settleSubagentKillSources) already excludes this input correctly viaisCurrentSessionControllerTurnInput; this change applies the same exclusion at the queued-drain boundary — the issue's first-named resolution ("the later scope drain should exclude that source, as the earlier settlement owner already does").Scope note: the issue lists self-join refusal/report as an alternative, and its Notes say the fixed row "should run in milliseconds and could assert that no drain-deadline error occurs" — asserted. The described test-only replacement-fixture row is the issue author's separate test-only follow-up (#189394).
Evidence
1. Dispatch regression (RED/GREEN, controlled clock)
New regression in
src/agents/subagents/registry/subagent-control.accepted-stop.test.ts: a terminal subagent whose raw disposal is held, with Stop issued inside that source's own async context. It runs on a controlled (fake) drain clock and leaves no timer scheduled.upstream/main, source restored in-tree): Stop never settles before the fake deadline —AssertionError: expected false to be true(exit 1).{ status: "ok" }, andresult.errorcontains no drain-deadline text.Focused suites:
accepted-stop+kill-settlement+publication3 files / 42 tests pass.tsgo:coreclean;oxlint0/0 andoxfmt --checkclean on both changed files.1b. Project-owned regression row: measured drain-deadline differential
The defect is observable in the repository's own shipped test suite, on a row that predates this PR (present identically on
upstream/main). Row:normal terminal cleanup preserves exact Stop ownership (self-disposal after turn completion, afterCleanup=true)insubagent-control.accepted-stop.test.ts.Command (same file, same row, only
subagent-control-kill-scope.tsdiffers):The affected row loses exactly one
SESSION_CONTROLLER_DRAIN_TIMEOUT_MS(15 s) and lands in line with its seven sibling rows (~2.2-2.4 s of shared fixture overhead); the suite total drops by 15,836 ms. This is the acceptance signal the issue's own Notes predicted:Once this is fixed, the row should run in milliseconds. No author-added scaffolding is involved — the row, the held raw disposal, and the Stop call all come from the existing suite.2. Gateway product-path artifact (redacted)
A real Gateway process ran the bundled Matrix plugin against a local fake homeserver; one room message entered through the real sync ingress and reply pipeline (channel runs bind gateway subagents). The scripted model then executed the reachable self-cleanup variant through shipped tools: main turn →
sessions_spawn; the child turn →subagents list→subagents cancel <own runId>from inside its own controller turn, with the kill executed by the shippedsubagentstool.Base comparison for this reachable variant is also prompt (~18 ms): cancelling a run from its own live turn aborts the turn, so the product path releases the source settlement quickly. The stalled join the issue reports needs the raw disposal to stay pending while the Stop awaits it — that held-disposal state is exactly what the controlled-clock regression pins (base fails, head passes). The external-cleanup control (Stop from outside still joining disposal) is covered by the existing
lifecycle cleanup joins terminal controller disposalrow, passing.AI disclosure: generated and automatically reviewed with Qoder.
3. Live proof capture — held-disposal fault through the production boundary (RED → GREEN)
The held-disposal fault is exercised through the real production boundary:
killSessionSubagentRunsis driven from insidewithSessionControllerSource(owner.input, …)— the source's own raw cleanup — with the real subagent registry, real session-controller settlement, and the real SQLite state worker (no mocked fix path). Only downstream gateway RPC/announce are mocked, which sit outside the repairedsettleQueuedboundary.Run on this PR's head commit
afcfa58c1b(isolated forks pool so the state worker opens on the main thread):Full
accepted-stopsuite on head — all self-disposal + external-cleanup-joining controls pass:Reverting the single fix line
!isCurrentSessionControllerTurnInput(capturedExecution.execution.input) &&insettleQueuedto reproduceupstream/mainbehavior, the same scenario FAILS:drainedstaysfalse: the self-issued Stop never settles before the 15 000 ms drain deadline — exactly the held-disposal fault. This isolates the repaired failure condition through the production boundary (the Gateway self-cancel path, by contrast, passes on both base and head because aborting the live turn releases the source settlement quickly).Prompt recovery: on head,
drained === trueunder the controlled drain clock — Stop returns before the deadline (no queued-drain error;result.errorcontains no drain-deadline text).External cleanup joining preserved: the fix keeps the existing controller predicate at the final drain, so external Stop callers still await cleanup. In the same passing suite the external-cleanup-joining controls pass (e.g.
lifecycle cleanup joins terminal controller disposal,normal terminal cleanup preserves exact Stop ownership (…)— 24 passed).settlement.statusremains"pending"after the self-source returns, confirming external custody is not weakened.No credentials, IPs, phone numbers, or non-public endpoints appear in this output (
<home>/paths redacted).4. Standalone production-boundary trace — real wall-clock RED → GREEN
This section answers the review's two objections directly: it is not a Vitest assertion and not the Gateway self-cancel variant that also succeeds on base. It is a standalone process that drives the shipped production entry
killSessionSubagentRuns(the same entrystopSessionResetSubagentscalls) against the real subagent registry, real session-controller settlement, and the real SQLite state worker in a scratch state dir.Method
node --import ./scripts/tsx.mjs, outside any test runner: novi, no fake timers, no mocked gateway / state worker / announce modules. Real wall clock, realsetTimeout, real deferred promises.registerSubagentRun; a real controller source is registered through shippedregisterChatAbortController; the source enters realwithSessionTurnand its raw disposal is held (releaseTailis resolved only after Stop is observed).captureSubagentExecutionis used as a pre-flight to prove the production boundary actually binds the held source to this run (captured: true,sameInputAsCaller: true).withSessionControllerSource(owner.input, …)— the source's own raw cleanup — via the shipped entry:settleQueued:!isCurrentSessionControllerTurnInput(capturedExecution.execution.input) &&. The file is restored afterwards; the PR diff is unchanged.settlesWithin(..., { ref: false })(an unref'd timer). In production the Gateway listener / state worker keeps the event loop alive so the deadline is observable. The standalone process supplies the equivalent long-lived service handle explicitly; the 15 000 ms deadline is neither mocked nor shortened.afcfa58c1bdbde105076180d8c047319c54c8a12(fix/189376-subagent-stop-self-source-drain). Node 26.12.1, macOS arm64.A. Held-disposal fault and prompt recovery (self-source Stop)
HEAD (this PR):
BASE (single fix line reverted):
The BASE Stop is held for 16 559 ms and HEAD returns in 1 746 ms: a 14 813 ms HEAD→BASE delta, i.e. one full
SESSION_CONTROLLER_DRAIN_TIMEOUT_MS(15 000 ms) within normal run-to-run variance.DERIVED.deadlineElapsedistrueon BASE andfalseon HEAD, emitted by the shipped 15 000 ms constant rather than a guessed threshold. Both returnstatus: "ok"with no error text — this is exactly the issue's complaint ("Stop then returns success, and the drain-deadline error is never reported"), so thedrain-deadline fault observed = falseline is the silent-success fault, not an absence of the stall.source settlement still held at Stop return = truein both confirms the Stop returned while its own raw disposal was still pending.B. External cleanup joining preserved (sibling invariant / over-exclusion control)
A second standalone run calls the same shipped entry without any source context (an external cleanup caller), while the source's raw disposal is still held. The held disposal is released 2.5 s later, after the external Stop is confirmed still pending. Both HEAD and BASE must still wait for and join that source.
HEAD (this PR):
BASE (single fix line reverted):
externalStopWaitedForHeldSource: trueandjoinedBeforeDeadline: trueon both heads: the external Stop was still pending at release time and completed immediately after the source's raw disposal joined. The new predicate therefore excludes only the caller's own source; it does not weaken external cleanup custody.sourceTurnCompleted: truein both.Result table
okokstatuson both self-source runsokokLimits / not tested: downstream Gateway RPC, announce delivery and channel adapters are not exercised by this standalone trace (they sit outside the repaired
settleQueuedboundary and are covered separately by §2's Gateway artifact and §1/§3's suites). No real network channel, credential store, or user data is involved. Timestamps include one-off process startup (module + SQLite worker bootstrap, ~15-19 s) which is identical in all four runs and is excluded from the measurement:STOP RETURNEDreports only thekillSessionSubagentRunscall elapsed.Redaction: all scratch state-dir paths are replaced with
<scratch-state-dir>; no credentials, IPs, phone numbers, hostnames, or non-public endpoints appear in the output above.5. Independent base/candidate builds through the shipped reset entry point
Section 4 used a one-line revert inside a single process. This section removes that limitation: two independently checked-out source trees, each in its own OS process, each loading only its own shipped source, both driven through the shipped production caller
stopSessionResetSubagents— the/resetcleanup owner that invokes the repairedkillSessionSubagentRunsboundary.Construction
afcfa58c1bdbde105076180d8c047319c54c8a12, clean (git status --shortempty).settleQueued:!isCurrentSessionControllerTurnInput(capturedExecution.execution.input) &&. Itsgit diff --shortstatis1 file changed, 1 deletion(-). No other source, test, config, or lockfile differs between the trees; both resolve the same dependency tree. The single independent variable is the shipped source line.PROOF_ROOTselecting the source root. No process imports a module from the other tree. As in §4: novi, no fake timers, no mocked gateway / announce / state-worker modules; the real subagent registry, session-controller settlement and SQLite state worker run in a fresh scratch state dir per process.settlesWithin(..., { ref: false })); each process keeps the equivalent long-lived service handle. The 15 000 ms deadline is neither mocked nor shortened.Commands (tree paths redacted; Node 26.12.1, macOS arm64):
CANDIDATE:
BASE:
Result
stopSessionResetSubagentselapsedDERIVED.deadlineElapsedstopped / failedtrue0 / 0okfalse0 / 0okThe BASE→CANDIDATE difference is 14739 ms, i.e. one shipped
SESSION_CONTROLLER_DRAIN_TIMEOUT_MS(15 000 ms) within normal run-to-run variance. Both trees return{stopped: 0, failed: 0}with no thrown error — the silent-success fault described in #189376 — andsource settlement still held at Stop return = truein both, so the decisive observation is the real wall-clock deadline, not a return-code difference. Both trees release and join the held source afterwards (EXTERNAL CLEANUP JOIN result: "ok"), so external cleanup custody is unchanged by the fix. §4's separate external-caller control remains the sibling invariant.The PR diff, reviewed head, and exact-head CI are unchanged by this section: it adds evidence only, via
gh pr edit --body-file.Limits / not tested: this is an in-process production-boundary observation, not a Gateway-level user-flow differential; downstream Gateway RPC, announce delivery and channel adapters are not exercised here (they sit outside the repaired
settleQueuedboundary and are covered by §1–§3). The held-disposal state cannot be produced by any shipped CLI command: §2 shows the reachable Gateway self-cancel variant aborts the live turn and releases the source settlement promptly on base as well. One-off process startup (module + SQLite worker bootstrap) is included in the absolute timestamps but excluded fromSTOP RETURNED, which measures only the shipped entry call.Redaction: scratch state-dir and tree paths are replaced with
<scratch-state-dir>/<candidate-tree>/<base-tree>; no credentials, IPs, phone numbers, hostnames, or non-public endpoints appear above.