agent-formal-verify 0.4.5 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +44 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/skills/formal-verify/SKILL.md +24 -7
- package/skills/formal-verify/examples/kani-template/src/lib.rs +6 -0
- package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.lean +22 -7
- package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.mutations +6 -1
- package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.statements +34 -6
- package/skills/formal-verify/examples/lean-template/lean-toolchain +1 -1
- package/skills/formal-verify/references/lean-brief.md +24 -4
- package/skills/formal-verify/references/review-brief.md +45 -0
- package/skills/formal-verify/references/rust-brief.md +14 -6
- package/skills/formal-verify/references/setup.md +1 -1
- package/skills/formal-verify/references/tla-brief.md +3 -2
- package/skills/formal-verify/scripts/baseline.py +413 -0
- package/skills/formal-verify/scripts/kani.py +37 -0
- package/skills/formal-verify/scripts/lean-check.sh +88 -9
- package/skills/formal-verify/scripts/lean-mutations.lean +95 -0
- package/skills/formal-verify/scripts/lean-replay.lean +19 -0
- package/skills/formal-verify/scripts/lean-statements.py +61 -39
- package/skills/formal-verify/scripts/lean-tools.sh +9 -0
- package/skills/formal-verify/scripts/mutate.py +271 -138
- package/skills/formal-verify/scripts/tlc-matrix.sh +4 -167
- package/skills/formal-verify/scripts/tlc.py +310 -0
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 0.4.9 - a specification baseline, Lean kernel replay and checked witnesses
|
|
4
|
+
|
|
5
|
+
The specification baseline now preserves whitespace and comment markers inside string literals, so edits to those parts of TLA+ properties and Kani assumptions are reported as changes. Lean kernel replay now selects exact modules and their project imports, leaving out cached objects from deleted, unimported descendants.
|
|
6
|
+
|
|
7
|
+
The Lean checker now replays every built module, and every project module it imports, through the Lean kernel with the pinned toolchain's `leanchecker`, after its existing checks. A declaration that a command added to the environment without a kernel check used to pass the build and the audit. The replay rejects it, and the checker exits 1 with `leanchecker`'s output. A pin that ships no `leanchecker`, such as Lean 4.20.0, prints `UNAVAILABLE kernel replay` and still passes. The PASS line says whether the replay passed or was unavailable.
|
|
8
|
+
|
|
9
|
+
The Lean checker now checks hypothesis witnesses. For a public theorem with hypotheses, a `private theorem <Property>.witness` in the same file proves that some values satisfy all of them at once. The checker derives the statement such a witness must prove from the property on every run. It prints the statement when the witness is missing or states something else, and fails only in the second case. Each property gets a WITNESS line, and the PASS line counts witnesses checked, absent and unavailable. The Lean brief no longer accepts an `example` as a witness. The Lean template now proves a witness for each of its two theorems with hypotheses. Its statements are re-frozen to record them, and no existing fingerprint changed. The mutation runner does not count a failing witness as a detection, so a mutation that breaks only a witness reads MISSED, and it does not list a public witness as UNCOVERED.
|
|
10
|
+
|
|
11
|
+
A new helper, `baseline.py`, records what each existing model specifies before the modelling agents run and names each part that changed afterwards. For a TLA+ matrix it records the matrix lines and the definitions of `Spec`, of the initial state, of the checked and reach operators, and of the operators they reference, but not the actions that `Spec` names under `[][...]_vars`, `WF_` or `SF_`. A column-0 definition whose header it cannot read, such as an infix operator, is recorded whether or not a property references it. For a Lean model it records the `.statements` file, and for a Kani harness file each harness name, assumption (`kani::assume` or `kani::any_where`), cover and stub, including those under `cfg_attr(kani, ...)`. A removed or changed item fails the comparison, and so does an added Kani assumption or stub. A Kani assumption, cover, stub or harness attribute in a form the helper cannot read, such as an import that renames `kani::assume`, fails the record instead of going unrecorded. An added Lean declaration, TLA+ check or run, or Kani cover or harness does not. The skill's main thread now runs this comparison where it used to read `git diff` for those changes, and records an accepted specification correction again with its old and new digests. `git diff` still covers what the record leaves out, such as a theorem newly marked `private` or a removed assertion in a Kani harness. The record keeps cooperative agents to their briefs; it does not stop an agent that edits it, and the skill says so.
|
|
12
|
+
|
|
13
|
+
Rust mutation runs now preserve the crate's workspace and local path dependencies in their temporary copies. Copying only the harness crate left sibling dependencies and inherited workspace settings behind, so a harness that passed the checker could fail mutation testing before Kani checked its property. The runner uses the bundled Cargo to find the required workspaces and packages, including transitive and optional path dependencies.
|
|
14
|
+
|
|
15
|
+
Lean mutation coverage now reads declaration identities and source ranges from the pinned Lean frontend. Indented public theorems remain covered, and equal short names in different namespaces remain separate targets. Structure and class projections and instance declarations are not property targets, including local and scoped instances. Wrapped guards and examples remain detectable, and their reported locations refer to the original model. Guard and example failures cannot cover named theorems; errors outside recognized properties are rejected. The runner checks that the original module elaborates before testing mutations.
|
|
16
|
+
|
|
17
|
+
A Lean mutation that changed a theorem's statement used to count as breaking its proof. Renaming a definition that a statement names makes the statement fail to elaborate, or makes Lean bind the old name as an automatic implicit variable so that only the proof fails. The runner printed DETECTED for both and counted the theorem as covered, although Lean checked no proof of the frozen statement against the mutated code. The runner now compares each failing theorem's elaborated statement with the unmutated model's, and a mutation that changes or adds one reaches no verdict. The comparison ignores binder names, which Lean 4.20 numbers by a counter that edits to earlier commands shift.
|
|
18
|
+
|
|
19
|
+
`example` and `#guard` commands have no declaration to compare, so a rename that broke one still printed DETECTED and exited 0. The runner now compares an example's elaborated header type and a guard's elaborated term with the unmutated model's, after closing them over section variables, whose internal ids shift when an earlier command changes. A mutation that changes one reaches no verdict. So does a mutation whose replacement adds a check that the unmutated model lacks, which used to count as DETECTED.
|
|
20
|
+
|
|
21
|
+
Lean mutation results explicitly measure whether existing proofs break; they do not establish that a statement is false or its hypotheses can hold. The skill reports those evidence gaps separately. Existing properties may be corrected and re-frozen when the main thread accepts source-backed specification evidence, even when production code is unchanged; unsupported weakening remains prohibited.
|
|
22
|
+
|
|
23
|
+
The mutation runner reads and applies every mutation before it runs any tool. A mutation whose replaced text does not occur exactly once in the model used to be found only when its turn came, after every earlier mutation had run its checker; it now stops the run first. A TLA+ or Rust mutation without a `detects` line, and a mutation with two `detects` or two `only` lines, now fail by name instead of reporting a property named by an empty string or keeping the last line. A Lean mutation with an `only` line now fails instead of ignoring it. Because these checks run first, a malformed mutations file fails before a missing tool reports `UNAVAILABLE`.
|
|
24
|
+
|
|
25
|
+
The mutation runner checks that a Lean project's pinned toolchain is ready once per run, not once per mutation. The check and its remedy now live in `lean-tools.sh`, where `lean-check.sh` reads them too, and a Lean project without a pin reports that directly instead of as an analysis that did not complete.
|
|
26
|
+
|
|
27
|
+
The Lean checker derives each source's module name once and passes it to the frozen-statement step, which derived it a second time from the same path. When Lake reports a build file outside `.lake/build/lib/lean`, the checker now names it and stops instead of auditing a wrong import.
|
|
28
|
+
|
|
29
|
+
The TLA+ matrix runner moved from bash into `tlc.py`, and `tlc-matrix.sh` now checks for Python 3 and runs it, as `kani-check.sh` runs `kani.py`. Its output and exit status are unchanged, except that a matrix saved with CRLF line ends now runs, where the bash runner reported its spec as not found. The mutation runner now reads the matrix with the same parser and runs each mutation through the same runner, instead of parsing the matrix a second time and reading verdicts back out of printed lines. So it now finds its spec's section when the `spec` line writes the path another way, such as `./Name.tla`, and it checks TLC once per run instead of once per mutation. Any line the matrix runner rejects now stops the mutation runner wherever it is in the matrix, including an unknown directive, a run before any `spec` line and a check after an empty `spec` line; before, it noticed only a malformed check or reach in its own spec's section. It also reads a matrix whose words are separated by tabs, as the matrix runner always did.
|
|
30
|
+
|
|
31
|
+
The Lean and Kani templates now ask the adapter to record the source files, line ranges, covered functions and `Source read at <commit>` line in the model's header, as the TLA+ template and all three briefs already did.
|
|
32
|
+
|
|
33
|
+
## 0.4.8 - pin Lean 4.35.0
|
|
34
|
+
|
|
35
|
+
The Lean template pins Lean 4.35.0 in place of 4.34.1. The template records the same 34 declarations with the same statement types under both versions. Lean 4.35.0 builds the bodies of three generated `match_1` matchers differently, so their value fingerprints changed, and the template's statements are re-frozen. A project copied from the template keeps its own pin. After its `lean-toolchain` changes, the checker asks for a review and a fresh `--freeze`, as before. The checker still supports pins from Lean 4.20.0.
|
|
36
|
+
|
|
37
|
+
## 0.4.7 - an optional review of each model's properties
|
|
38
|
+
|
|
39
|
+
A property can pass every check and still promise less than the code's callers rely on, and until now only the agent that wrote it read it. After writing the target table, the skill asks whether to add an independent review, one agent per target, and skips the question when the request already answers it. A headless run cannot answer, so it gets no review, and its reply says so. A reviewer follows the new review brief. It reads the source and the model's properties, assumptions and fix commits, without the modelling agent's report, and writes the bugs it expects to pass as mutations. The skill appends them to the model's mutations file and runs the mutation runner. It keeps the detected ones and gives a missed one to a new modelling agent. A finding that no mutation can express is reported as an open question. For each model, the reply says whether its properties were reviewed and how the reviewer's mutations fared.
|
|
40
|
+
|
|
41
|
+
## 0.4.6 - every Lean theorem must be breakable, past fixes become mutations, and agents' results are rechecked
|
|
42
|
+
|
|
43
|
+
A Lean theorem whose hypotheses can never all hold passes whatever the code does, and the mutation runner never required a Lean theorem to fail. It now reads each Lean model's `.statements` file and prints UNCOVERED for a public theorem that no mutation makes fail, as it already did for TLA+ properties and Kani harnesses. A failing `#guard` does not count for the theorem, and private theorems are proof helpers that need no mutation. A Lean model without a `.statements` file fails before its mutations run. So does a Lean mutation with a `detects` line, which would otherwise count as covering the theorem it names. The template's `invariant_init` named the literal state `⟨0, 0⟩`, so no mutation could break it. The template now transcribes the initial state as `init`, uses it in the reach search and adds a mutation that counts an item as consumed before any claim; its statements are re-frozen. Models copied from earlier templates report `UNCOVERED theorem invariant_init` until they gain such a mutation.
|
|
44
|
+
|
|
45
|
+
Step 1 lists the commits that fixed a bug in each target's code, and each brief replays them as mutations that restore the behaviour before the fix. A Kani mutation can replay a fix only in the file beside its mutations file. After the agents report, step 3 reruns every matrix, Lean check, Kani check and mutations file in the main thread and takes the verdicts from those runs. It reverts a changed property, theorem statement, statements record or Kani assumption on an existing model, or a theorem newly marked `private`, unless the row's evidence supports the change.
|
|
46
|
+
|
|
3
47
|
## 0.4.5 - follow renames before retiring a model
|
|
4
48
|
|
|
5
49
|
The 0.4.4 recheck could propose retiring a model whose code still exists, and could skip the commit that changed a guarantee on purpose. Its search for the covered functions left out each model's files. A Kani harness written inside a production file, as in the bundled template, took the production functions out of the search with it, and a function renamed in place matched nothing. Step 1 now leaves out only model files that hold no production code. When a covered name is found nowhere, it finds the commit that removed the name with `git log -S` and reads all of it, and proposes retiring the model only when that commit deleted the code. The history search read a source file's first and last paths only, so a commit made at an intermediate path was skipped, and a guarantee changed there on purpose kept its old property. Step 1 now follows each source file through every rename since the sync commit and reads the log over all of its paths.
|
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ In Claude Code, use `/agent-formal-verify:formal-verify`. In Codex, type `$forma
|
|
|
67
67
|
|
|
68
68
|

|
|
69
69
|
|
|
70
|
-
The agent selects risky code, builds TLA+ or Lean models or adds Kani harnesses that call the Rust code, and checks their properties. Reachable counter-examples guide reproductions and fixes to both the code and model. Mutation checks test whether the properties detect mistakes, and CI reruns the models as the code changes.
|
|
70
|
+
The agent selects risky code, builds TLA+ or Lean models or adds Kani harnesses that call the Rust code, and checks their properties. Reachable counter-examples guide reproductions and fixes to both the code and model. Mutation checks test whether the properties detect mistakes. On request, a second agent reviews each model's properties against the code and proposes mistakes for those checks. CI reruns the models as the code changes.
|
|
71
71
|
|
|
72
72
|
A passing check establishes its stated properties under its assumptions and bounds. Reports must identify omitted constraints and unfinished proofs. See [scope and evidence](docs/reference.md#scope-and-evidence).
|
|
73
73
|
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@ Then read `git log -p <sync>..HEAD -- <paths collected>`, which includes commits
|
|
|
35
35
|
Record the sync commit, the commits read and the answers to two questions in the row:
|
|
36
36
|
|
|
37
37
|
- Does the model still describe the code as it is now? If not, the model changes.
|
|
38
|
-
- Does a doc comment, test, changelog entry or commit message in those commits say the guarantee changed? If so, the property changes with it, citing that evidence.
|
|
38
|
+
- Does a doc comment, test, changelog entry or commit message in those commits say the guarantee changed? If so, the property changes with it, citing that evidence. Otherwise preserve the property unless step 3 accepts an evidenced specification correction; a failure after updating the transcription is a bug candidate.
|
|
39
39
|
|
|
40
40
|
Then search for new targets in code no model covers, unless the user asked only to recheck the existing models.
|
|
41
41
|
|
|
@@ -48,8 +48,12 @@ Search with `rg` for `pthread_cond`, `pthread_mutex`, `atomic_`, `std::condition
|
|
|
48
48
|
|
|
49
49
|
For Rust functions, also search for `unsafe`, `as u32`, `as usize`, `checked_`, `wrapping_`, `unwrap(`, slicing and `%`. Record each function's input ranges, loop bounds and assumptions for a Kani target.
|
|
50
50
|
|
|
51
|
+
For each target, list the commits that fixed a bug in its code, from `git log --format='%h %s' -- <source files>`. A fix commit is one whose message, linked issue or added test names a bug in a covered function. A model that passes on the code before a fix would not have caught that bug, so the briefs replay each fix commit in the row as a mutation.
|
|
52
|
+
|
|
51
53
|
Write a table with one row per target before modelling. A protocol and the arithmetic it depends on are separate targets. For a protocol, record its threads, shared variables, every wait and what wakes it, terminal states such as joined or closed, and resources whose ownership moves. Include slots, buffers, file handles and resources that `close` frees. For a Lean target, record the functions, their integer types and the property. Start with waits that have no escape, resources freed by two paths, and errors raised on a different thread from the one that reports them. Read the whole source file for each target so the model follows the code.
|
|
52
54
|
|
|
55
|
+
Then ask the user whether to add an independent review of each model's properties, which costs one more agent per target. Use the host's question tool where it has one, such as `AskUserQuestion` in Claude Code. Do not ask when the request already says whether to review. When the user cannot answer, as in a headless run, skip the review and say in the reply that the properties were not reviewed.
|
|
56
|
+
|
|
53
57
|
## 2. Prepare the tools
|
|
54
58
|
|
|
55
59
|
Prepare tools after picking targets and before launching agents. The helpers are in this skill's `scripts/` directory. Stay in the target repository and run each helper with `bash` and its absolute path. Pass absolute paths to models and matrices. [Tool setup](references/setup.md) describes the pins, caches and environment settings.
|
|
@@ -66,11 +70,12 @@ The helpers:
|
|
|
66
70
|
|
|
67
71
|
- The setup helper, [`scripts/setup.sh`](scripts/setup.sh), verifies the pinned TLC JAR and is the only helper that installs a Lean toolchain.
|
|
68
72
|
- The matrix runner, [`scripts/tlc-matrix.sh`](scripts/tlc-matrix.sh), runs TLC with a matrix of constants and prints one PASS or FAIL per run with its state count, then a SUMMARY line with the totals. A failing run prints its error trace reduced by [`scripts/tlc-trace.py`](scripts/tlc-trace.py) to the variables each step changed. Copy [`examples/tla-template/`](examples/tla-template/BoundedQueue.tla) to start a spec and its matrix.
|
|
69
|
-
- The Lean checker, [`scripts/lean-check.sh`](scripts/lean-check.sh), builds every `.lean` file in the pinned Lake project and audits every declaration of every built module. It fails on a build error, a `sorry`, a declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, or a `.lean` file that no Lake library owns. Use `--freeze` before the file names to record statement types and definition bodies in each model's `.statements` file before proving it. Freezing permits `sorry` and reports FROZEN, not a proof PASS. Later checks enforce those records and permit proof changes and added declarations. Given file names after the project, it checks only those files. Copy [`examples/lean-template/Model/BoundedQueue.lean`](examples/lean-template/Model/BoundedQueue.lean) to start a model.
|
|
73
|
+
- The Lean checker, [`scripts/lean-check.sh`](scripts/lean-check.sh), builds every `.lean` file in the pinned Lake project and audits every declaration of every built module. It fails on a build error, a `sorry`, a declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, or a `.lean` file that no Lake library owns. It checks each `<Property>.witness` theorem against its property's hypotheses, and fails on a witness that states something else, as the [Lean brief](references/lean-brief.md) describes. It then replays every built module, and every project module it imports, through the Lean kernel with the pin's `leanchecker`, which rejects a declaration that a command added without a kernel check. A pin without `leanchecker`, such as Lean 4.20.0, passes with the replay reported as unavailable. Use `--freeze` before the file names to record statement types and definition bodies in each model's `.statements` file before proving it. Freezing permits `sorry` and reports FROZEN, not a proof PASS. Later checks enforce those records and permit proof changes and added declarations. Given file names after the project, it checks only those files. Copy [`examples/lean-template/Model/BoundedQueue.lean`](examples/lean-template/Model/BoundedQueue.lean) to start a model.
|
|
70
74
|
- The Rust checker, [`scripts/kani-check.sh`](scripts/kani-check.sh), runs the pinned Kani on the crate's proof harnesses. It reports each harness's unwind bound and check count, rejects failed checks and unsatisfied cover conditions, and prints concrete playback tests when available. Copy [`examples/kani-template/`](examples/kani-template/src/lib.rs) for a bounded-queue example.
|
|
71
|
-
- The mutation runner, [`scripts/mutate.py`](scripts/mutate.py), takes a model's `<Name>.mutations` file and applies each listed bug to a temporary copy of the model. It prints DETECTED or MISSED per mutation with what failed, UNCOVERED for a TLA+ property or Kani harness that no mutation targets, and a SUMMARY line. All three templates include a mutations file.
|
|
75
|
+
- The mutation runner, [`scripts/mutate.py`](scripts/mutate.py), takes a model's `<Name>.mutations` file and applies each listed bug to a temporary copy of the model. It prints DETECTED or MISSED per mutation with what failed, UNCOVERED for a TLA+ property or Kani harness that no mutation targets or for a public theorem in a Lean model's `.statements` file whose proof no mutation makes fail, and a SUMMARY line. Lean names are fully qualified. A Lean DETECTED line means the existing proof fails; it does not establish that the statement is false or its hypotheses can hold. A Lean mutation that changes the statement of a theorem, example or `#guard`, such as renaming a definition that the statement names, reaches no verdict. A Lean model needs its `.statements` file before its mutations run. All three templates include a mutations file.
|
|
76
|
+
- The baseline helper, [`scripts/baseline.py`](scripts/baseline.py), records what each model specifies and later names each part that changed. For TLA+ it records the matrix lines and the definitions of `Spec`, of each operator that a `check` or `reach` line names, and of the operators those reference, including the initial state. It does not follow `Spec` into the actions it names under `[][...]_vars`, `WF_` or `SF_`, because every correction of the transcription changes them. An operator that `Spec` names outside those, such as a fairness definition, is followed into its actions. A column-0 definition whose header it cannot read, such as an infix operator, is recorded whether or not a property references it, with the operators it references. For Lean it records the `.statements` file. For Kani it records the name of each harness and each `kani::assume`, `kani::any_where`, `kani::cover!` and `#[kani::stub]` in the harness file, but not a harness's assertions or the inputs it builds. It fails on a Kani assumption, cover, stub or harness attribute written in a form it cannot read, such as an import that renames `kani::assume`, rather than leave it unrecorded.
|
|
72
77
|
|
|
73
|
-
Run every existing model's checker and mutations once, before any agent changes a model, and record the results. For a TLA+ or Lean model a pass shows only that the old description still holds; a Kani harness runs the code as it is now. A model that still describes the code needs no agent. When it passes, refresh its header as step 5 says; when it fails, take the failure through step 4. A Kani compile error means the harness no longer fits the code, so give it to an agent. A check that passes here and fails after the update was passing on a stale description; say so in the reply.
|
|
78
|
+
Run every existing model's checker and mutations once, before any agent changes a model, and record the results. Then record what the models specify with `python3 <skill-dir>/scripts/baseline.py record <record-file> <model files>`, naming each existing `.matrix`, `.statements` and Kani harness file. Put `<record-file>` in a temporary directory outside the repository, and leave its path out of every brief. For a TLA+ or Lean model a pass shows only that the old description still holds; a Kani harness runs the code as it is now. A model that still describes the code needs no agent. When it passes, refresh its header as step 5 says; when it fails, take the failure through step 4. A Kani compile error means the harness no longer fits the code, so give it to an agent. An UNCOVERED line means the mutations file lacks a bug that the property detects, not that the code fails; give the model to an agent to add one. A check that passes here and fails after the update was passing on a stale description; say so in the reply.
|
|
74
79
|
|
|
75
80
|
## 3. Model one target per agent
|
|
76
81
|
|
|
@@ -84,7 +89,13 @@ Spawn one agent per target, in parallel when supported. Use the host runtime's a
|
|
|
84
89
|
|
|
85
90
|
Name the brief file and leave its text out of the prompt. The [TLA+ brief](references/tla-brief.md), the [Lean brief](references/lean-brief.md) and the [Rust brief](references/rust-brief.md) hold the modelling requirements, the files to write, the commands to run and what to report. If delegation is unavailable, read the brief for each target and model the targets yourself, one at a time.
|
|
86
91
|
|
|
87
|
-
An agent writes only its own files, `tla/<Name>.tla`, `.matrix` and `.mutations`, `lean/Model/<Name>.lean`, `.mutations` and `.statements`, or the assigned Rust harness and `.mutations` files in a separate crate, so parallel agents share none.
|
|
92
|
+
An agent writes only its own files, `tla/<Name>.tla`, `.matrix` and `.mutations`, `lean/Model/<Name>.lean`, `.mutations` and `.statements`, or the assigned Rust harness and `.mutations` files in a separate crate, so parallel agents share none. An existing Lean project keeps its layout and must pin Lean 4.20.0 or later.
|
|
93
|
+
|
|
94
|
+
When the agents have reported, rerun every check in this thread: the matrix runner on each matrix file, the Lean checker on the whole project without a file name, the Rust checker on each crate, and the mutation runner on each mutations file. Take each verdict from these runs, not from an agent's report. Then run `python3 <skill-dir>/scripts/baseline.py compare <record-file>`. It exits 1 and prints CHANGED with the changed parts when a recorded property, fairness condition, matrix line, `.statements` record, Kani cover or stub changed, a Kani harness was removed or renamed, or a Kani assumption was added or changed. Also read `git diff` for each model that existed before this run, for the changes the record does not cover, such as a theorem newly marked `private`, a new guard in a TLA+ action, or a removed assertion or narrowed input in a Kani harness. Each such change needs the evidence its row cites, a specification correction accepted below, or for a re-freeze another reason the Lean brief permits. Revert any change without it and give the model back to its agent with the reason. Run the comparison again until it exits 0.
|
|
95
|
+
|
|
96
|
+
Accept a specification correction when a reviewer finding, a missed mutation, an UNCOVERED result with source evidence, or a checked witness demonstrates a gap in the old statement. Read the old and proposed guarantees against the callers, record the evidence and decision in the target's row, and permit the corresponding re-freeze even when production code is unchanged. The correction must preserve the intended guarantee or strengthen it over the intended inputs. A broken proof alone does not justify changing a statement. A weaker guarantee or a new assumption excluding shipped inputs needs evidence of an intentional production contract change or the user's explicit agreement. Rerun all checks after the accepted correction and re-freeze. Then run `baseline.py record <record-file>` again on that model's file, and add the previous and new digests it prints to the row.
|
|
97
|
+
|
|
98
|
+
When the user chose the review, spawn one reviewer per model once these checks pass, on a different model from the modelling agents when the host offers a choice. Its brief contains the target's row, the source files with line ranges, the model's files, `<skill-dir>` and the instruction to read `<skill-dir>/references/review-brief.md` in full and follow it. The [review brief](references/review-brief.md) holds the questions and the report. Leave out the modelling agent's report, so the reviewer judges the properties against the code alone. Append the mutations the reviewer proposes to the model's mutations file and run the mutation runner. Remove a proposal that the runner rejects, such as one whose text does not occur once or whose `detects` names no checked property, and rerun. Keep a DETECTED proposal. Drop a MISSED proposal that changes nothing a caller could observe, such as a reordered sum. Any other MISSED proposal shows a property that lets a plausible bug pass; give the model, the proposal and the reviewer's reason to a new modelling agent, then repeat the checks above. Run one review round per model, and report what is still open after it. Report each finding that no mutation can express as an open question in the reply, and leave the model as it is.
|
|
88
99
|
|
|
89
100
|
## 4. Read the counter-example back into the code
|
|
90
101
|
|
|
@@ -118,6 +129,8 @@ Do not add a report file per bug, and do not paste run tables or traces into sev
|
|
|
118
129
|
|
|
119
130
|
These models do not check memory ordering below the mutex. Keep the project's ThreadSanitizer or race-detector checks. Model floating-point results as the integers they round to, unless the property concerns the rounding itself.
|
|
120
131
|
|
|
132
|
+
The baseline record and these steps detect a modelling agent that weakens a specification while it follows its brief. They do not stop an agent that sets out to defeat them. An agent runs as the same user, with a shell, and can edit any file, including the record and the helpers. Say so when a report states that a specification did not change.
|
|
133
|
+
|
|
121
134
|
A passing TLA+ or Lean model establishes its stated properties under its assumptions. It describes the code by hand. Kani checks the Rust function itself, within the reported input and unwind bounds. Neither result establishes correctness of the whole program.
|
|
122
135
|
|
|
123
136
|
## Reply
|
|
@@ -125,7 +138,7 @@ A passing TLA+ or Lean model establishes its stated properties under its assumpt
|
|
|
125
138
|
Write the reply, and any pull request or document, for a reader who knows the code and has used none of these tools.
|
|
126
139
|
|
|
127
140
|
1. Start with what was found, in the code's terms. For each bug, say what goes wrong for a caller or user, the code events in order with `file:line`, whether the shipped settings can reach it, how to reproduce it, and the fix or proposed fix, with a PR link when one was opened.
|
|
128
|
-
2. Give a table with one row per target: what was checked, as a sentence about the code, and the verdict. Label each counter-example `reproduced`, `reachable at shipped settings`, or `model-only`. State each property as what it guarantees, such as "the bar never shows 100% before the work finishes". Add the model's name for it in backticks only so the reader can find it. For a model from an earlier run, add whether it was unchanged or updated, or is proposed for retirement, with its sync commit and the commits read for it.
|
|
141
|
+
2. Give a table with one row per target: what was checked, as a sentence about the code, and the verdict. Label each counter-example `reproduced`, `reachable at shipped settings`, or `model-only`. State each property as what it guarantees, such as "the bar never shows 100% before the work finishes". Add the model's name for it in backticks only so the reader can find it. For a model from an earlier run, add whether it was unchanged or updated, or is proposed for retirement, with its sync commit and the commits read for it. For each model, say whether its properties were reviewed, how many of the reviewer's mutations were detected and missed, and the reviewer's open questions.
|
|
129
142
|
3. Say what each kind of evidence means where it first appears:
|
|
130
143
|
|
|
131
144
|
| Evidence | Meaning to give |
|
|
@@ -133,8 +146,12 @@ Write the reply, and any pull request or document, for a reader who knows the co
|
|
|
133
146
|
| TLC passes | TLC tried every ordering of the modelled steps at the listed small sizes and found none that breaks the property. The SUMMARY line's state total is the size of that search, not a count of real runs. |
|
|
134
147
|
| Kani passes | Kani checked every input within the stated bounds and found no violation. Larger inputs are not covered. |
|
|
135
148
|
| Lean passes | Lean proved the property for every input, under the listed assumptions. |
|
|
149
|
+
| Kernel replay passed | Lean's kernel checked every declaration of the built modules a second time, including any that a command added without a check. `unavailable` means the pinned Lean has no `leanchecker`, so this second check did not run. |
|
|
150
|
+
| Witness checked | A Lean proof shows that some concrete values satisfy all of a property's hypotheses at once, so the property is not true merely because nothing meets its conditions. `absent` and `unavailable` mean this was not checked. |
|
|
136
151
|
| A bounded search passes | Every input up to the stated bound was tried. |
|
|
137
|
-
| Mutations detected | Deliberate bugs were planted in copies of the model, and the checks caught each one.
|
|
152
|
+
| Mutations detected | Deliberate bugs were planted in copies of the model, and the checks caught each one. For Lean, this shows that existing proofs fail, not that the mutated statements are false. |
|
|
153
|
+
| Past fix detected | The checks fail on the behaviour before a recorded bug fix. For Lean, report proof sensitivity separately from whether a checked counterexample establishes that the property rules out that bug. |
|
|
154
|
+
| Specification unchanged | The baseline comparison found every recorded property, fairness condition, matrix line, statement record, Kani harness name, assumption, cover and stub as it was when the run began. It does not cover a Kani harness's assertions; `git diff` does. |
|
|
138
155
|
| UNAVAILABLE | The tool could not run. This target was not checked; give the printed remedy. |
|
|
139
156
|
| reproduced | A deterministic test or race-detector run fails on the production code. |
|
|
140
157
|
| reachable at shipped settings | The shipped constants and callers permit the counter-example, but no production reproduction has confirmed it yet. |
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// Copyright (c) 2026 Michael Denyer
|
|
2
2
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
3
|
+
//
|
|
4
|
+
// The harnesses in `proofs` check `claim` and `consume` of a bounded queue with
|
|
5
|
+
// ordered output. To adapt them, replace this comment with the production
|
|
6
|
+
// source files and line ranges the harnesses call, the functions they cover,
|
|
7
|
+
// the commit they were read at as `Source read at <commit>`, and each caller
|
|
8
|
+
// constraint and stub assumption.
|
|
3
9
|
|
|
4
10
|
#[derive(Clone, Copy)]
|
|
5
11
|
pub struct State {
|
|
@@ -5,11 +5,17 @@ This model checks the counters of a bounded queue with ordered output.
|
|
|
5
5
|
`next` counts claimed items, `consumed` counts consumed items, and at most
|
|
6
6
|
`w` items may be in flight. To adapt it:
|
|
7
7
|
|
|
8
|
-
1.
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
1. Replace this description with the source files and line ranges the model
|
|
9
|
+
follows, the functions it covers, the commit they were read at as
|
|
10
|
+
`Source read at <commit>`, and each assumption it makes.
|
|
11
|
+
2. Transcribe the state and steps from the code with the same arithmetic.
|
|
12
|
+
3. State the invariant as a `Prop` with a `Decidable` instance.
|
|
13
|
+
4. Run `#eval badPairs` to find states where a step violates the invariant
|
|
11
14
|
within the chosen bound, and keep the `#guard` that fails the build on one.
|
|
12
|
-
|
|
15
|
+
5. Prove the invariant for every size by cases on the step.
|
|
16
|
+
6. For each theorem with hypotheses, prove `<theorem>.witness` on concrete
|
|
17
|
+
values that satisfy all of them at once. `lean-check.sh` prints the
|
|
18
|
+
statement it expects and checks the one it finds.
|
|
13
19
|
|
|
14
20
|
Name any unfinished proof that uses `sorry`. `lean-check.sh` fails on it, on
|
|
15
21
|
any declaration that rests on a declared axiom, and on a `.lean` file that no
|
|
@@ -31,6 +37,9 @@ def Invariant (w : Nat) (s : State) : Prop := s.consumed ≤ s.next ∧ s.next
|
|
|
31
37
|
|
|
32
38
|
instance (w : Nat) (s : State) : Decidable (Invariant w s) := by unfold Invariant; infer_instance
|
|
33
39
|
|
|
40
|
+
/-- The state before any item is claimed. -/
|
|
41
|
+
def init : State := ⟨0, 0⟩
|
|
42
|
+
|
|
34
43
|
/-- Return the next state, or `none` when the guard fails. -/
|
|
35
44
|
def claim (w : Nat) (s : State) : Option State :=
|
|
36
45
|
if s.next < s.consumed + w then some { s with next := s.next + 1 } else none
|
|
@@ -56,15 +65,15 @@ def badPairs (w n : Nat) : List (State × State) :=
|
|
|
56
65
|
#guard (badPairs 2 6).isEmpty
|
|
57
66
|
|
|
58
67
|
def reachable (w : Nat) : Nat → List State
|
|
59
|
-
| 0 => [
|
|
68
|
+
| 0 => [init]
|
|
60
69
|
| steps + 1 =>
|
|
61
70
|
let states := reachable w steps
|
|
62
71
|
states ++ states.flatMap fun s => [claim w s, consume s].filterMap id
|
|
63
72
|
|
|
64
73
|
#guard (reachable 2 6).any fun s => s.next == s.consumed + 2
|
|
65
74
|
|
|
66
|
-
theorem invariant_init (w : Nat) : Invariant w
|
|
67
|
-
simp [Invariant]
|
|
75
|
+
theorem invariant_init (w : Nat) : Invariant w init := by
|
|
76
|
+
simp [Invariant, init]
|
|
68
77
|
|
|
69
78
|
theorem claim_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h : claim w s = some t) :
|
|
70
79
|
Invariant w t := by
|
|
@@ -75,6 +84,9 @@ theorem claim_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h :
|
|
|
75
84
|
omega
|
|
76
85
|
· cases h
|
|
77
86
|
|
|
87
|
+
private theorem claim_keeps_invariant.witness : ∃ w s t, Invariant w s ∧ claim w s = some t :=
|
|
88
|
+
⟨1, ⟨0, 0⟩, ⟨1, 0⟩, by decide, by decide⟩
|
|
89
|
+
|
|
78
90
|
theorem consume_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h : consume s = some t) :
|
|
79
91
|
Invariant w t := by
|
|
80
92
|
unfold consume at h
|
|
@@ -84,6 +96,9 @@ theorem consume_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h
|
|
|
84
96
|
omega
|
|
85
97
|
· cases h
|
|
86
98
|
|
|
99
|
+
private theorem consume_keeps_invariant.witness : ∃ w s t, Invariant w s ∧ consume s = some t :=
|
|
100
|
+
⟨1, ⟨1, 0⟩, ⟨1, 1⟩, by decide, by decide⟩
|
|
101
|
+
|
|
87
102
|
def vectors : List (Nat × State) :=
|
|
88
103
|
[(0, ⟨0, 0⟩), (1, ⟨0, 0⟩), (1, ⟨1, 0⟩), (1, ⟨1, 1⟩),
|
|
89
104
|
(4, ⟨0, 0⟩), (4, ⟨3, 0⟩), (4, ⟨4, 0⟩), (4, ⟨5, 1⟩), (4, ⟨5, 5⟩)]
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Mutations for mutate.py. Each one swaps a piece of BoundedQueue.lean for a
|
|
2
2
|
# plausible bug. The text after `- ` must occur exactly once in the model;
|
|
3
|
-
# `+ ` lines replace it. mutate.py reports the declarations that fail on each
|
|
3
|
+
# `+ ` lines replace it. mutate.py reports the declarations that fail on each,
|
|
4
|
+
# and every public theorem's proof in BoundedQueue.statements must fail on one.
|
|
5
|
+
|
|
6
|
+
mutation count an item as consumed before any claim
|
|
7
|
+
- def init : State := ⟨0, 0⟩
|
|
8
|
+
+ def init : State := ⟨0, 1⟩
|
|
4
9
|
|
|
5
10
|
mutation claim one item past the window
|
|
6
11
|
- if s.next < s.consumed + w then
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"format": 1,
|
|
3
|
-
"toolchain": "leanprover/lean4:v4.
|
|
3
|
+
"toolchain": "leanprover/lean4:v4.35.0",
|
|
4
4
|
"module": "Model.BoundedQueue",
|
|
5
5
|
"declarations": [
|
|
6
6
|
{
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"kind": "definition",
|
|
128
128
|
"type": "(motive : Option BoundedQueue.State → Sort u_1) → (t : Option BoundedQueue.State) → ((t' : BoundedQueue.State) → motive (some t')) → (Unit → motive none) → motive t",
|
|
129
129
|
"typeHash": "af98a4e3bf5e18322b9281d582642a70793e0eb5ce6780696c448cbf28256cce",
|
|
130
|
-
"valueHash": "
|
|
130
|
+
"valueHash": "462c1132951924916484f4295f1aff8678fe9d71fa0a89a181829589f7f76d53"
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
133
|
"name": "BoundedQueue.claim",
|
|
@@ -143,6 +143,13 @@
|
|
|
143
143
|
"typeHash": "a62ef6d7676b1be25d6f5adc855db00967122a1664301f089eddcbc5b7425716",
|
|
144
144
|
"valueHash": null
|
|
145
145
|
},
|
|
146
|
+
{
|
|
147
|
+
"name": "BoundedQueue.claim_keeps_invariant.witness",
|
|
148
|
+
"kind": "theorem",
|
|
149
|
+
"type": "∃ w s t, BoundedQueue.Invariant w s ∧ BoundedQueue.claim w s = some t",
|
|
150
|
+
"typeHash": "345ce2f56368ae1d973c198de43581007e5a656e2115d3c9101fd3013b3d8430",
|
|
151
|
+
"valueHash": null
|
|
152
|
+
},
|
|
146
153
|
{
|
|
147
154
|
"name": "BoundedQueue.consume",
|
|
148
155
|
"kind": "definition",
|
|
@@ -157,6 +164,27 @@
|
|
|
157
164
|
"typeHash": "8f97727457cdc622aff37bd77a07265ab79e8ad8c1fe7124db33cef3aacc0b3f",
|
|
158
165
|
"valueHash": null
|
|
159
166
|
},
|
|
167
|
+
{
|
|
168
|
+
"name": "BoundedQueue.consume_keeps_invariant.witness",
|
|
169
|
+
"kind": "theorem",
|
|
170
|
+
"type": "∃ w s t, BoundedQueue.Invariant w s ∧ BoundedQueue.consume s = some t",
|
|
171
|
+
"typeHash": "3667894d6b0a22c93ce6d8dae29d88713eb74e7f218a2f854d4272d41fb160ca",
|
|
172
|
+
"valueHash": null
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"name": "BoundedQueue.init",
|
|
176
|
+
"kind": "definition",
|
|
177
|
+
"type": "BoundedQueue.State",
|
|
178
|
+
"typeHash": "11103524df36d3cdaaecfad5a8e4ea76bfd435294bead5f2acdefbe05c6aef71",
|
|
179
|
+
"valueHash": "bd3dc3f1382ed19a578267073024d6fbc246b465d6e7c14b0aed9787c0cbeef7"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"name": "BoundedQueue.init.eq_1",
|
|
183
|
+
"kind": "theorem",
|
|
184
|
+
"type": "BoundedQueue.init = { next := 0, consumed := 0 }",
|
|
185
|
+
"typeHash": "5e405f4acd1a41903fdd240d23ad3be5e67fb0883e48136d1ace01dfa756fdc9",
|
|
186
|
+
"valueHash": null
|
|
187
|
+
},
|
|
160
188
|
{
|
|
161
189
|
"name": "BoundedQueue.instDecidableEqState",
|
|
162
190
|
"kind": "definition",
|
|
@@ -176,7 +204,7 @@
|
|
|
176
204
|
"kind": "definition",
|
|
177
205
|
"type": "(motive : BoundedQueue.State → BoundedQueue.State → Sort u_1) → (x x_1 : BoundedQueue.State) → ((a a_1 b b_1 : Nat) → motive { next := a, consumed := a_1 } { next := b, consumed := b_1 }) → motive x x_1",
|
|
178
206
|
"typeHash": "a3593a5bf4fe863d9a64998e6820f9d4d108b25b8a7dbadc85895186e774b0bd",
|
|
179
|
-
"valueHash": "
|
|
207
|
+
"valueHash": "8c1885bcd3420a131168e49097f6dbcc0424182d1b3c14d0cba7e31775881e9b"
|
|
180
208
|
},
|
|
181
209
|
{
|
|
182
210
|
"name": "BoundedQueue.instDecidableInvariant",
|
|
@@ -202,8 +230,8 @@
|
|
|
202
230
|
{
|
|
203
231
|
"name": "BoundedQueue.invariant_init",
|
|
204
232
|
"kind": "theorem",
|
|
205
|
-
"type": "∀ (w : Nat), BoundedQueue.Invariant w
|
|
206
|
-
"typeHash": "
|
|
233
|
+
"type": "∀ (w : Nat), BoundedQueue.Invariant w BoundedQueue.init",
|
|
234
|
+
"typeHash": "20543cdf11e2b3d3fd74663519eb516029af8d9b758253502dbbe486d82f9800",
|
|
207
235
|
"valueHash": null
|
|
208
236
|
},
|
|
209
237
|
{
|
|
@@ -218,7 +246,7 @@
|
|
|
218
246
|
"kind": "definition",
|
|
219
247
|
"type": "(motive : Nat → Sort u_1) → (x : Nat) → (Unit → motive 0) → ((steps : Nat) → motive steps.succ) → motive x",
|
|
220
248
|
"typeHash": "762abfa7addd0bd8d4a548d7221baf925cf09a9c172d54d9d49a913a6c7908c2",
|
|
221
|
-
"valueHash": "
|
|
249
|
+
"valueHash": "d3ec4495c6184aacdc386c9a5da8fa7e98fa053decdc0d4ab66dcccd8ec23846"
|
|
222
250
|
},
|
|
223
251
|
{
|
|
224
252
|
"name": "BoundedQueue.vectors",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
leanprover/lean4:v4.
|
|
1
|
+
leanprover/lean4:v4.35.0
|
|
@@ -10,7 +10,7 @@ Every `.lean` file in the project must belong to a library in the lakefile. With
|
|
|
10
10
|
|
|
11
11
|
## Existing model
|
|
12
12
|
|
|
13
|
-
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the transcription where it no longer describes the code. Change a theorem statement only
|
|
13
|
+
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the transcription where it no longer describes the code. Change a theorem statement only with that evidence or a specification correction accepted by the main thread under step 3 of the skill. Re-freeze after either change, as the Check section allows, and rerun the differential vectors. Add a mutation for each branch or step the update adds. Update the header to the code you read.
|
|
14
14
|
|
|
15
15
|
## Model
|
|
16
16
|
|
|
@@ -18,7 +18,8 @@ The row in your task gives the commits since the model was last synced and says
|
|
|
18
18
|
2. State the property as a `Prop` with a `Decidable` instance. It may describe an invariant, an encoder round trip, an index bound or states the machine must never reach.
|
|
19
19
|
3. Write every theorem statement with `sorry` for its proof, then freeze the model with `bash <skill-dir>/scripts/lean-check.sh <absolute-project-path> --freeze Model/<Name>.lean`. This records types and definition bodies even while proofs are unfinished. The FROZEN line confirms the record, not a proof. Added axioms still fail.
|
|
20
20
|
4. Write and evaluate a bounded exhaustive check before proving the theorem. The template's `badPairs` finds states where one step breaks the invariant; evaluating `badPairs 2 6` at top level, as the template does, prints concrete counter-examples and `#guard` fails the build while any exist. Set the bound above the code's slot count, batch size, window and other constants so it includes boundary cases. Add a `#guard` that a bounded search from the initial state reaches the states the property depends on. The template's `reachable` search requires a full window.
|
|
21
|
-
5. Prove one theorem per step or function for every size. Split on the guards, use `simp only [...]` to expose arithmetic, then use `omega` or `decide` for a finite type. If a proof needs a fact about the real code that the model lacks, state it as a theorem hypothesis and name it in a comment. Do not declare it as an `axiom`. An unfinished proof may use `sorry`, but the Lean checker reports it as a failure. The checker also fails every declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, which also rules out `native_decide`.
|
|
21
|
+
5. Prove one theorem per step or function for every size. Split on the guards, use `simp only [...]` to expose arithmetic, then use `omega` or `decide` for a finite type. If a proof needs a fact about the real code that the model lacks, state it as a theorem hypothesis and name it in a comment. Do not declare it as an `axiom`. Mark each helper lemma `private`; every public theorem is a property whose proof the mutations must be able to break. An unfinished proof may use `sorry`, but the Lean checker reports it as a failure. The checker also fails every declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, which also rules out `native_decide`.
|
|
22
|
+
6. For each public theorem with hypotheses, prove on concrete values that all of them can hold at once, as `private theorem <Property>.witness` in the same file. The template does this for each of its theorems with hypotheses.
|
|
22
23
|
|
|
23
24
|
After a proof closes, print differential test vectors by evaluating them at top level, as the template does. Include boundary inputs and a spread of in-range inputs, with each input and the model's output on one line. Write a test in the target repository's own framework that calls the production function on those inputs and compares its output. A mismatch is a bug in the production code or the transcription; establish which before reporting. State how many vectors agree and the integer widths in both implementations. If the production comparison was not run, say so beside the proof verdict.
|
|
24
25
|
|
|
@@ -41,11 +42,27 @@ bash <skill-dir>/scripts/lean-check.sh <absolute-project-path> Model/<Name>.lean
|
|
|
41
42
|
python3 <skill-dir>/scripts/mutate.py <absolute-project-path>/Model/<Name>.mutations
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
The checker enforces the `.statements` file beside each checked source. Changing a theorem type, a definition type or body, or deleting a frozen declaration fails with its name. Adding lemmas and definitions and changing proofs is allowed. Re-freeze only after the production code changes, after a production test contradicts the transcription,
|
|
45
|
+
The checker enforces the `.statements` file beside each checked source. Changing a theorem type, a definition type or body, or deleting a frozen declaration fails with its name. Adding lemmas and definitions and changing proofs is allowed. Re-freeze only after the production code changes, after a production test contradicts the transcription, after reviewing a toolchain bump, or after the main thread accepts a specification correction under step 3 of the skill. Record the evidence, the old and new guarantees, and the reason for re-freezing in the report. Records are specific to the pinned Lean toolchain. Fingerprints use structural expressions, including the module identity of private references. If two private declarations share a name in one model, give them distinct names before freezing. A project-wide check also rejects records whose source files were deleted. Named-file checks remain limited to those files. A model without a record retains the usual proof and axiom checks, so keep the records under version control. Deleting a record removes that protection.
|
|
45
46
|
|
|
46
47
|
The file name limits the Lean checker to your model, so another agent's unfinished file does not fail your check.
|
|
47
48
|
|
|
48
|
-
List plausible bugs in the mutations file, such as `<` instead of `≤`, a missing `+ 1` or a swapped argument. The mutation runner checks each on a copy of the file and names the theorems and `#guard` lines that fail. Expect both the bounded search's `#guard` and the theorem. It rejects a mutation that stops a definition compiling. Revise the properties behind each MISSED line.
|
|
49
|
+
List plausible bugs in the mutations file, such as `<` instead of `≤`, a missing `+ 1` or a swapped argument. The mutation runner checks each on a copy of the file and names the theorems and `#guard` lines that fail. Expect both the bounded search's `#guard` and the theorem. It rejects a mutation that stops a definition compiling or changes the statement of a theorem, example or `#guard`, such as renaming a definition that a statement names. Revise the properties behind each MISSED line.
|
|
50
|
+
|
|
51
|
+
The mutation runner reads the `.statements` file and uses Lean's elaborated names and source ranges to report each frozen public theorem whose proof no mutation makes fail. Structure and class projections and instance declarations are not property targets. Names remain fully qualified, including nested namespaces. A failing `#guard` or example does not cover a named theorem. Guard and example locations point into the original model; a command introduced by the mutation is labelled as a replacement at the edit's original location. Add a mutation that breaks the proof, or propose a specification correction with evidence for the main thread to accept before re-freezing. A helper lemma that shows here should be `private`; a property marked `private` to hide it is a change the main thread reverts. Lean mutations take no `detects` line. For each fix commit in your row, add a mutation that restores the behaviour the code had before the fix, with the commit's short hash in its label.
|
|
52
|
+
|
|
53
|
+
A broken proof does not establish that the mutated statement is false. Even a theorem with contradictory hypotheses can have a proof that breaks when the implementation changes. Check that each theorem's hypotheses can hold together, using concrete inputs and Lean-checked witnesses where practical, and report where this was not checked. Keep proof sensitivity, hypothesis satisfiability and a checked counterexample as separate evidence. Do not claim non-vacuity or that a historical bug is ruled out from a DETECTED line alone.
|
|
54
|
+
|
|
55
|
+
The checker derives the statement a witness must prove from its property: `∃ (v1 : T1), …, ∃ (vn : Tn), H1 ∧ … ∧ Hk`, with the theorem's variables and hypotheses in binder order. It rebuilds this statement on every run, so a changed property needs a new witness. When the witness is missing or states something else, the checker prints the statement, which can be pasted as the witness's type. Only a `theorem` named `<Property>.witness` in the property's file counts; an `example`, `def` or `axiom` does not. A witness, private or public, is not a mutation-coverage property. Adding one needs no re-freeze. A mutation that breaks only a witness reads MISSED, because the witness proves chosen values, not the property. Do not make an existing property private to avoid coverage. Each check prints one WITNESS line per property:
|
|
56
|
+
|
|
57
|
+
| Status | Meaning |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `checked` | The witness states the property's hypotheses, and Lean proved it. |
|
|
60
|
+
| `failed` | The witness states something else. The check exits 1 and prints the statement expected. |
|
|
61
|
+
| `absent` | No witness exists. The check passes; report non-vacuity as not checked. |
|
|
62
|
+
| `no-hypotheses` | The theorem has no hypotheses written as binders. The checker does not look inside definitions or at the variable types, so a property whose statement unfolds to an implication, or whose variable has an empty type such as `Fin 0`, also reads `no-hypotheses`. |
|
|
63
|
+
| `unavailable` | A variable's type uses a hypothesis's proof, or deriving the statement failed. The check passes with the reason; report non-vacuity as not checked. |
|
|
64
|
+
|
|
65
|
+
After these checks the checker replays every built module, and every project module it imports, through the Lean kernel with the pinned toolchain's `leanchecker`. The replay rejects a declaration that a command added to the environment without a kernel check, and the checker then exits 1 with `leanchecker`'s output. A pin without `leanchecker`, such as Lean 4.20.0, prints `UNAVAILABLE kernel replay` and still exits 0; report the kernel replay as not checked. This differs from a missing tool, which exits 3.
|
|
49
66
|
|
|
50
67
|
Check the reach guard as well as the absence of bad pairs. A search that cannot reach a boundary state does not establish the intended coverage.
|
|
51
68
|
|
|
@@ -54,8 +71,11 @@ Check the reach guard as well as the absence of bad pairs. A search that cannot
|
|
|
54
71
|
Report only after reading the output of both commands. If either exits 3 with `UNAVAILABLE`, report "not checked" with the printed remedy; do not claim a pass or a model failure. Give:
|
|
55
72
|
|
|
56
73
|
- the file paths, both commands, the checker's PASS or FAIL line and the mutation runner's output;
|
|
74
|
+
- each fix commit from the row and the verdict of its mutation;
|
|
57
75
|
- the states required by the reach guard and the search bound;
|
|
58
76
|
- for each counter-example, concrete inputs to the code's function, the source line of the failing arithmetic, a unit test with those inputs and whether it fails on the production code, whether shipped callers can pass those inputs, and the proposed fix;
|
|
59
77
|
- the `.statements` path and any reason for re-freezing;
|
|
60
78
|
- for a closed proof, its assumptions, including integer widths, bounds and each theorem hypothesis;
|
|
79
|
+
- each theorem's WITNESS status, with `absent` and `unavailable` reported as non-vacuity not checked;
|
|
80
|
+
- whether the kernel replay passed or was unavailable;
|
|
61
81
|
- the number of differential vectors on which the model and production code agree, their integer widths, or an explicit statement that the comparison was not run.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Property review brief
|
|
2
|
+
|
|
3
|
+
Follow this brief to review one model's properties against the code it describes. A property can pass every check and still promise less than the code's callers rely on, so this review reads the properties, not the proofs. Your task gives the target's row, the source files with their line ranges, the model's files and the absolute path `<skill-dir>`. You did not write the model, and you do not get the report of the agent that did. Write no files.
|
|
4
|
+
|
|
5
|
+
## Read
|
|
6
|
+
|
|
7
|
+
Read each source file in full, then the model:
|
|
8
|
+
|
|
9
|
+
- for TLA+, the spec's properties, its fairness conditions and the `check` lines of its matrix;
|
|
10
|
+
- for Lean, the public theorems with their hypotheses and the definitions they mention;
|
|
11
|
+
- for Kani, each harness's `kani::assume` calls, assertions and `kani::cover!` witnesses.
|
|
12
|
+
|
|
13
|
+
Read the assumptions in the model's header and the fix commits in the row.
|
|
14
|
+
|
|
15
|
+
## Questions
|
|
16
|
+
|
|
17
|
+
Ask each of these about every property:
|
|
18
|
+
|
|
19
|
+
1. Does a caller of this code rely on a guarantee that no property states? Name the guarantee and the function.
|
|
20
|
+
2. Does an assumption, hypothesis, `kani::assume` or fairness condition exclude inputs or schedules that shipped callers produce? Cite the caller's `file:line`.
|
|
21
|
+
3. Would a plausible bug still pass, such as an off-by-one at a boundary, a lost wakeup, a double free, results in the wrong order, or a fix commit from the row undone?
|
|
22
|
+
4. Does the model leave out a branch, error path or step that the code has? Name the code line.
|
|
23
|
+
|
|
24
|
+
## Proposed mutations
|
|
25
|
+
|
|
26
|
+
Write each finding that a bug in the model can show as a mutation, in the syntax that `<skill-dir>/scripts/mutate.py` documents at its top:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
mutation <what goes wrong, in the code's terms>
|
|
30
|
+
detects <property or fully qualified harness; TLA+ and Kani only, never Lean>
|
|
31
|
+
- <a line of the model file, quoted exactly; together the lines occur once>
|
|
32
|
+
+ <the line with the bug>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
A mutation edits only the model file beside the mutations file. For a Kani harness kept apart from the production code, a bug in the code cannot be written this way; report it as an open finding.
|
|
36
|
+
|
|
37
|
+
## Report
|
|
38
|
+
|
|
39
|
+
Give:
|
|
40
|
+
|
|
41
|
+
- each proposed mutation, with the question it answers and the source `file:line` it rests on;
|
|
42
|
+
- each finding that no mutation can express, such as a guarantee that no property states or a code path the model leaves out, with its source `file:line`;
|
|
43
|
+
- "no findings" when there are none.
|
|
44
|
+
|
|
45
|
+
Do not restate the model, grade it or propose rewrites of its proofs.
|
|
@@ -26,7 +26,8 @@ The row in your task gives the commits since the harness was last synced and
|
|
|
26
26
|
says whether any of them changed the guarantee on purpose. The harness calls the
|
|
27
27
|
production code, so drift shows as a compile error or a failed check. Update its
|
|
28
28
|
bounds, stubs, contracts and covers where they no longer fit the code. Change a
|
|
29
|
-
property only
|
|
29
|
+
property only with that evidence or a specification correction accepted by the
|
|
30
|
+
main thread under step 3 of the skill. Add a mutation, with `detects`
|
|
30
31
|
naming the harness, for each branch or step the update adds. Update the header
|
|
31
32
|
to the code you read.
|
|
32
33
|
|
|
@@ -65,10 +66,16 @@ printed installation remedy before making any claim about the code. A compilatio
|
|
|
65
66
|
error, missing harness or incomplete verifier report fails.
|
|
66
67
|
|
|
67
68
|
Put `<Name>.mutations` beside the assigned `<Name>.rs`. Use
|
|
68
|
-
`detects <fully-qualified-harness>` for each mutation. The mutation runner
|
|
69
|
-
the
|
|
69
|
+
`detects <fully-qualified-harness>` for each mutation. The mutation runner uses
|
|
70
|
+
the bundled Cargo to find the crate's workspace and local dependencies, copies
|
|
71
|
+
them to temporary storage with their relative paths intact, and checks the named harness. A compiler
|
|
70
72
|
error never counts as detection. Every discovered harness needs a mutation.
|
|
71
73
|
|
|
74
|
+
For each fix commit in your row whose fixed code is in the file beside the
|
|
75
|
+
mutations file, add a mutation that restores the code before the fix, with the
|
|
76
|
+
commit's short hash in its label. The runner edits only that file, so report a
|
|
77
|
+
fix in any other file as not replayed.
|
|
78
|
+
|
|
72
79
|
## Counter-examples
|
|
73
80
|
|
|
74
81
|
The helper prints failed checks with source locations and Kani's generated
|
|
@@ -87,8 +94,9 @@ Never disable unwinding checks to obtain a pass.
|
|
|
87
94
|
## Report
|
|
88
95
|
|
|
89
96
|
Report each property, input bounds, integer widths, unwind bound, assumptions,
|
|
90
|
-
cover witnesses, mutation results and source location.
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
cover witnesses, mutation results and source location. Give each fix commit from
|
|
98
|
+
the row with the verdict of its mutation, or say it was not replayed. For each
|
|
99
|
+
counter-example, include its inputs and reproducing test and say whether shipped
|
|
100
|
+
callers can pass those inputs. Use `reproduced`, `reachable at shipped settings` or `model-only`
|
|
93
101
|
as appropriate. A pass covers the stated bounded inputs only. Report unavailable
|
|
94
102
|
tools as not checked with the remedy, never as a pass or a model failure.
|
|
@@ -43,7 +43,7 @@ Kani supports Linux and macOS on x86_64 and aarch64. See the [pinned installatio
|
|
|
43
43
|
|
|
44
44
|
The Rust checker discovers proof harnesses and checks each selected harness separately. It reports the unwind bound and check count, rejects an insufficient bound and any cover condition that was not satisfied, and prints a concrete playback test for a failed assertion when Kani can produce one. Larger inputs and loops remain outside the reported bounds. Crate builds may obtain dependencies declared in Cargo; the template has none.
|
|
45
45
|
|
|
46
|
-
The mutation runner reads `Name.mutations` beside `Name.rs`,
|
|
46
|
+
The mutation runner reads `Name.mutations` beside `Name.rs`, uses the bundled Cargo to find the crate's workspace and local dependencies, and copies them to a temporary directory with their relative paths intact. It checks the harness named by `detects` and leaves the source crate unchanged. Each harness must have a mutation that its property detects.
|
|
47
47
|
|
|
48
48
|
## Lean 4
|
|
49
49
|
|
|
@@ -8,7 +8,7 @@ Write `tla/<Name>.tla`, `tla/<Name>.matrix` and `tla/<Name>.mutations` in the ta
|
|
|
8
8
|
|
|
9
9
|
## Existing model
|
|
10
10
|
|
|
11
|
-
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the spec where it no longer describes the code. Change a property only
|
|
11
|
+
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the spec where it no longer describes the code. Change a property only with that evidence or a specification correction accepted by the main thread under step 3 of the skill. Add a mutation for each step, branch or wait the update adds, naming the property that must fail on it. Update the header to the code you read.
|
|
12
12
|
|
|
13
13
|
## Model
|
|
14
14
|
|
|
@@ -53,13 +53,14 @@ The matrix runner prints PASS or FAIL per run and a SUMMARY line. A failing run
|
|
|
53
53
|
|
|
54
54
|
Each reach check prints its own PASS with the shortest witness length in states and transitions, or FAIL when the model never reaches the state. Reach searches use one worker and ignore deadlock so they can finish exploring a stopped model. The SUMMARY counts reach checks separately; its state total covers ordinary runs only. Use `detects reach:<Operator>` for a mutation that removes a required state. Reach checks do not count as properties for mutation coverage.
|
|
55
55
|
|
|
56
|
-
Before reporting a pass, list mutations that represent plausible code bugs in the mutations file. Try replacing `while` with `if`, removing a broadcast, replacing FIFO order with stack order, leaving a flag set, or taking an item without removing it. Each mutation names the one property that must fail on it. The mutation runner applies each to a copy of the spec. Revise a property it reports as UNCOVERED, and the property or the mutation behind each MISSED line.
|
|
56
|
+
Before reporting a pass, list mutations that represent plausible code bugs in the mutations file. Try replacing `while` with `if`, removing a broadcast, replacing FIFO order with stack order, leaving a flag set, or taking an item without removing it. Each mutation names the one property that must fail on it. For each fix commit in your row, add a mutation that restores the behaviour the code had before the fix, with the commit's short hash in its label. The mutation runner applies each to a copy of the spec. Revise a property it reports as UNCOVERED, and the property or the mutation behind each MISSED line.
|
|
57
57
|
|
|
58
58
|
## Report
|
|
59
59
|
|
|
60
60
|
Report only after reading the output of both commands. If either exits 3 with `UNAVAILABLE`, report "not checked" with the printed remedy; do not claim a pass or a model failure. Give:
|
|
61
61
|
|
|
62
62
|
- the file paths, both commands and their SUMMARY lines;
|
|
63
|
+
- each fix commit from the row and the verdict of its mutation;
|
|
63
64
|
- each reach predicate, its selected run and witness length;
|
|
64
65
|
- each FAIL line, with every step of its trace mapped to a code event and `file:line`;
|
|
65
66
|
- for each counter-example, whether the shipped constants and callers can reach it;
|