← Back to Pull requests

fix: fail the turn when pending cancel cannot be sent #655

Closed
SebTardif closed this pull request without merging on Sep 21, 2026 03:04 UTC
View on GitHub
SebTardif SebTardif commented on Sep 20, 2026 22:08 UTC
Author

What Problem This Solves

Fixes: acpx cancel during queue-owner turn start can be dropped when sending native session/cancel throws, 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

onPromptActive is how the owner applies a cancel that arrived while the turn was still starting. The hook caught that error, so runPromptTurn never saw it. The hook now reports the error and rethrows so the prompt lifetime aborts.

Evidence

Live node run of invokePromptActiveHook:

{
  "reported": "cancel failed",
  "threw": true
}

Command:

pnpm exec tsx _f016-proof.mjs

The cancel failure is both reported and thrown. Previously the same catch reported only when --verbose was set and then swallowed the rejection.

Real behavior proof

  • Behavior or issue addressed: A cancel that arrives while a queued turn is starting could be swallowed if session/cancel threw, leaving the prompt running.

  • Real environment tested: Windows 11, Node v24.19.0, acpx source on this branch, tsx loading src/session/execution/prompt-active-hook.ts.

  • Exact steps or command run after this patch:
  •   pnpm exec tsx _f016-proof.mjs
      

    The script invokes the prompt-active hook with a throwing cancel and prints whether the error was reported and rethrown.

  • Evidence after fix: terminal output from the patched source:
  •   {
        "reported": "cancel failed",
        "threw": true
      }
      

  • Observed result after fix: The hook reports cancel failed and rejects (threw: true). Queue-owner onPromptActive uses this helper, so a failed native cancel no longer continues the turn.

  • What was not tested: A live acpx cancel against a hung ACP agent that rejects session/cancel. The same helper is what the owner calls after session/prompt is written.
  • Diff: 49 lines (+45 / -4) across 3 files Reviewer: steipete Review duration: 296m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.29) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.29 · 49 lines diff across 3 files
    0.29
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.76 · 3 substantive comment(s)
    0.76
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    83%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.234
    Real PR Conversation Timeline
    5 items
    clawsweeper[bot] clawsweeper[bot] commented on Sep 20, 2026 22:08 UTC
    Bot

    <!-- 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 -->

    clawsweeper[bot] clawsweeper[bot] commented on Sep 20, 2026 22:12 UTC
    Bot

    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

  • Add real behavior 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.

  • Complete next step (P2) - Add production-path before/after evidence and a regression covering the reachable pending-cancel failure, accounting for existing admission guards. Terminal output or logs are sufficient; screenshots or recordings are welcome when useful. Redact credentials, private endpoints, IP addresses, and other private data. Updating the PR body should trigger review; otherwise ask a maintainer to comment @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:

  • add P2: This is a bounded cancellation reliability change without evidence of an urgent current-user regression.

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.

  • add 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:

  • 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. (src/session/execution/runtime.ts:948, 607a568ea017)

  • 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. (src/session/execution/runtime.ts:948, 8391082239cc)

  • 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. (src/session/queue/owner-turn-controller.ts:65, 607a568ea017)

  • Propagation reaches lifecycle cleanup: runPromptTurn awaits the prompt-start hook and aborts its lifetime in finally. The surrounding session runtime checks unresolved prompts, attempts bounded cancellation, and retires unresolved connections during cleanup. (src/runtime/engine/prompt-turn.ts:112, 607a568ea017)

  • Supplied proof covers only the extracted helper: The complete supplied body, captured under sourceRevision 4ebe60a0fd1e3c8528545de3f6dcf5764d3bd2af49e6dfa54eb53c3a3c351149, reports a Windows 11/Node 24.19.0 run invoking invokePromptActiveHook with a throwing callback. Its output proves reporting and rejection, but the author explicitly says live queue-owner cancellation was not tested. No embedded script was executed. (607a568ea017)

  • Related merged cancellation work and routing: GitHub verifies https://github.com/openclaw/acpx/pull/636 as merged. Its recorded patch carries the owner signal into retry waits and native admission and changes cancellation ordering. This is relevant overlap, but it does not establish that this PR's exact error-reporting request is already implemented. Recent path history also identifies Peter Steinberger's cancellation and lifecycle work. Some deeper local history objects were unavailable; GitHub commit metadata and patches supplied the focused provenance. (src/session/queue/owner-turn-controller.ts:87, 323191a80ff6)
  • Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Rank-up moves

    Optional improvements that raise the rating; they are not merge blockers.

  • Establish the failing queue-owner scenario against current main and add regression coverage that reaches the production lifecycle.

  • Provide redacted after-fix terminal output showing the real transport failure and resulting turn cleanup.
  • 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 keeps one durable marker-backed review comment per issue or PR.

  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.

  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.

  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.

  • Maintainers can also comment @clawsweeper review to request a fresh review only.

  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.

  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.

  • Maintainers can comment @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 -->

    steipete steipete requested changes on Sep 21, 2026 01:25 UTC
    Changes Requested Reviewer

    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.

    steipete steipete commented on Sep 21, 2026 03:04 UTC
    Contributor

    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.

    Reviewers
    Assignees
    SebTardif SebTardif
    Labels
    risk: low confidence: 84.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 29.3% (LOW) · Higher = larger blast radius
    29.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.0% · Lower = rushed or shallow review
    84.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%
    Repository