fix: fail the turn when pending cancel cannot be sent #655
<!-- clawsweeper-pr-ack:opened item=655 -->
🦞👀
ClawSweeper picked this up.
Pull request received. I will update this pull request when review starts.
<!-- clawsweeper-review-progress:start -->
ClawSweeper review complete
ClawSweeper finished reviewing this revision. The review result is being finalized.
View the workflow run.
<!-- clawsweeper-review-progress:end -->
Codex review: needs real behavior proof before merge. _Reviewed September 20, 2026, 6:11 PM ET / 22:11 UTC._
ClawSweeper review
What this changes
The PR makes prompt-start hook failures propagate into turn cleanup and adds focused helper tests.
Merge readiness
⛔ Blocked before merge - 2 items remain
Keep open: the error-propagation change is not implemented on main, but the supplied helper trace does not establish the claimed queue-owner failure or its recovery. Existing cancellation admission guards make production-path evidence particularly important.
Priority: P2
Reviewed head: 607a568ea017b2e204af254f9b7e781934d7c0f0
Review scores
| Measure | Result | What it means |
|---|---|---|
| Overall readiness | 🦪 silver shellfish (2/6) | The small patch has no identified introduced correctness defect, but its helper-only evidence leaves the central runtime claim unverified. |
| Proof confidence | 🦪 silver shellfish (2/6) | Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the Windows terminal trace exercises only the extracted helper with a throwing callback, not the queue owner, real ACP transport, or observed turn cleanup. A redacted production-path trace with an injected cancel-write failure can satisfy this internal reliability requirement. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review. |
| Patch quality | 🐚 platinum hermit (4/6) | No actionable review findings were identified. |
Verification
| Check | Result | Evidence |
|---|---|---|
| Real behavior | Needs proof | Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the Windows terminal trace exercises only the extracted helper with a throwing callback, not the queue owner, real ACP transport, or observed turn cleanup. A redacted production-path trace with an injected cancel-write failure can satisfy this internal reliability requirement. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review. |
| Evidence reviewed | 7 items | Pinned introduced change: The introduced delta contains only the hook helper, its runtime call site, and two helper tests; unrelated main-branch documentation changes are excluded.<br>Main and release comparison: Fetched main still catches and logs onPromptActive failures without rethrowing. The relevant execution runtime, turn controller, and prompt-turn files are identical between fetched main and v0.18.0; the proposed propagation change is absent from both.<br>Existing cancellation guards complicate the reported trigger: A pending cancellation already aborts the owner's turn signal. The runtime checks that signal before each attempt and passes it into native prompt admission; AcpClient checks authority again before dispatch. A helper callback that throws does not demonstrate how a starting cancelled turn bypasses these guards. |
| Findings | None | None. |
| Security | None | None. |
How this fits together
The acpx queue owner serializes prompts and delivers cancellation requests to an ACP agent. Its prompt-start hook applies pending cancellation, while the execution runtime manages turn completion and connection cleanup.
flowchart TD
A[CLI cancel request] --> B[Queue owner]
B --> C[Turn cancellation state]
C --> D[Prompt-start hook]
D --> E[ACP cancel transport]
E --> F{Send fails}
F --> G[Propagate error and clean up turn]
Before merge
@clawsweeper re-review.<details>
<summary><strong>Agent review details</strong></summary>
Security
None.
Review metrics
| Metric | Value | Why it matters |
|---|---|---|
| Production and test delta | production +17/-4, tests +28/-0 | The production growth extracts error propagation into a helper; both new tests exercise that helper rather than the queue-owner lifecycle. |
Technical review
Best possible solution:
Keep cancellation failure handling in the existing turn lifecycle, with regression coverage demonstrating a reachable failure and completed cleanup through the queue owner.
Do we have a high-confidence way to reproduce the issue?
Unclear: the swallowed hook exception is visible in source, but the claimed continuing prompt has not been demonstrated through current main's queue owner, which already aborts pending cancellation and guards prompt admission.
Is this the best way to solve the issue?
Unclear: propagating lifecycle-hook failures is a narrow implementation, but a production-path regression must establish what remains broken despite the existing cancellation guards.
AGENTS.md: found and applied where relevant.
Codex review notes: model internal, reasoning medium; reviewed against 8391082239cc.
Labels
Label changes:
P2: This is a bounded cancellation reliability change without evidence of an urgent current-user regression.rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the Windows terminal trace exercises only the extracted helper with a throwing callback, not the queue owner, real ACP transport, or observed turn cleanup. A redacted production-path trace with an injected cancel-write failure can satisfy this internal reliability requirement. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.Label justifications:
P2: This is a bounded cancellation reliability change without evidence of an urgent current-user regression.rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the Windows terminal trace exercises only the extracted helper with a throwing callback, not the queue owner, real ACP transport, or observed turn cleanup. A redacted production-path trace with an injected cancel-write failure can satisfy this internal reliability requirement. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.Evidence
What I checked:
src/session/execution/runtime.ts:948, 607a568ea017)src/session/execution/runtime.ts:948, 8391082239cc)src/session/queue/owner-turn-controller.ts:65, 607a568ea017)src/runtime/engine/prompt-turn.ts:112, 607a568ea017)src/session/queue/owner-turn-controller.ts:87, 323191a80ff6)Likely related people:
Rank-up moves
Optional improvements that raise the rating; they are not merge blockers.
Rating scale
| Score | Internal tier | Crab rank | Meaning |
|---:|:---:|---|---|
| 6/6 | S | 🦀 challenger crab | Exceptional readiness |
| 5/6 | A | 🦞 diamond lobster | Very strong readiness |
| 4/6 | B | 🐚 platinum hermit | Good normal PR; ordinary maintainer review |
| 3/6 | C | 🦐 gold shrimp | Useful, but confidence is limited |
| 2/6 | D | 🦪 silver shellfish | Proof or implementation needs work |
| 1/6 | F | 🧂 unranked krab | Not merge-ready |
| N/A | NA | 🌊 off-meta tidepool | Rating does not apply |
Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.
Workflow
@clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.@clawsweeper review to request a fresh review only.@clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.@clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.</details>
<!-- clawsweeper-verdict:needs-human item=655 sha=607a568ea017b2e204af254f9b7e781934d7c0f0 confidence=high updated_at=2026-09-20T22:09:11Z reviewed_at=2026-09-20T22:11:07.930Z lease_owner=github-run-35540738712-1 lease_comment_id=5753027957 source_revision=4ebe60a0fd1e3c8528545de3f6dcf5764d3bd2af49e6dfa54eb53c3a3c351149 live_verification=absent -->
<!-- clawsweeper-review-state:blocked item=655 sha=607a568ea017b2e204af254f9b7e781934d7c0f0 v=1 -->
<!-- clawsweeper-review-version item=655 reviewed_at=2026-09-20T22:11:07.930Z sha=607a568ea017b2e204af254f9b7e781934d7c0f0 source_revision=4ebe60a0fd1e3c8528545de3f6dcf5764d3bd2af49e6dfa54eb53c3a3c351149 lease_owner=github-run-35540738712-1 lease_comment_id=5753027957 v=1 -->
<!-- clawsweeper-review item=655 -->
Please provide a current-main production-path reproduction before we change this lifecycle hook. The catch exists, but the reported startup cancellation scenario appears to be covered by https://github.com/openclaw/acpx/pull/636.
When cancellation arrives before a native prompt is active, QueueOwnerTurnController.requestCancel() both marks pending cancellation and aborts the waiting turn signal. Current runtime checks that signal before attempts and passes it to prompt authority; the client rechecks authority at dispatch and at the queued transport write. Cancellation after a native prompt is active takes the direct active-cancel path.
I reran node --test dist-test/test/session-close-checkpoint.test.js dist-test/test/queue-retry-cancel.test.js dist-test/test/owned-controls.test.js: all 14 passed, including cancellation in the prompt-admission gap, backoff, active error handling, and unaffected successors.
The new helper test proves that an explicitly throwing callback rethrows. It does not establish how a pending cancellation reaches that hook while bypassing the current admission guards. Please exercise the built CLI or public runtime with a synthetic ACP peer, record prompt/cancel writes, and show a concrete current-main case where an accepted cancel fails to stop the affected turn. Keep the existing completed-response and successor behavior in the regression coverage. Leaving this open for that evidence.
I completed the production-path reproduction myself on current main 4e4dcf5. Closing this as superseded by https://github.com/openclaw/acpx/pull/636.
The proof drives built dist/cli.js against a synthetic ACP peer, holds its session/load response, queues a successor, accepts acpx cancel, then releases the held load. The persisted session journal and the peer's actual wire log show:
{
"acceptedCancel": true,
"cancelledTargetPromptWrites": 0,
"successorPromptWrites": 1,
"turnResults": ["cancelled", "completed"],
"samePeer": true,
"closedPeerExited": true
}
This exercises sessions new, prompt, prompt --no-wait, cancel, and sessions close with isolated HOME/cwd state on macOS / Node 26.8.2. The cancelled turn never crosses the native prompt-write boundary, and its independent successor remains usable. The held load is released before finalization; this does not claim to interrupt an indefinitely stalled load handshake.
The code matches that result: startup cancellation aborts the waiting turn signal, which is checked before attempts, at deferred dispatch, and immediately before the transport write. Later active cancellations take the direct cancellation path. The proposed helper changes an internal callback error path without fixing the claimed CLI scenario, so no additional runtime change is needed here. Thanks for examining cancellation reliability.
steipete
SebTardif
What Problem This Solves
Fixes:
acpx cancelduring queue-owner turn start can be dropped when sending nativesession/cancelthrows, so the prompt still runs to completion.User Impact
User impact: a failed pending-cancel send fails the in-flight turn instead of logging only in verbose mode and continuing.
Why This Change Was Made
onPromptActiveis how the owner applies a cancel that arrived while the turn was stillstarting. The hook caught that error, sorunPromptTurnnever saw it. The hook now reports the error and rethrows so the prompt lifetime aborts.Evidence
Live
noderun ofinvokePromptActiveHook:Command:
The cancel failure is both reported and thrown. Previously the same catch reported only when
--verbosewas set and then swallowed the rejection.Real behavior proof
startingcould be swallowed ifsession/cancelthrew, leaving the prompt running.tsxloadingsrc/session/execution/prompt-active-hook.ts.The script invokes the prompt-active hook with a throwing cancel and prints whether the error was reported and rethrown.
cancel failedand rejects (threw: true). Queue-owneronPromptActiveuses this helper, so a failed native cancel no longer continues the turn.acpx cancelagainst a hung ACP agent that rejectssession/cancel. The same helper is what the owner calls aftersession/promptis written.