Amended 2026-10-16 by a-cleanup-is-shielded-within-its-grace: the precedence rule below stands, and the cleanup now runs shielded against a stop, for the host’s grace counted from the strike.

Amended 2026-11-11 by a-guard-acquires: guard ACQUIRE BODY RELEASE applies the same precedence to its release. A returning release discards its own value and restores the body’s outcome; a halting release pre-empts it. The release receives the resource and the body’s four-arm ExitCase, with a witnessed error record under err, but cannot suppress that ending. A halting acquisition runs no release. The examples and implementation names below record the original decision.

Amended 2026-11-13 by runtime values are value closures: the release’s err record is plain data with no witness; a caught failure carries no typed cause.

A failing cleanup pre-empts

guard M { N }: any halt of the cleanup pre-empts the body’s outcome — an ordinary error exactly as a control escape already did. A cleanup that cannot fail the computation is a cleanup whose failures are unreportable.

Decision

  • Precedence, in full. Body returns and cleanup halts → the cleanup’s halt is the outcome. Body halts and cleanup halts → the cleanup’s signal wins, whichever kinds the two are. Body halts and cleanup returns → the body’s signal survives, as before.
  • One rule for both signals, so eval_guard (core evaluator) stops reading the cleanup’s Break: it runs the cleanup, and the body’s result is reachable only through the cleanup’s Ok.
  • Log-and-continue keeps its spelling and loses its privilege. guard M { try N { |err| … } } reports the cleanup’s failure and carries on; guard M { attempt N } swallows it silently. Primitives strict, sugar soft — the soft reading is one keystroke away and is the caller’s to ask for.
  • Typing is untouched. A halt carries no value, so guard still takes its value and route from the body alone and the cleanup still contributes neither.

Why the split rule had to go

The escape half was already this rule: an exit or a stopped job raised in the cleanup propagated, because discarding a stop orphans a process group whose pgid is then lost — never resumable, never reapable. The error half was trap-EXIT folklore. The cleanup’s Err went to stderr as guard: cleanup failed: … and the body’s result stood.

Its cost is the thing this language exists to refuse. A guard whose cleanup releases a lease, commits a staging file, or unmounts a directory is doing work the program depends on; when that work failed, a caller reading the exit status saw success, try could not catch it, ? could not fall through on it, and audit recorded no failure — the diagnostic went to a stream with no structure and no reader. A shell that reports a failure only in prose has not reported it.

The asymmetry was unmotivated besides. The two signals differ in what catches them, not in whether the cleanup got to the end of its work.

Consequences

  • A failing cleanup is now catchable by try, visible in an audit tree, and present in the process exit status: the three places a failure belongs.
  • A program that wants its old behaviour says so in its own text, where a reader can see the decision instead of inferring it from a form’s folklore.
  • docs/SPEC.md §8.7 and §17.8 state the single rule, and failure states its precedence beside try and attempt.
  • a_cleanups_fail_pre_empts_an_exit (core/tests/guard_under_exit.rs) carries the new meaning, beside the escape test it is now a second reading of.

Where

guard_release and Frame::Cleanup in core/src/shell/evaluator/machine.rs implement release precedence.

See failure, control-operators, capture (a cleanup’s bytes are chatter, unchanged by this) and core evaluator.