0320.
Automatic Purity & Authority Badges and
--assert-pure / --assert-total
Enforcement
- Status: Accepted (2026-11-28)
- Date: 2026-11-28
- Plan: M29.1
Context
Tenon already models direct external effects and transitive
call-chain witnesses in crates/tenon/src/authority/
(--report=authority) and statically proves eliminated
runtime value checks in tenon_compiler::checks
(--report=checks and checkfree fn).
However, three gaps remained for developers and coding agents:
checkfree fncallee loophole:checkfree fnonly verifies that no unproved runtime checks remain inside the annotated function's own body; calling a helper with an unproved divide, bounds, overflow, slice, or shift check silently bypassed total-function intent.- No structured authority report or automatic API purity
badges:
--report=authorityemitted text only,tenon doc --cardreported capability names without a cleanpure/effectful+totalclassification, andtenon outline --jsonomitted function purity and capability parameter metadata. - No CI/agent enforcement flags: There was no
CLI mechanism on
tenon checkto fail closed when a designated function accidentally gains an external effect or a transitive runtime trap check.
Decision
Rich Static Purity, Authority & Transitive Totality Summary (
crates/tenon/src/authority/):- Added
authority::SummaryandFnAuthorityoverauthority::collect+authority::reach+tenon_compiler::checks. - For each materialized function, computes:
effects: BTreeSet<String>(all reachable modeled effect categories plusunknown.extern),is_pure: bool(effects.is_empty()),local_checks: usize(unproved check sites in the function body),is_total: bool(transitively zero remaining runtime checks across the function and every transitive callee, computed via deterministic reverse-BFS shortest-path reachability),- deterministic call-chain
witnessesfor reachable effects andcheck_witnessfor remaining runtime checks.
- Added structured JSON output
(
schema: "tenon-authority-1") when--report=authorityis combined with--jsonor--diagnostics=json, while keeping existing human--report=authorityoutput byte-for-byte backward-compatible.
- Added
Automatic Purity/Effect Badges in
tenon doc --cardandtenon outline:- Extended
doc_card::ApiItemwithpurity("pure"|"effectful"),total: bool, andeffects: Vec<String>. - Lowered entry files use
authority::summarizefor exact transitive effects and totality; non-entry modules infer effects from capability parameters, local capability-bearing types, and transitiveexterncalls, and infer conservative local totality from transitivecheckfreedeclarations. - Text cards render compact badges (
[pure],[pure, total],[effects: fs, clock],[total, effects: ...]) within existing token budgets; JSON cards include"purity","total", and"effects"on everyfnitem. tenon outline --jsonemits"purity"("pure"|"effectful") and"capabilities"(sorted capability parameter type names, when non-empty) onfnentries while preserving humanoutlineoutput unchanged.
- Extended
CLI Purity & Totality Enforcement (
crates/tenon/src/purity_check.rs):- Added repeatable
--assert-pure <fn>and--assert-total <fn>flags totenon check(supporting both--flag <fn>and--flag=<fn>). - Emits deterministic diagnostics in human or
--jsonformat and exits with status1on failure:E1250: Function asserted pure reaches an external effect, with exact function span and shortest call-chain witness naming the reachable effect and terminal operation.E1251: Function asserted total has a remaining runtime check (in self or a transitive callee), with exact function span and shortest call-chain witness naming the check kind and terminal location.
- Emits a clear usage error (exit
2) if the named function is not found in the checked program.
- Added repeatable
Consequences
- Coding agents and CI pipelines can inspect purity, totality,
and concrete effects directly from
tenon doc --card,tenon outline --json, andtenon check --report=authority --json. tenon check --assert-pure <fn> --assert-total <fn>provides fail-closed regression gates against accidental side effects and transitive runtime traps without requiring language syntax changes.- Existing human
--report=authority, humantenon outline, andtenon doc --check-driftworkflows remain 100% backward-compatible.