The Cx Cancellation Model
321 words1 min read4 subsectionsFrom the README at ft 0.15.21
On this page4
Cx is asupersync's capability and cancellation context. When FrankenTerm
threads it explicitly through a call graph, it preserves typed cancellation,
deadline, budget, and capability state at each audited operation boundary.
What Cx is
A Cx is a token-bearing scope. When you spawn a child task with the canonical
spawn_with_cx wrapper, the child inherits the exact context and effective
capability mask. Cancellation becomes observable through explicit checkpoints
and operation-specific races. Budget-aware sleeps, timeouts, receives, and
locks do not all share identical direct-cancellation wake behavior, so each
wrapper documents its own contract.
What this buys us
- Monotone cancellation authority. Explicit child tasks inherit the
parent's
Cxand effective capability restrictions. Lifetime enforcement still requires owned handles or aJoinSet; aCxby itself does not forcibly terminate a detached future. - Budget-aware primitives with explicit direct-cancel handling. The pinned
asupersync
budget_sleep/budget_timeoutprimitives honor theCxbudget deadline, but do not register a direct-cancellation wake. Callers that need prompt cancellation checkpoint before/after bounded waits or race an explicit cancellation signal, then classify timeout and cancellation from the typed context state. - Auditable shutdown. When the operator hits Ctrl-C, the root
Cxrequests cancellation and owned top-level handles are drained under a bounded budget. Shutdown reports when acknowledgement or independently delegated/blocking work remains unproven instead of claiming that no operation can survive.
Pre-cancel vs mid-flight semantics
asupersync's recv/acquire primitives observe pre-cancel cleanly but not mid-flight by default; a recv that's already past the cancellation check at the moment cancel arrives will complete its current iteration. The project standard for mid-flight cancel responsiveness is the select-race pattern: race the awaited operation against cx.cancelled(). See docs/proofs/runtime-async-cancel-traces.md (Mazurkiewicz cancel-trace classes) for the formal model.
Cancellation is not a circuit-breaker failure
Error::Cancelled is explicitly exempted from circuit-breaker failure counts (ft-gc4hz). Cancelling a request because the operator hit Ctrl-C is not a sign that the downstream system is unhealthy; treating it as one would open the circuit on every clean shutdown.