fix(cancel): instant Notify-backed AbortSignal + pin the drop contract - #210
Merged
Conversation
…t (dirge-2mw0) Investigating "a cancelled tool keeps running detached" showed the dispatcher's drop-on-cancel is actually correct: `tokio::select!` dropping the tool's execute future cancels it (no further polls, awaits unwind, RAII guards run — e.g. bash's PgKillGuard SIGKILLs the whole process group). The real shortcomings were responsiveness + an over-pessimistic comment, plus no test pinning the contract. Changes: - AbortSignal is now Notify-backed. `cancel()` notifies waiters; `cancelled().await` resolves the instant cancellation fires (race-free via `Notified::enable()` before the state check). The cheap `is_cancelled()` poll API is unchanged for tools. - wait_for_cancel awaits `cancelled()` instead of a 50ms poll loop — Ctrl+C is now immediate, with no busy-poll. - Corrected the dispatcher comment to state accurately that dropping the future cancels it (and bash kills its group on the drop path); the genuine residual is tools that detach via tokio::spawn, which must abort that work themselves. Tests: AbortSignal.cancelled() resolves-when-already-cancelled + wakes-on-concurrent-cancel; and a dispatcher regression proving the tool future is DROPPED on a mid-execution cancel (RAII drop-flag set, completion flag NOT set) — i.e. no detached execution. 2115 pass under the full feature matrix at -D warnings.
allen-munsch
pushed a commit
to allen-munsch/dirge
that referenced
this pull request
Jun 3, 2026
…ation fix(cancel): instant Notify-backed AbortSignal + pin the drop contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Thread 3, item #9 — dirge-2mw0.
Investigating "a cancelled tool keeps running detached" showed the dispatcher's drop-on-cancel is actually correct:
tokio::select!dropping the tool's execute future cancels it — no further polls, in-flight.awaits unwind, and RAII guards run (e.g. bash'sPgKillGuardalready SIGKILLs the whole process group on the drop path). MCP has no detached spawn either. The real shortcomings were responsiveness and an over-pessimistic comment — plus no test pinning the contract.Changes
AbortSignalis nowNotify-backed.cancel()notifies waiters;cancelled().awaitresolves the instant cancellation fires — race-free viaNotified::enable()before the state check. The cheapis_cancelled()poll API is unchanged for tools.wait_for_cancelawaitscancelled()instead of a 50ms poll loop → Ctrl+C is immediate, no busy-poll.tokio::spawn, which must abort that work themselves.Test plan
AbortSignal::cancelled()resolves-when-already-cancelled + wakes-on-concurrent-cancel.2115 pass under the full feature matrix at
RUSTFLAGS="-D warnings".