Skip to the content.

0014: Declared controls in the sealed verify log, checked by the gate

Status: accepted. Author: drafted by the AI operations agent at Le Chen’s request. Created: 2026-11-10. Revised: 2026-11-10, after two field reviews. Decided: 2026-11-09, accepted by Le Chen (maintainer of record), as written, after three field reviews (the last: accept). Implemented in: (release).

Summary

A package may commit a declaration of its controls, lean-pkg-controls.yaml (controls/1), in three kinds: Lean files that must fail to compile for a mathematical reason (must-fail: a wrong statement, a removed hypothesis), files that must compile and prove wrong variants false (refutes), and files that must simply compile cleanly (compiles: audit printouts, a consumer example). The lower-tier verify script runs every declared control after the build, with the lean of the package’s toolchain, and appends a controls/1 section to the sealed verify log, the way the hypotheses section (hyp-probe/1) is appended today. The section is covered by the receipt’s report_sha256; the receipt schema does not change. gate, gate --check and receipt check re-judge the section at the gated commit from the recorded facts and refuse a receipt whose package declares controls when the section is missing, does not match the declaration, or records a failure. page, status and the catalog show the counts, never the files. A package without the declaration is unaffected.

Motivation

A receipt certifies the build, the sorry count, the axioms and, per claim, the axioms of each claim’s declaration. It says nothing about the controls some companions keep beside their proofs. A field report (2026-11-09) describes a paper companion with 68 must-fail controls, 30 refutations and 26 audit files, run by the package’s own script: a reader of the receipt cannot see that the controls exist, let alone that they ran and passed at the certified commit. The results were recorded by hand in commit messages and review notes.

Controls are evidence of a different kind than the build. A must-fail control shows that a statement is not vacuously provable in the package’s setting (a theorem with a contradictory hypothesis would let a wrong variant compile too); a refutation shows that a plausible misreading of the paper is false. Both say something about the statements the comparator tier does not: the comparator checks that the proof proves the Challenge statement, not that the Challenge statement excludes the wrong variants.

The same companion shows how controls pass for the wrong reason, which this design guards against:

Design

The declaration: lean-pkg-controls.yaml

Committed in the package directory, beside claims.yaml:

schema: controls/1
controls:
  - id: neg-drop-homog            # unique, [a-z0-9][a-z0-9-]*
    kind: must-fail               # the file must not compile, for a non-setup reason
    file: controls/DropHomog.lean
    expect: "⊢ False"             # optional: a substring of the first error message (see below)
    targets: [Paper.second_moment_bound]   # optional: package declarations the failing command uses
    note: the bound without the homogeneity hypothesis   # optional, one line
  - id: ref-kappa
    kind: refutes                 # must compile and prove every listed theorem, each a negation
    file: refutations/Kappa.lean
    theorem: [Refutations.kappa_sign_wrong, Refutations.kappa_zero_wrong]
    targets: [Paper.kappa]
    note: kappa with the opposite sign, or zero, is false
  - id: audit-main
    kind: compiles                # must compile: no sorry, standard axioms
    file: Audit/Main.lean

A file belongs to exactly one control: two controls never name the same file, so a file with several negations lists them all in one refutes control.

Messages

The job reads Lean’s messages from lean --json FILE, one JSON object per message with its severity and its kind. For a named error the kind is the error name with a ._namedError suffix (lean.unknownIdentifier._namedError, measured under Lean 4.35); other errors have kinds such as Tactic.unsolvedGoals or [anonymous] (a parse error and a decide refutation both have [anonymous]). The fileName of each object is the path as passed, so every path prefix is stripped from anything recorded from these objects, as from first_error. A message’s text is its whole text, over all its lines. Where JSON output is unavailable, the job splits the plain output on message headers, the regular expression ^<file>:\d+:\d+: (error|warning|info)(\([^)]*\))?: (a tagged header such as error(lean.invalidField): included), and a message ends at the next header of any severity, info: included, so a #check printed after an error is not appended to it. The first error message is the first message of severity error. Lean often puts the generic line first (unsolved goals, Tactic `decide` proved that the proposition) and the evidence of a mathematical failure (⊢ False, is false) on the following lines of the same message; expect is matched against the whole text.

Setup errors

A fixed list lean-pkg ships, of case-insensitive regular expressions and of error names. The regular expressions are matched against the text of every error message, whatever its kind: a kind adds a name to match, it never replaces the text match (a parse error’s kind is [anonymous], like a decide refutation’s, so only its text tells them apart). An error name matches a kind equal to the name or to the name followed by ._namedError:

Pattern or error name What it means
unknown (identifier\|constant\|namespace\|tactic\|module), lean.unknownIdentifier a name that does not exist: a typo, a renamed lemma, a missing import
invalid field, lean.invalidField, lean.invalidDottedIdent a renamed lemma used through dot notation
unexpected token, unexpected end of input a parse error
unknown option, unknown attribute a broken option or attribute
object file .* does not exist an imported module that is not built
\(deterministic\) timeout, deterministic timeout, maximum recursion the elaborator or kernel ran out of heartbeats or depth

A control whose output matches one of them failed, whatever its kind: the file is broken, not refuted. The ctl line records the matched entry. The list grows only through lean-pkg’s upgrade record, so every package means the same by any-error.

The kinds

Negation

A theorem is a negation when, after instantiating its universally quantified binders (instantiateForall over the whole Π-telescope), its type’s head is Not or Ne, or the telescope’s conclusion is False. So ¬ P, a ≠ b, ∀ x, ¬ P x, ∀ x, P x → False and ¬ ∀ x, P x all count; ∃ x, ¬ P x does not (its head is Exists): state it as ¬ ∀ x, P x.

Targets

targets (optional, every kind) names package declarations the control must use. A target must be a declaration of the package’s own library: its declaring module is a module of one of the package’s lean_libs (a package may have several). Where it must occur:

The ctl line records, per target, whether it was found and where: statement or proof of the failing command (must-fail), negation (in a listed theorem’s type or proof) or other (only in another declaration of the file, such as a contrast theorem; refutes, compiles). A refutation whose target occurs only in a contrast theorem passes, and a reader sees that the refuted statement itself does not name the target.

A control without targets passes on its own facts, and page counts it as naming no package declaration, as it counts any-error.

Other keys and rules

The section: controls/1 in the sealed verify log

The verify scripts (receipt slurm --template and the verify.sh that lean-pkg new writes) run the controls after the per-claim axioms and the hypotheses section, before the seal, when the declaration is tracked. Each control runs as lean --json FILE, with:

The job, not Lean, writes the lines:

== lean-pkg controls (controls/1) ==
ctl-decl: {"v":1,"file":"lean-pkg-controls.yaml","sha256":"<64 hex>","controls":124,"toolchain":"leanprover/lean4:v4.35.0"}
ctl: {"v":1,"id":"neg-drop-homog","kind":"must-fail","file":"controls/DropHomog.lean","sha256":"<64 hex>","exit":1,"errors":1,"first_error":"unsolved goals\n⊢ False","setup_error":null,"expect":"matched","targets":{"Paper.second_moment_bound":"statement"},"seconds":3.1,"ok":true}
ctl: {"v":1,"id":"ref-kappa","kind":"refutes","file":"refutations/Kappa.lean","sha256":"<64 hex>","exit":0,"sorry":false,"theorems":{"Refutations.kappa_sign_wrong":{"negation":true,"axioms":["propext"]},"Refutations.kappa_zero_wrong":{"negation":true,"axioms":[]}},"other_axioms":["propext","Quot.sound"],"targets":{"Paper.kappa":"other"},"seconds":2.8,"ok":true}
ctl: {"v":1,"id":"audit-main","kind":"compiles","file":"Audit/Main.lean","sha256":"<64 hex>","exit":0,"sorry":false,"axioms":["propext","Quot.sound"],"targets":null,"seconds":3.4,"ok":true}
ctl-done: {"v":1,"ran":124,"passed":124,"failed":0,"seconds":346.0}

The gate

When lean-pkg-controls.yaml is tracked at the gated commit, gate and gate --check (and receipt check, which re-derives the gate’s checks) require, in the sealed log the receipt binds:

  1. a controls/1 section whose ctl-decl sha256 is the declaration’s at the gated commit;
  2. one ctl line per declared control, each sha256 the control file’s at that commit;
  3. every control passed, re-judged from the line’s facts by the rules above: the setup-error list and expect applied by the gate to the recorded first_error (the gate does not trust setup_error or expect as recorded), and exit, sorry, negation, the axioms and targets supporting the verdict.

The gate can apply the setup list only to the first error message, which is the one recorded; the job applies it to every error message and records the result in setup_error, which the gate accepts only when it does not contradict the recorded text.

Otherwise the gate refuses with the control ids and the reason (controls: section missing, controls: neg-drop-homog failed: exit 0 (the file compiled), controls: neg-x failed: setup error 'unknown identifier', controls: ref-kappa: Refutations.kappa_zero_wrong is not a negation, controls: neg-y: target Paper.kappa not found in the failing command). A package without the declaration is gated as before; a receipt with a section but no declaration is gated as before too (the section is ignored and gate --check says so).

gate --check prints one line with the counts and the section’s time, so a growing section is seen before it reaches the unit’s runtime cap:

✓ controls: 124 declared, 124 passed (68 must-fail, 30 refutes, 26 compiles); 0 any-error, 37 naming no package declaration; 5m46s

JSON controls {declared, passed, failed[], by_kind {must-fail, refutes, compiles}, any_error, no_target, toolchain, seconds}.

What readers see

Compatibility and migration

Trust model

This adds refusals: a package that declares controls cannot be gated with a receipt whose controls did not all pass, and a control cannot pass on a setup error, on a refutation whose listed theorems are not all negations, or without the targets it declares. Nothing that was refused before is accepted now.

The controls are lower-tier evidence: the verify script runs them and writes the lines, as it writes the axioms lines, and the gate re-judges the facts but cannot re-run Lean. A dishonest script could fake the section as it could fake the axioms; the seal, the receipt’s binding and an independent re-run (receipt check on another host) are the defence, as for every lower-tier fact. Recording the first error message lets the gate re-derive the setup-error and expect verdicts from the recorded text instead of from flags. The gate checks that the declared controls ran on the committed bytes and passed for the declared reasons, not that they are good controls: an any-error control, or one naming no package declaration, passes, and page and the catalog show how many there are.

Alternatives

Open questions

Answered by the two field reviews and folded in above: expect stays optional, with the setup-error list; comparing refutations in the comparator tier is a later proposal, targets taking most of its value now; 300 s per control by default, a timeout is a failure, and gate --check shows the section’s total time; the catalog shows counts, never files; the setup list is not extendable per package; a target not found in the failing command fails, with no imports fallback; module-headed files run identically under plain lean with the checked LEAN_PATH (measured on 64 files under Lean 4.35). Still open:

  1. Whether a refutation whose negated statement is a Challenge theorem should also be compared by the comparator tier (a later proposal).
  2. Whether lean --json covers every message the plain output shows on the toolchains lean-pkg supports, or the header fallback must stay the primary path on some (to be measured in the implementation).

AI assistance

Drafted and revised with Claude Code (Claude Opus 5.5) at Le Chen’s request, from a field report and two field reviews by an AI agent working on a paper companion, measured on its 68 must-fail controls, 30 refutations and 26 audit files under Lean 4.35.0. Le Chen reviews and decides.