Repository navigation
fix(auto-reply): retire queued cancellation ownership when execution freezes - #118359
wangyan2026 wants to merge 1 commit into
Conversation
|
Codex review: needs changes before merge. What this changesRetire queued turns’ cancellation ownership when execution freezes, including terminal preflight failures and aggregate turns. Example: A queued successor is finalizing its reply when chat.abort targets its runId.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR: current main still lacks freeze-time queued cancellation retirement, and the patch follows the maintainer-approved repair boundary. No introduced correctness defect was found; GitHub reports a merge conflict. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe reply executor passes terminal lifecycle facts through queued-turn callbacks to the Gateway registry, which decides whether chat.abort can still cancel each run. flowchart LR
A[Queued chat turn] --> B[Followup execution]
B --> C[Terminal freeze]
C --> D[Cancellation retirement lifecycle]
D --> E[Gateway queued registry]
F[Chat abort request] --> E
E --> G[Reject late abort]
B --> H[Delivery and settlement]
Technical reviewBest possible solution: Preserve the freeze-time retirement repair while integrating aggregate callbacks into main’s existing createAggregateDelivery owner. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the missing retirement handoff, and the contributor supplies Gateway traces and an execution-owner control; no target code was run during this read-only review. Is this the best way to solve the issue? The repair uses the existing lifecycle at the authoritative freeze boundary and preserves retryable pre-start cancellation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 31549178da4d. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +74, Tests +1745. Total +1819 across 10 files. Added test files: 4. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (68 earlier review cycles; latest 8 shown)
Reviewed October 15, 2026, 11:50 PM ET / October 16, 2026, 03:50 UTC (Revision 69). |
9d6b84c to
0e64bc0
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
0e64bc0 to
01a8e61
Compare
2dda42c to
abcc441
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
90cdaad to
27af1f7
Compare
27af1f7 to
ad88e2a
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
5 similar comments
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
…freezes (openclaw#118028) When an auto-reply follow-up run reaches its terminal freeze boundary (commitTerminalOutcome), its Gateway cancel entry must retire so that a late chat.abort is rejected rather than falsely marking the finalizing run as aborted while delivery completes. - Retire followup cancellation in commitTerminalOutcome after freezeAbort using the shared hasReplyOperationExecutionStarted state (maintainer Rank-up move: no local executionStarted tracking) - Retire queued cancellation in the terminal preflightFailurePayload branch in followup-turn-execution.ts (preflightError is retryable and stays abortable) - Extract buildOverflowSummaryTurnAdoptionLifecycle and buildCollectGroupTurnAdoptionLifecycle to drain-lifecycle.ts, both with onCancellationRetired that retires real sources on freeze - Always attach overflow summary turnAdoptionLifecycle regardless of onAdmitted, so singleton cancel-only overflow sources (where needsAdmission=false sets onAdmitted=undefined) also receive freeze-time retirement - Add lifecycle unit test for cancellation retirement on freeze, including a singleton cancel-only overflow source (1 dropped source, not 2) to exercise the onAdmitted=undefined path - Add Gateway harness proof that late chat.abort returns aborted=false - Add E2E proof with real ephemeral Gateway and held mock provider - Replace fixed sleep in E2E with state-based active-run barrier (waitForChatRunActive: state=status, phase=starting_model) Closes openclaw#118028
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Related to #118028 (does not close — remaining terminal pre-start paths tracked there)
What Problem This Solves
After
chat.sendterminalizes, auto-reply queued followup runs keep their Gateway queued-cancel entry registered and still abortable, so a latechat.abortreports a finalizing run as aborted. Retire Gateway cancellation ownership through the existingonCancellationRetiredlifecycle when execution freezes.The maintainer-clarified production path (from closed PR #118057):
chat.abortafterchat.sendterminalize reaches the queued run throughabortQueuedChatTurnById(chat-abort-handler.ts:241), which checks only the entry's ownabortableflag (chat-queued-turns.ts:156) and never consultsisReplyRunAbortableForSignal. Execution freeze (freezeAbort) never retired the Gateway cancel entry, so finalizing runs could still be marked aborted — while synthetic aggregate owners (overflow summary, collect groups) had noonCancellationRetiredat all.Root Cause
mergeRunSignalinsrc/agents/embedded-agent-runner/stream-resolution.ts:278composescallerSignalandrunSignalwithAbortSignal.any(...)when both exist and differ (#117731,7c1d5dc7ef). The composite signal is handed to provider transports, which report request activity vianotifyLlmRequestActivity(options.signal); the idle watchdog subscribes with its ownstreamAbortController.signal(llm-idle-timeout.ts:530-533). The activity registry is aWeakMap<AbortSignal, Set<...>>keyed by exact signal identity, so watchdog activity is lost.For queued followups specifically, the maintainer clarified (#118057) that the production
chat.abortroute goes throughabortQueuedChatTurnById(chat-abort-handler.ts:241), checking the entry'sabortableflag, notisReplyRunAbortableForSignal. Execution freeze never retired the entry, so the finalizing run stayed abortable.Canonical Repair
retireFollowupRunCancellation(executionParams.followupRun)insidecommitTerminalOutcomeinagent-runner-execution.ts, but only when execution has actually started — implemented using the sharedhasReplyOperationExecutionStarted(executionParams.replyOperation)state (maintainer Rank-up move, no localexecutionStartedtracking). This closes the queued abort gate (entry.abortable = false) for individual followups, execution-started failures, and active/queued overlap. Pre-start failures (e.g. image resolution) are retryable — the follow-up runner requeues them when execution has not started, so their queued entry must remain abortable.retireFollowupRunCancellation(turn.queued)only inside thepreflightFailurePayloadbranch infollowup-turn-execution.ts, which bypassesexecuteAgentTurnand proceeds directly to terminal delivery. ThepreflightErrorbranch is NOT retired because it is retryable — the queued entry must remain abortable so the follow-up runner can classify it for retry. Normal execution paths are also NOT retired early; they reachcommitTerminalOutcomeat the existing freeze boundary.onCancellationRetiredto the synthetic aggregate lifecycles inqueue/drain.ts—runSyntheticOverflowSummaryand collectdrainGroup— so collect/overflow ownership (which composes yet another signal) retires its real sources when the aggregate run freezes. InrunSyntheticOverflowSummary, the syntheticturnAdoptionLifecycleis now always created (not only whenonAdmittedexists), so singleton cancel-only overflow sources — whererunQueueSummaryDeliverysetsonAdmitted=undefinedbecauseneedsAdmission=false— also receive freeze-time retirement.retireFollowupRunCancellation→onCancellationRetired→retireQueuedChatTurnCancellationchain (queue/types.ts:242,chat-send-handler.ts:425,chat-queued-turns.ts:112); no new registry surface, noisReplyRunAbortableForSignalchanges.Best-fix judgment: retiring at the execution-freeze boundary via the existing lifecycle chain is the narrowest owner boundary, exactly as the maintainer directed in #118057. Registering upstream abort signal aliases (PR #118057's approach) was rejected because the queued
chat.abortpath bypasses that lookup — repairing a registry row the production path never consults does not protect finalizing delivery.User Impact
chat.abort(e.g. a second abort arriving after the turn terminalized).Remaining Terminal Pre-start Scope (P1 Merge Risk)
Terminal pre-start rejections outside the explicit
preflightFailurePayloadbranch remain outside the execution-start retirement guard. These are tracked by the broader linked issue #118028. This PR's bounded repair addresses the execution-freeze boundary and the terminal preflight-failure delivery path; other terminal pre-start rejection paths retain their current behavior under the linked issue.Evidence
Test Cost Report (
--maxWorkers=1wall time + CI seconds)Per writing-tests cost budget, each new or materially changed test file reports measured one-worker wall time and estimated CI seconds. All measurements taken on the contributor host with
node scripts/run-vitest.mjs <file> --maxWorkers=1.test/chat-abort-frozen-queued.e2e.test.ts(new)src/gateway/server-methods/chat.abort-frozen-queued-transport.test.ts(new)src/gateway/server-methods/chat.abort-frozen-queued-execution-owner.test.ts(new)src/gateway/server-methods/chat.abort-frozen-queued-run.test.ts(new)src/auto-reply/reply/agent-runner-execution-contract.test.ts(modified, +67 lines)src/auto-reply/reply/queue/lifecycle.test.ts(modified, +137 lines)No real timers, sleeps, polling, or per-test Gateway/process boots. The transport and E2E tests boot a real Gateway at suite level (shared fixture), not per test. The execution-owner test uses
getExecuteAgentTurnForTest()with shared state teardown. Total new local wall time: ~463s across 6 files; CI estimate ~695s.Adjacent suites green (no new files in these shards):
followup-turn-executionqueue.in-flightqueue.drain-restartchat-queued-turnsPer-File Results
node scripts/run-vitest.mjs --config test/vitest/vitest.e2e.config.ts test/chat-abort-frozen-queued.e2e.test.ts: 1/1 — real ephemeral Gateway E2E proof (real gateway process + held mock provider + realchat.send/chat.abortRPC)node scripts/run-vitest.mjs src/gateway/server-methods/chat.abort-frozen-queued-transport.test.ts: 1/1 — real-Gateway transport proof (real Gateway RPC + held provider + queued successor + late abort during pending delivery)node scripts/run-vitest.mjs src/gateway/server-methods/chat.abort-frozen-queued-execution-owner.test.ts: 2/2 (real execution owner + before-fix control)node scripts/run-vitest.mjs src/gateway/server-methods/chat.abort-frozen-queued-run.test.ts: 6/6 (real-behavior harness + before-fix control + terminal preflightFailurePayload harness + preflightFailurePayload before-fix control + active queued run abortable control + retryable preflightError abortable control)node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-execution-contract.test.ts: 5/5 (incl. freeze-retire regression + pre-start failure retryable regression + started-error retire regression)node scripts/run-vitest.mjs src/auto-reply/reply/queue/lifecycle.test.ts: 7/7 (incl. overflow + collect + singleton cancel-only overflow freeze-retire regression)oxlint(0 errors on changed files)Real-Transport Queued Successor Proof — Late
chat.abortRejected During Pending Delivery (REV 53)src/gateway/server-methods/chat.abort-frozen-queued-transport.test.tsprovides the strongest real-transport proof for the queued followup mode. It exercises a genuinely queued successor (not a direct turn) over real Gateway RPC with real queue admission.Three fixture defects fixed (ClawSweeper Rev 53):
Successor-specific gate (Rev 53 F1): The
commitTurnhook now uses a call counter. The predecessor'scommitTurn(1st call) acknowledges immediately with 204 — the predecessor can finish and the queue can drain. Only the successor'scommitTurn(2nd call) blocks onreleaseAfterTurn, creating the pending-delivery window. Previously the gate blocked everycommitTurn, deadlocking the predecessor.Queued precondition snapshot (Rev 53 F2):
queuedPreconditionis now snapshotted asmodelRequests.length === 1before releasing the predecessor (line 365). The final verdict uses this snapshot, somodelRequestCount: 2andqueuedPrecondition: trueare no longer contradictory. Previously the precondition was calculated from the final request count, which is always 2.Valid commitTurn acknowledgement (Rev 53 F3):
commitTurnnow returns{ status: "committed" }as required by the production outbox (context-engine-turn-outbox.ts:471-477). Previously it returnedundefined, causing the outbox to throw"context engine does not implement commitTurn"and retain the pending turn.Two-turn queued admission pattern (addresses ClawSweeper Rev 50 finding):
chat.send→ provider holds the request → first turn becomes the active runwaitForRunActive(events, firstRunId)→ synchronizes on Gateway's real "starting_model" status event (session is now active)chat.send→resolveActiveRunQueueActionreturns"enqueue-followup"(session is active) → registers Gateway queued cancellation entryqueuedPrecondition = modelRequests.length === 1→ queued precondition: second turn is waiting in the followup queue, not running concurrentlycommitTurnacknowledges immediately → predecessor finishes → queue drains → followup starts executingcommitTerminalOutcome→retireFollowupRunCancellation→retireQueuedChatTurnCancellation→entry.abortable = falsecommitTurn(2nd call) blocks via HTTP POST → pending-delivery windowchat.abortfor the followup → rejected (aborted: false) becauseentry.abortable === falsecommitTurn→ delivery completesThis is the exact scenario ClawSweeper Rev 50/53 required: "Hold a first turn, enqueue a successor, and target that successor during its pending-delivery interval."
Regression control: The execution-owner test (
chat.abort-frozen-queued-execution-owner.test.ts) provides the before-fix control that verifies the regression fails when terminal retirement is removed (same execution path withonCancellationRetiredas no-op →aborted: true).Transcript persistence: The test verifies the followup reply is durable in the transcript before abort, is not marked as aborted after the rejected abort, and survives a Gateway close/reopen cycle.
Real Execution Owner Proof — Late
chat.abortRejected During Pending Deliverysrc/gateway/server-methods/chat.abort-frozen-queued-execution-owner.test.tsfills the gap identified by ClawSweeper: the E2E test sends abort after final delivery, and the separate harness manually retires the entry. Neither proved that the changed execution owner (executeAgentTurn→ realcommitTerminalOutcome) rejects abort while the queued entry remains present and delivery is pending.This test calls the real
executeAgentTurn(viagetExecuteAgentTurnForTest()) with afollowupRunwhoseturnAdoptionLifecycleis wired to real Gateway queued turns (registerQueuedChatTurn,retireQueuedChatTurnCancellation,completeQueuedChatTurn). AfterexecuteAgentTurnreturns:commitTerminalOutcomehas fired (real, not manual) →retireFollowupRunCancellation→onCancellationRetired→retireQueuedChatTurnCancellation→entry.abortable = falseonSettledhas NOT been called (delivery is still pending)A late
chat.abortis then issued via the realhandleChatAbortRequestWithLifecyclewhile delivery is pending. The abort is rejected becauseentry.abortable === false(produced by the realcommitTerminalOutcome, not manual retirement). The entry remains present after the rejected abort. Only whenonSettledis called (delivery settles) is the entry deleted.Key distinction from prior proof: This test exercises the real
executeAgentTurnproduction function (not a manualretireFollowupRunCancellationcall), and issueschat.abortbeforeonSettled(delivery) is called — proving the changed execution owner rejects abort during the decisive pending-delivery interval, with the queued entry still present andabortable=false.Real Ephemeral Gateway E2E — Late
chat.abortvs Frozen Queued Runtest/chat-abort-frozen-queued.e2e.test.tsruns a real ephemeral Gateway process (createOpenClawTestInstance+startGateway) against a held-back mock provider: the firstchat.sendstays active, the secondchat.sendqueues as a followup and registers its Gateway cancel identity, the first turn is released so the queue drains and the followup terminalizes (freeze + retire), then a latechat.abortRPC is sent. No context construction, no mocked session lookup, no handler-direct invocation — the full gateway wire path is exercised.Queued precondition: Before releasing the held first turn, the test asserts that the mock provider has received exactly one request — proving the second turn is still waiting in the followup queue and has not started executing concurrently.
Proof scope: The E2E proves the terminal state in a real Gateway. The real execution owner test (above) fills the gap by proving the precise internal ordering that distinguishes retirement from deletion during the pending-delivery interval. The harness test (below) proves the retirement-vs-deletion distinction synchronously.
Gateway Real-Behavior Harness — Late
chat.abortvs Frozen Queued RunEnd-to-end harness (
src/gateway/server-methods/chat.abort-frozen-queued-run.test.ts) drives the real production chain with real module implementations — no mocks in the critical path. This harness distinguishes freeze-time retirement from post-delivery deletion by directly inspecting the queued entry map.Four-Tier Proof Architecture
chat.abort-frozen-queued-transport.test.ts(1 test)commitTurngate + valid commit acknowledgement + queued precondition snapshot; abort rejected for the queued successor during pending delivery; transcript persistence verifiedchat.abort-frozen-queued-execution-owner.test.ts(2 tests)executeAgentTurn→ retirement synchronized viaonCancellationRetireddeferred; abort rejected whileentry.present=true,deliverySettled=false; before-fix control proves regressionchat-abort-frozen-queued.e2e.test.tschat.abort-frozen-queued-run.test.tsabortable=false+present=truebefore delivery deletesFreeze-Retire Proof — Production Function (
retireFollowupRunCancellation)Direct call into the production function with real lifecycle objects, proving freeze-time retire fires once per owner and is idempotent (WeakSet in
queue/types.ts:244):Regression Tests
New tests prove freeze-time retire across every owner boundary:
agent-runner-execution-contract.test.ts"retires queued cancellation ownership when execution freezes"executeAgentTurn+turnAdoptionLifecycle.onCancellationRetiredspyagent-runner-execution-contract.test.ts"does not retire queued cancellation ownership on a pre-start failure that is retryable"resolveCurrentTurnImagesfailure +onCancellationRetiredspyagent-runner-execution-contract.test.ts"retires queued cancellation ownership when a started execution throws"runEmbeddedAgentthrows aftermodel_call_started+onCancellationRetiredspyqueue/lifecycle.test.ts"retires all source cancellations when admitted overflow delivery freezes"onCancellationRetiredqueue/lifecycle.test.ts"retires a singleton cancel-only overflow source when the summary freezes"onAdmittedqueue/lifecycle.test.ts"retires all source cancellations when an admitted collect group freezes"chat.abort-frozen-queued-run.test.ts"harness: terminal preflightFailurePayload path retires cancellation before delivery, late chat.abort is rejected"chat.abort-frozen-queued-run.test.ts"harness (before-fix control): without preflight retire, a late chat.abort falsely aborts the terminal preflight-failure run"chat.abort-frozen-queued-run.test.ts"harness: active queued run without early retire remains abortable"After-Fix Runtime Artifact
Key Invariant Verified
Freeze-time retire coverage matrix per owner boundary:
When execution freezes,
abortQueuedChatTurnById's gate (entry.abortable === false, chat-queued-turns.ts:156) is now reachable for finalizing runs, matching the maintainer-clarified canonical fix. Single-source collect groups are untouched becausecreateAggregateCancellationreturns the native signal for a single owner — no composite, no identity mismatch.CI Notes
The
shard:core-tooling-7-hosted-3tsgo-core-test-shards failure ("messaging: 701 test roots exceeds the 700 limit") was caused by this PR adding two new test files insrc/auto-reply/reply/. Fixed by adding the 3executeAgentTurncancellation-retire tests to existingagent-runner-execution-contract.test.tsand the 3 queue collect freeze-retire tests to existingqueue/lifecycle.test.ts— no new files insrc/auto-reply/reply/, so the messaging shard root count stays at 699 (same as before this PR). Tests were placed inqueue/lifecycle.test.ts(43→183 lines, well under the 700-line cap) rather thanqueue.collect.test.ts(grandfathered at 3894 lines; the line-cap ratchet rejects growth).The
shard:auto-reply-reply-state-routingworker crash (exit 137 OOM) is pre-existing and reproducible onmain— it is a CI-environment resource issue with 66+ test files in a singleisolate: falseworker. This PR does not add any new files to that shard.The
scripts/mantis/run-request-telegram.mtsTS error andmantis-telegram-proof.test.tsPython errors are pre-existing — this PR does not touch any mantis or telegram files.Diff Shape
agent-runner-execution.ts+9/-4,followup-turn-execution.ts+7/-0,queue/drain.ts+20/-32, newqueue/drain-lifecycle.ts+86/-0). The lifecycle builders for overflow summary and collect group aggregate owners are extracted todrain-lifecycle.ts, each withonCancellationRetiredthat retires real sources on freeze.agent-runner-execution-contract.test.ts+67/-0,queue/lifecycle.test.ts+137/-0,chat.abort-frozen-queued-execution-owner.test.ts+281/-0,chat.abort-frozen-queued-run.test.ts+299/-0,chat.abort-frozen-queued-transport.test.ts+508/-0,chat-abort-frozen-queued.e2e.test.ts+455/-0).Rebase & Conflict Resolution Notes
Rebased onto current
main(e380a25). No conflicts — all 10 files applied cleanly. TheturnAdoptionLifecycleinrunSyntheticOverflowSummaryis now always created (not conditional ononAdmitted), so singleton cancel-only overflow sources — whererunQueueSummaryDeliverysetsonAdmitted=undefinedbecauseneedsAdmission=false— also receive freeze-time retirement viaonCancellationRetired. TheonSettledlogic inbuildOverflowSummaryTurnAdoptionLifecycle(drain-lifecycle.ts) completes sources unconditionally whenonAdmittedis absent, covering the singleton cancel-only path.CI Repair & Review Resolution Notes (squashed into single commit)
CI Failures Repaired
Line-cap ratchet violations (3 files): Extracted
turnAdoptionLifecyclebuilders to newqueue/drain-lifecycle.ts; extracted cancellation-retire tests to newagent-runner-execution-cancellation-retire.test.tsandqueue.collect-freeze-retire.test.ts. All three original files now at or below their upstream baselines.test/chat-abort-frozen-queued.e2e.test.tsTS error:createDeferrednot exported fromsrc/shared/deferred.js(onlycreateDeferredCoreexists). Fixed by aliasing import.src/auto-reply/reply/agent-runner-execution.tsmax-lines (709>700): Addressed by extractingrecordMessageToolOnlyRunOutcometo new file + implementing maintainer's Rank-up move (sharedhasReplyOperationExecutionStartedstate).ClawSweeper Review Findings Resolved
All actionable findings from the ClawSweeper review are resolved in the current head:
[P1] Preserve the execution-identity callback argument — The
onAgentRunStartwrapper that forwarded onlyid(droppingexecutionIdentityToken) has been completely removed as part of the Rank-up move. The canonical producer now callsparams.opts?.onAgentRunStart?.(runId, admittedRunContext.current?.executionIdentityToken)directly, preserving both arguments.[P2] Use the shared execution-start fact — The local
executionStartedclosure boolean has been removed entirely.commitTerminalOutcomenow queries the sharedhasReplyOperationExecutionStarted(executionParams.replyOperation)state.[P2] Wait for an active-run state instead of sleeping — The fixed
await sleep(1_000)in the E2E test has been replaced withawait waitForChatRunActive(events, firstRunId), which synchronizes on the Gateway's real broadcast event.[P2] Attach overflow retirement independently of admission —
turnAdoptionLifecycleinrunSyntheticOverflowSummaryis now always created viabuildOverflowSummaryTurnAdoptionLifecycle, not conditional onparams.onAdmitted. This covers singleton cancel-only overflow sources whererunQueueSummaryDeliverysetsonAdmitted=undefinedbecauseneedsAdmission=false(1 source, no exclusive admission). The lifecycle builder handlesonAdmitted=undefinedcorrectly:onAdoptedis a no-op,onCancellationRetiredretires all sources, andonSettledcompletes sources unconditionally.ClawSweeper Proof Gap Resolved (Revision 38)
The reviewer identified: "The matching captured body supplies real Gateway terminal output, but abort occurs after final delivery. The separate harness manually retires the entry, so neither proves that the changed execution owner rejects abort while the queued entry remains present and delivery is pending."
Resolved by adding
src/gateway/server-methods/chat.abort-frozen-queued-execution-owner.test.tscalls the realexecuteAgentTurn(which triggers realcommitTerminalOutcome→retireFollowupRunCancellation), wiresonCancellationRetiredto realretireQueuedChatTurnCancellation, and issueschat.abortbeforeonSettled(delivery) is called — proving the changed execution owner rejects abort while the queued entry remains present (abortable=false,present=true) and delivery is pending (deliverySettled=false).ClawSweeper Proof Gap Resolved (Revision 43 — synchronized pending-delivery proof)
The reviewer identified: "Synchronize on execution-driven retirement while holding settlement pending, then release delivery after the abort response; verify the regression fails without retirement."
The previous delta-based E2E approach was removed — ClawSweeper correctly identified that
state: "delta"is emitted from live assistant streaming events (server-chat.ts:1843-1865) beforecommitTerminalOutcomeruns, so it cannot establish the freeze-to-settlement interval.Resolved by rewriting
chat.abort-frozen-queued-execution-owner.test.tswith two tests that follow ClawSweeper's exact pattern:Test 1: "real execution owner rejects late chat.abort during pending delivery (synchronized on retirement)"
registerQueuedChatTurn)onCancellationRetiredto a deferred — this callback fires synchronously insidecommitTerminalOutcome→retireFollowupRunCancellation, providing a deterministic execution-driven retirement barrierexecuteAgentTurn(viagetExecuteAgentTurnForTest()) withmodel_call_startedphase → triggers realcommitTerminalOutcome→ realretireFollowupRunCancellation→onCancellationRetiredfiresentry.abortable=false,entry.present=true,deliverySettled=false(delivery pending)chat.abortvia realhandleChatAbortRequestWithLifecycle(real Gateway handler)aborted=false,runIds=[],entry.present=true(rejected by retirement, not deletion)onSettled→completeQueuedChatTurn) — entry deletedTest 2: "before-fix control: with retirement hook removed, chat.abort succeeds during pending delivery"
onCancellationRetiredas a no-op (retirement hook removed — simulates current main wherecommitTerminalOutcomecallsfreezeAbortbut never retires the queued cancellation)executeAgentTurn(same execution path as Test 1, minus the retirement hook — an apples-to-apples control)entry.abortable=undefined(still abortable),entry.present=true,deliverySettled=falsechat.abortvia realhandleChatAbortRequestWithLifecycleaborted=true,runIds=["queued-control"],controller.signal.aborted=true— the current-main bugThis control does not skip execution — it runs the same
executeAgentTurn→commitTerminalOutcome→freezeAbortpath, with only the retirement hook removed. This is an apples-to-apples comparison: the only difference between Test 1 and Test 2 is whetheronCancellationRetiredretires the queued entry.This satisfies all four ClawSweeper requirements:
onCancellationRetireddeferredonSettlednot called until after abort responseonSettledcalled afteraborted=falseverifiedClawSweeper Proof Gap Resolved (Revisions 50 + 53 — queued successor over real transport)
Rev 50 finding: "this is the only
chat.sendin a fresh session.resolveActiveRunQueueActionreturnsrun-nowwhen the session is inactive and its queue is empty, even withmessages.queue.mode: "followup". Consequently no deferred Gateway cancellation entry is registered, and the asserted rejection exercises direct-turn freeze protection instead of the new queued retirement hook."Root cause confirmed:
queue-policy.ts:43—if (!params.isActive && (!params.queueAdmissionState || params.queueAdmissionState === "empty"))returns"run-now"for a fresh session regardless of followup mode. The previous transport test sent onechat.sendto a fresh session, so the message ran immediately without registering a Gateway queued cancellation entry. The abort rejection exercisedfreezeAbort(), notretireFollowupRunCancellation.Rev 53 findings (three fixture defects in the Rev 50 transport test):
Predecessor blocked by gate: The
commitTurnhook posted to the blocking gate for every turn, including the predecessor. Production awaits that hook before finishing the predecessor, but the test released the gate only after observing the successor. The successor could not reach the asserted interval (deadlock). Fixed: Gate is now successor-specific — the 1stcommitTurncall (predecessor) acknowledges immediately with 204; only the 2nd call (successor) blocks onreleaseAfterTurn.Queued precondition contradiction:
queuedPreconditionwas calculated from the finalmodelRequests.length, while the final assertion required bothmodelRequestCount: 2ANDqueuedPrecondition: true. These cannot both hold. Fixed:queuedPreconditionSnapshotis captured asmodelRequests.length === 1before releasing the predecessor (line 365). The final verdict uses this snapshot.Invalid commitTurn return: After the gate returned,
commitTurnresolved toundefined. The production outbox requires{ status: "committed" }or{ status: "duplicate" }(context-engine-turn-outbox.ts:471-477); otherwise it retains the pending turn. Fixed:commitTurnnow returns{ status: "committed" }.Resolved by restructuring
chat.abort-frozen-queued-transport.test.tswith:chat.send→resolveActiveRunQueueActionreturns"enqueue-followup"(session is active) → registers Gateway queued cancellation entryqueuedPrecondition = modelRequests.length === 1before releasing predecessorcommitTurnacknowledges immediately (gate is successor-specific) → predecessor finishes → queue drains → followup executescommitTerminalOutcome→retireFollowupRunCancellation→entry.abortable = falsecommitTurn(2nd call) blocks → pending-delivery windowchat.abortfor the followup → rejected (aborted: false)commitTurn→ delivery completesThis properly exercises the queued retirement path (
retireFollowupRunCancellation→retireQueuedChatTurnCancellation→entry.abortable = false) over real transport, with a genuinely queued successor (not a direct turn), a successor-specific gate, a valid commit acknowledgement, and a correctly snapshotted queued precondition.AI Assistance