agent-formal-verify 0.4.19 → 0.4.21
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 +38 -0
- package/package.json +1 -1
- package/skills/formal-verify/SKILL.md +6 -6
- package/skills/formal-verify/references/evidence.md +1 -1
- package/skills/formal-verify/references/helpers.md +3 -16
- package/skills/formal-verify/references/lean-brief.md +1 -1
- package/skills/formal-verify/references/lean-helpers.md +5 -0
- package/skills/formal-verify/references/rust-brief.md +16 -22
- package/skills/formal-verify/references/rust-helpers.md +18 -0
- package/skills/formal-verify/references/setup.md +5 -3
- package/skills/formal-verify/references/tla-brief.md +2 -1
- package/skills/formal-verify/references/tla-helpers.md +12 -0
- package/skills/formal-verify/scripts/baseline.py +73 -19
- package/skills/formal-verify/scripts/kani_reader.py +33 -3
- package/skills/formal-verify/scripts/lean.py +124 -2
- package/skills/formal-verify/scripts/lean_mutations.py +2 -5
- package/skills/formal-verify/scripts/mutate.py +50 -19
- package/skills/formal-verify/scripts/processes.py +16 -4
- package/skills/formal-verify/scripts/tlc.py +206 -42
- package/skills/formal-verify/scripts/tlc_report.py +2 -2
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 0.4.21 - TLA+ matrix symmetry and cfg checks, a TLC check in setup, natively built Lean analysis, and Kani baselines that read the items beside a harness
|
|
4
|
+
|
|
5
|
+
The matrix runner and `mutate.py` now reject, before any run, a matrix line that could change the generated cfg beyond itself. That is a name on a `check` line, or a constant's name, that is not a TLA+ identifier or that is a cfg keyword of TLC or everystate, such as `TYPE` or `TYPE_CONSTRAINT`, or a TLA+ reserved word, and a `reach` operator that is not a TLA+ identifier or is a reserved word. It is also a constant's value that holds a comment opener, a string that it does not close, or a cfg keyword outside a string that is not the whole value or a whole set element, such as `{}PROPERTIES`. Each such line prints `FAIL <matrix>:<line>:` with the problem, and both runners exit 2. `baseline.py record` fails on the same lines. Before this change, the check line `check INVARIANTS InWindow PROPERTIES Bogus`, the constant `FailAt={}PROPERTIES(**)Bogus` or a constant named `PROPERTIES(**)Bogus(**)CONSTANT(**)FailAt` added a `PROPERTIES Bogus` statement to the cfg, and a value with an unclosed string made TLC stop with an unexpected exception.
|
|
6
|
+
|
|
7
|
+
`setup.sh tla` with Java TLC now checks a one-state model before it prints `READY`, so where TLC cannot listen on a local port, setup prints the matrix runner's `UNAVAILABLE` line and exits 3. Before this change, setup printed `READY TLC` there, and the agent learned that TLC could not run only after it had written a model. The check adds about 0.6 seconds: setup took 0.76 s at the median of ten runs against 0.17 s before, on an Apple Silicon Mac with JDK 21. With an unusable `TMPDIR`, setup now prints only its `FAIL` line, without a `READY` line before it. Setup with everystate runs no model.
|
|
8
|
+
|
|
9
|
+
A TLA+ matrix section can hold one `symmetry <Operator>` line, which adds `SYMMETRY <Operator>` to the cfg of each run and `reach` check in the section and of the mutation runs taken from it. On the template with three workers, `Perms == Permutations(Workers)` and a section of the invariants and reach checks, the `window=4 items=5 workers=3` run falls from 46,451 to 8,019 distinct states on TLC 1.7.4 and on everystate 0.4.6, and every run, reach witness length and mutation verdict stays the same. TLC can miss a liveness violation under symmetry, so the runner refuses the line in a section that checks a `PROPERTY` or `PROPERTIES`, and in a section with two such lines. It prints a `FAIL` line, runs that section without symmetry and exits 1, and the mutation runner and baseline helper stop on that line. The operator passes the same name check as a `check` name, so `symmetry PROPERTIES` stops the runners with status 2 before any run. The baseline helper records each run's symmetry and the operator's definition, so adding, removing or changing the line prints `CHANGED`. The TLA+ brief says when symmetry is sound: a `CHOOSE` over the set, a value named in the spec or a constant, or an order on the values can make an invariant pass falsely or a reach check report "never reached", and no runner detects that.
|
|
10
|
+
|
|
11
|
+
The Lean checker and the mutation runner now run `scripts/lean-analysis.lean` as a program that the pin's own `lean` and `leanc` build the first time they use the toolchain. The program stays in `~/.cache/agent-formal-verify/lean-analysis`, or in `LEAN_ANALYSIS_CACHE` when that is set, and nothing is written into the skill directory. Before this change, every audit and every mutation ran the file with `lean --run`, which elaborated it and imported Lean for it on each call, and then imported Lean a second time for the model. On the Lean template, with Lean 4.35.0 on an Apple M5 Pro, the median of seven interleaved runs of a `lean-check.sh` call went from 3.2 s to 1.8 s, and of a run of its three mutations from 8.3 s to 3.0 s, below the 2.3 s and 7.3 s measured before the analysis moved into one program. The first call with a toolchain spends about 4 s on the build. The output is unchanged. A toolchain without `leanc`, or a build that fails, runs the file with `lean --run` as before, and a failed build prints why on `stderr`.
|
|
12
|
+
|
|
13
|
+
The Kani baseline now records the rest of each module that holds a harness, without its functions, as `items in <module>`: its `use` declarations, constants, macro definitions and calls, and the headers of its modules and `impl` blocks. A change there prints `CHANGED` with `changed items in <module>`. Before this change, a `use super::fake::claim;`, a `const claim` or a macro that defines `fn claim`, added beside a harness, took the place of the `claim` that `use super::*;` brings in, so the harness checked the stand-in and `compare` printed `UNCHANGED`. A record made before this change holds no such items, so `compare` prints `CHANGED` with a `previous baseline did not record items in <module>` line for each module until the file is recorded again, and `move` keeps no `items in` when it merges such a record with a newer one. A harness moved from a crate of its own with `baseline.py move` now prints one `changed items in proofs` line for the `use crate as <name>;` that the Rust brief adds; the Rust helper reference says to accept it.
|
|
14
|
+
|
|
15
|
+
`references/rust-helpers.md` and `references/rust-brief.md` are shorter. With `references/helpers.md`, a Rust target now reads 28,090 bytes, 1,153 under the 29,243-byte limit that keeps the read in one inline tool result. The three files held 29,236 bytes before this change and the older-record note above, so an addition of more than 7 bytes failed the size test. The notes on older Kani records are now one sentence, since `compare` prints what to review for each such record, and text that repeated another section or described how the helpers work inside is gone. The TLA+ and Lean reads are unchanged.
|
|
16
|
+
|
|
17
|
+
The native build of `scripts/lean-analysis.lean` is now named for the size and modification time of the toolchain's `bin/lean`, of each library in its `lib/lean` and of each `.olean` file under that directory. Before this change it read only `bin/lean`, which on macOS is a 49,968-byte launcher in both Lean 4.35.0 and 4.36.0, while the program links Lean's libraries and reads the `.olean` files. With a path pin whose directory held 4.35.0 and then 4.36.0, and `bin/lean` given its old modification time, the next `lean-check.sh` reused the 4.35.0 program and failed with `failed to read file '…/lib/lean/Init.olean', incompatible header`; it now builds a new program and passes. Reading the files costs each Lean checker and mutation runner process 15 ms with Lean 4.20.0 (1,529 files) and 35 ms with 4.35.0 (2,565 files), at the median of 21 runs, against 0.2 ms before. Each program in the cache is built once more after the upgrade.
|
|
18
|
+
|
|
19
|
+
A matrix constant can again use a cfg keyword as a model value when the keyword is the whole value, a whole set element or inside a string, as in `Mode=INIT`, `Mode={TYPE,VIEW}` or `Mode="INIT"`, and a `reach` operator can again be named like a cfg keyword, as in `reach INIT | label`. The check above had refused them, though TLC 1.7.4 and everystate 0.4.6 read each of the 24 keywords in those places as a model value or string, and the reach check names its operator in a wrapper module rather than in the cfg. A keyword in any other place, such as `FailAt={}CONSTANT`, still stops the runners with status 2; both engines read that one as a second `CONSTANTS` statement and pass the run.
|
|
20
|
+
|
|
21
|
+
The line of a run or `reach` check under a section's `symmetry` line now names the operator, as in `PASS BoundedQueue window=4 items=5 workers=3 8019 distinct states found under symmetry Perms` or `FAIL One reach Full n=4 under symmetry Perms: the model never reaches this state`. So do the run's row and the title of its trace in the `TLC_HTML_REPORT` report, and the mutation runner's `DETECTED` line, as in `Counted fails in run 'three' under symmetry Perms`. A `MISSED` line names each run that passed under symmetry, as in `MISSED <label>: run 'three' passes under symmetry Perms`. Before this change, these lines matched those of a full run, so a reader without the matrix could not tell that 8019 counted one state for each set of states that the symmetry merges, not the 46,451 states of a full run, or that the verdict depended on the model treating the values alike.
|
|
22
|
+
|
|
23
|
+
## 0.4.20 - Protocols between processes routed to TLA+, per-engine helper notes, TLC sandbox reporting, and mutation and Kani baseline fixes
|
|
24
|
+
|
|
25
|
+
The skill now sends protocols between processes, such as message delivery, retries, leases and crash recovery, to TLA+ in any language. Kani stays the choice for a bounded sequential Rust function, and Lean for sequential properties in other languages or proofs for every size. Before this change, the checker table named only thread interleavings, and the skill preferred Kani for any Rust function whose inputs and loops can be bounded.
|
|
26
|
+
|
|
27
|
+
The mutation runner now prints a `FAIL` line for every malformed mutation in the file before it stops, and names the lines where `-` text that occurs more than once starts, as in `its - text occurs 3 times in <model>, want 1 (lines 12, 40, 77)`. Before this change, it stopped at the first malformed mutation, so a file with two stale mutations took two runs, and a repeated `-` text took a search of the model to find.
|
|
28
|
+
|
|
29
|
+
`references/helpers.md` now holds what every engine shares, and the matrix runner, Lean checker and Rust checker, with the TLA+ and Kani parts of the baseline helper, moved to `references/tla-helpers.md`, `references/lean-helpers.md` and `references/rust-helpers.md`. The skill reads the shared file with the part for each target's engine. Each line moved unchanged. A Lean or TLA+ target now reads 9.6 KB or 10.5 KB of helper notes in place of 22.1 KB, and a Rust target 18.3 KB. Before this change, reading the helper reference with a brief in one command overflowed the inline output limit in two of six eval traces, and the agent read only a 2 KB preview.
|
|
30
|
+
|
|
31
|
+
A Java TLC run that cannot listen on a local port, as under a sandbox that denies network binding, now makes the matrix and mutation runners print an `UNAVAILABLE` line and exit 3. The line names two remedies: run where processes may listen on localhost, or set `TLC_ENGINE=everystate`, which opens no port. TLC's fingerprint set is an RMI object, so every run opens a port, even on one machine. Before this change, each run printed `FAIL ... TLC threw an unexpected exception`, which reads as a model failure, and the agent searched the references for a fix that they do not hold.
|
|
32
|
+
|
|
33
|
+
The TLA+, Lean and Rust briefs now give the mutations file's syntax: a `mutation` line, the `detects` line each engine needs, `-` lines that quote consecutive model lines occurring once, and `+` lines that replace them. Before this change, only `mutate.py`'s own header and the review brief gave it. A Lean eval run grepped the helper reference and read `mutate.py`'s source to learn how to replace several lines, and a Kani run wrote a mutation with two `detects` lines.
|
|
34
|
+
|
|
35
|
+
Kani baseline comparison reports `added body <function>` for a new proof harness when previously recorded code uses its name. Check whether the new harness shadows a function that an existing proof calls or takes as a function value.
|
|
36
|
+
|
|
37
|
+
A Kani check, a Lean check or a TLA+ run whose `stderr` reader exits while the check runs, such as `head -n 1`, now exits with its verdict's code. Before this change, the elapsed-time line that could not be written stayed in Python's `stderr` buffer, and the flush at shutdown failed on it again, so a passing check exited 120.
|
|
38
|
+
|
|
39
|
+
The Kani baseline reads a function's body after a braced const argument in its return type or where clause, a braced type macro, or the never return type. Older records can contain a const expression in place of the body or omit the function. Review affected functions against the original revision and record them again.
|
|
40
|
+
|
|
3
41
|
## 0.4.19 - Protocols between processes in the TLA+ brief, TLA+ runs with stderr closed, and Kani baseline and mutation fixes
|
|
4
42
|
|
|
5
43
|
Step 1 of the skill now searches for protocols between processes or services, such as retries, timeouts, leases, idempotency keys, queue consumers and webhook handlers, and the TLA+ brief says how to model them: lost and repeated messages and crashes are separate actions that constants inject at any point, a timeout can fire whenever a caller waits, each send remains separately deliverable, including a retry with the same payload, and messages can arrive in any order, a crash keeps only durable state and a restart runs the recovery code, a request can still take effect after its caller times out, and a lease can expire while its holder still acts. The brief says which of these steps get fairness. Such a model checks `TypeOK` and the one promise whose break harms a user, and adds a property from a short list, such as at most one effect per request key or no accepted write with a lower fencing token, only when the code makes that promise. The brief now sizes each step to the atomic unit that the code guarantees, such as a critical section, a compare-and-swap, or a transaction whose isolation or conflict mechanism protects its whole relevant read/decision/write dependency, so row locks or per-key conditions alone do not collapse an unprotected predicate read and later write, and it lists mutations for these protocols.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: formal-verify
|
|
3
|
-
description: "Model-check thread protocols with TLA+ and TLC, prove sequential invariants with Lean 4, and check bounded Rust functions with Kani. Map counter-examples to source locations, reproductions and fixes, and keep the models in CI. Bring existing models back in line after the code changes. Use for /agent-formal-verify:formal-verify, formal verification, model checking, Lean proofs, Kani, bounded Rust verification, rechecking models after code changes, or concurrency bugs that runtime tests cannot reproduce."
|
|
3
|
+
description: "Model-check thread and interprocess protocols with TLA+ and TLC, prove sequential invariants with Lean 4, and check bounded Rust functions with Kani. Map counter-examples to source locations, reproductions and fixes, and keep the models in CI. Bring existing models back in line after the code changes. Use for /agent-formal-verify:formal-verify, formal verification, model checking, Lean proofs, Kani, bounded Rust verification, rechecking models after code changes, or concurrency bugs that runtime tests cannot reproduce."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Formal verify
|
|
@@ -11,13 +11,13 @@ Choose tools according to the target:
|
|
|
11
11
|
|
|
12
12
|
| What can go wrong | Tool | Why |
|
|
13
13
|
| --- | --- | --- |
|
|
14
|
-
| Thread interleavings
|
|
14
|
+
| Thread interleavings (wakeups, ownership, delivery, close, error routing) or interprocess message delivery, retries, leases and crash recovery | TLA+ with TLC | TLC explores the states of a small instance and reports counter-examples |
|
|
15
15
|
| Overflow, out-of-bounds access, panics and broken invariants in a Rust function with bounded loops | Kani | Kani checks the real code for every input within the stated bounds |
|
|
16
16
|
| Arithmetic or sequential transitions that break bounds, invariants or encoder round trips, or reach states the code assumes impossible | Lean 4 | Evaluate bounded instances, then prove the property for every size |
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Use TLA+ for interprocess behavior in any language. Prefer Kani for a bounded sequential Rust function. Use Lean for sequential properties in other languages or proofs for every size.
|
|
19
19
|
|
|
20
|
-
A
|
|
20
|
+
A protocol that depends on arithmetic such as `slot = item mod window` needs both tools. Use TLA+ for the interleavings with the arithmetic as a constant, and Lean for the arithmetic.
|
|
21
21
|
|
|
22
22
|
Use the tool the user names. When the table gives another tool for part of the target, report what the named tool leaves unchecked.
|
|
23
23
|
|
|
@@ -63,7 +63,7 @@ Each setup command also reports the temporary directory's free space; [tool setu
|
|
|
63
63
|
|
|
64
64
|
If a system prerequisite such as Java or elan is missing, use the [setup skill](../setup/SKILL.md) to prepare it within the user's installation constraints and existing authorization. Report any prerequisite that cannot be prepared. If `java` on PATH has no runtime, set `JAVA` to a working JDK's `java` binary for the setup helper and the matrix runner.
|
|
65
65
|
|
|
66
|
-
Read the [helper reference](references/helpers.md) before you interpret a helper's output.
|
|
66
|
+
Read the [helper reference](references/helpers.md) and the part for each target's engine, [TLA+](references/tla-helpers.md), [Lean](references/lean-helpers.md) or [Rust](references/rust-helpers.md), before you interpret a helper's output. They say what each helper checks and prints. The helpers:
|
|
67
67
|
|
|
68
68
|
- The setup helper: [`scripts/setup.sh`](scripts/setup.sh)
|
|
69
69
|
- The matrix runner: [`scripts/tlc-matrix.sh`](scripts/tlc-matrix.sh)
|
|
@@ -89,7 +89,7 @@ Name the brief file and leave its text out of the prompt. The [TLA+ brief](refer
|
|
|
89
89
|
|
|
90
90
|
An agent writes only its own files, `tla/<Name>.tla`, `.matrix` and `.mutations`, `lean/Model/<Name>.lean`, `.mutations` and `.statements`, or the `#[cfg(kani)]` harness module in the production file that defines its Rust function and the `.mutations` file beside it, so parallel agents share none. Give one agent every Rust target in one production file. An existing Lean project keeps its layout and must pin Lean 4.20.0 or later. A Kani harness that an earlier run wrote in a crate of its own moves into its production file when the Rust brief's "Moving a harness" section allows, so it gets an agent even when it passes; otherwise its agent edits it and its `.mutations` file in place.
|
|
91
91
|
|
|
92
|
-
When the agents have reported, delete each moved harness's old file, and its crate, workspace entry and CI steps once they hold nothing else. Then 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. For a moved harness, first run `baseline.py move` as the [helper reference](references/helpers.md) says. 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 harness or helper body, cover or stub changed, a Kani harness was removed, renamed, no longer compiles or had its `cfg` guards changed on a route the record reads, a Kani assumption was added or changed, or a function or method was added beside a Kani harness. Accept a move only as that reference says. 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 narrowed input in a Kani helper outside the harness's module. 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. Report each file that prints `NOT CHECKED` as not checked against Kani.
|
|
92
|
+
When the agents have reported, delete each moved harness's old file, and its crate, workspace entry and CI steps once they hold nothing else. Then 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. For a moved harness, first run `baseline.py move` as the [Rust helper reference](references/rust-helpers.md) says. 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 harness or helper body, cover or stub changed, a Kani harness was removed, renamed, no longer compiles or had its `cfg` guards changed on a route the record reads, a Kani assumption was added or changed, or a function or method was added, or another item such as a `use` changed, beside a Kani harness. Accept a move only as that reference says. 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 narrowed input in a Kani helper outside the harness's module. 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. Report each file that prints `NOT CHECKED` as not checked against Kani.
|
|
93
93
|
|
|
94
94
|
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.
|
|
95
95
|
|
|
@@ -13,7 +13,7 @@ Include the matching meaning from this table where each kind of evidence first a
|
|
|
13
13
|
| A bounded search passes | Every input up to the stated bound was tried. |
|
|
14
14
|
| 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. |
|
|
15
15
|
| 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. |
|
|
16
|
-
| Specification unchanged | The baseline comparison preserved each recorded run's inputs and checks, reach check's selected inputs, property and fairness definition, action subscript such as `vars`, statement record, qualified Kani harness name with its `should_panic` and `unwind` attributes and the `cfg` attributes that can switch it off on each route the record reads, function-owned assumption, cover and stub, and body of each Kani harness and of each function or method in a module that holds one, such as an input helper or an `impl kani::Arbitrary`, including its assertions, input construction and the conditions around its assertions, apart from comments, layout and covers whose conditions cannot run code. It also found no function or method added in those modules, other than a new harness, since
|
|
16
|
+
| Specification unchanged | The baseline comparison preserved each recorded run's inputs and checks, reach check's selected inputs, property and fairness definition, action subscript such as `vars`, statement record, qualified Kani harness name with its `should_panic` and `unwind` attributes and the `cfg` attributes that can switch it off on each route the record reads, function-owned assumption, cover and stub, and body of each Kani harness and of each function or method in a module that holds one, such as an input helper or an `impl kani::Arbitrary`, including its assertions, input construction and the conditions around its assertions, apart from comments, layout and covers whose conditions cannot run code. It also found no function or method added in those modules, other than a new harness, and no change to their other items, such as a `use`, `const` or macro call, since each can shadow a function that a glob import brings in. It does not cover the body of a function or method outside those modules, apart from its assumptions, covers and stubs, or the `cfg` attributes on a route that its record value lists under `unread(...)`; `git diff` does. |
|
|
17
17
|
| UNAVAILABLE | The tool could not run. This target was not checked; give the printed remedy. |
|
|
18
18
|
| reproduced | A deterministic test or race-detector run fails on the production code. |
|
|
19
19
|
| reachable at shipped settings | The shipped constants and callers permit the counter-example, but no production reproduction has confirmed it yet. |
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Detailed behaviour of the verification scripts under `scripts/`. Run each helper from the target repository using `bash` or `python3` with `<skill-dir>` resolved to the installed `formal-verify` skill directory.
|
|
4
4
|
|
|
5
|
+
Each engine has a part of its own: [TLA+](tla-helpers.md), [Lean](lean-helpers.md) and [Rust](rust-helpers.md). Read the part for each target's engine with this file.
|
|
6
|
+
|
|
5
7
|
- **Setup helper ([`scripts/setup.sh`](../scripts/setup.sh))**: verifies the pinned TLC JAR (`tla`), or `everystate` 0.4.6 or later when `TLC_ENGINE=everystate`, checks the pinned Kani driver and bundled Rust toolchain (`rust`), and is the only helper that installs a Lean toolchain (`lean`).
|
|
6
|
-
- **Matrix runner ([`scripts/tlc-matrix.sh`](../scripts/tlc-matrix.sh))**: runs TLC (or the native `everystate` engine with `-lncheck final` when `TLC_ENGINE=everystate`, requiring no JDK or JAR) with a matrix of constants. It prints an `ENGINE` line naming the checker and version before the first run, then one `PASS` or `FAIL` per run with its state count, then a `SUMMARY` line with the totals (tagged with `(everystate <version>)` when using `everystate`). Stops each run after sixty minutes, or after the limit in `TLC_TIMEOUT` as [setup](setup.md) describes, and forwards periodic elapsed-time and `Progress(...)` updates to `stderr` during long runs. A failing run prints its error trace reduced by [`scripts/tlc_trace.py`](../scripts/tlc_trace.py) to the variables each step changed. Set `TLC_HTML_REPORT=<path>` to also write a self-contained offline HTML report through [`scripts/tlc_report.py`](../scripts/tlc_report.py) with the active engine metadata, the run table, an interactive native SVG state chain, a variable diff panel, and copyable Mermaid `stateDiagram-v2` source for each failing and `reach` witness trace. The runner checks the path after checking the TLA+ engine and before the first run, and a path where it cannot write the report prints an `UNAVAILABLE TLC_HTML_REPORT=...` line with the remedy and exits 3. It replaces the report in one step, and a written report leaves `stdout` and the exit status as they are without one. If the write fails after the runs, the runner prints the same line and exits 1 when a run failed and 3 otherwise. `tlc.py ready` and `mutate.py` ignore the variable. Copy [`examples/tla-template/`](../examples/tla-template/BoundedQueue.tla) to start a spec and its matrix.
|
|
7
|
-
- **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](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. While the build, the audit or the replay runs, the checker writes a line such as `[lean] build: 45s elapsed` to `stderr` after fifteen seconds and every thirty seconds after that. The mutation runner writes the same lines while it runs the checker on the unmutated model. It then writes `[lean] unmutated model: <N>s elapsed` while Lean elaborates that model, and a line such as `[lean] mutation no step: 45s elapsed`, which names the mutation, while Lean elaborates each mutant. 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.
|
|
8
|
-
- **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, requires a satisfied cover witness in each passing harness, rejects failed checks, and prints concrete playback tests when available. It stops each harness after five minutes, or after the limit in `KANI_HARNESS_TIMEOUT` as [setup](setup.md) describes, and fails a harness that reaches the limit with a message that names the setting. Each harness check, here or in the mutation runner, can take up to that limit, so run the command in the background or with a command timeout longer than the total. While Kani builds the crate or checks a harness, the checker and the mutation runner write a line such as `[kani] proofs::claim_keeps_invariant: 45s elapsed` to `stderr` after fifteen seconds and every thirty seconds after that. When discovery fails because code Kani compiles uses a feature newer than Kani's bundled toolchain (error E0658), the failure names that toolchain, and the [Rust brief](rust-brief.md) says what to rewrite or report. Copy [`examples/kani-template/`](../examples/kani-template/src/lib.rs) for a bounded-queue example.
|
|
9
8
|
- **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. Each Rust mutation gets a fresh copy of the source. When the crate or a local dependency has a Cargo build script, each mutation also gets its own target directory so the script runs for that source tree. Otherwise every mutation reuses the same source and target paths to cache dependency builds. It prints `DETECTED` or `MISSED` per mutation with what failed, `UNCOVERED` for a TLA+ property or a Kani harness in the adjacent Rust file 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, and so does a mutation that edits the text of a theorem whose proof then fails. The runner matches a failing example or `#guard` to one occurrence in the original model, so a failure in an example or `#guard` that the mutation adds, or in one that it cannot match to a single original occurrence, also reaches no verdict. So does a TLA+ mutation whose check reaches the `TLC_TIMEOUT` limit, or a Kani mutation whose harness reaches the Rust checker's time limit. TLA+ runs inherit `TLC_ENGINE`, print the `ENGINE` line before checking the unmutated model, and tag `SUMMARY` with `(everystate <version>)` when using `everystate`. A mutation with no verdict stops the run with a `FAIL` line. A Lean model needs its `.statements` file before its mutations run. All three templates include a mutations file.
|
|
10
9
|
- **Sync helper ([`scripts/sync.py`](../scripts/sync.py))**: takes an existing model's files, the source files its header names as `--source` and the functions and shared variables it covers as `--name`, and lists what changed since the model was last synced. [Step 1 of the skill](../SKILL.md#1-pick-the-targets) says what to do with its `SYNC none`, `READ` and `MISSING` lines.
|
|
11
10
|
- Output:
|
|
@@ -19,26 +18,14 @@ Detailed behaviour of the verification scripts under `scripts/`. Run each helper
|
|
|
19
18
|
- Documents, such as `.md`, `.txt` and `.tex` files and `README` or `CHANGELOG` with no extension, TLA+ and Lean model files, and each of the model's files that is not also given as `--source` are not searched, unless a source path has the same extension. They get no `PATH` line, and the `READ` command does not show their changes, such as a changelog entry.
|
|
20
19
|
- In languages other than Rust, such as C, JavaScript or Python, a mention of a covered name in a comment or a string counts as finding it, so the name gets no `MISSING` line even when only a comment still mentions it.
|
|
21
20
|
- **Baseline helper ([`scripts/baseline.py`](../scripts/baseline.py))**: records what each model specifies and later names each part that changed. [Steps 2](../SKILL.md#2-prepare-the-tools) and [3](../SKILL.md#3-model-one-target-per-agent) of the skill say when to run `record` and `compare`, list the changes that `compare` reports and say what to do with them.
|
|
22
|
-
- The Kani baseline includes helpers in an inline module declared inside a function when that module holds a harness. A baseline made before support for these modules can lack their helpers. Review those helpers against the original revision and record the file again.
|
|
23
21
|
- Output of `record <record-file> <model files>`:
|
|
24
22
|
- `RECORDED <file> <digest>` for each file, with an indented `previous <digest>` line under it when the file's entry had another digest.
|
|
25
|
-
- An indented `not checked against Kani: <reason>` line: Kani is missing or the harness file's Cargo package does not compile, so the entry holds what the file's text shows alone.
|
|
26
23
|
- Output of `compare <record-file>`, which exits 1 when a recorded file changed. Each indented line under `CHANGED` counts as a change, except the `not checked against Kani at record, ...` line and the lines under it:
|
|
27
24
|
- `UNCHANGED <file>`, `CHANGED <file>` or `NOT CHECKED <file>` for each recorded file, then `SUMMARY <n> unchanged, <m> changed`, which ends with `, <k> not checked` when a file printed `NOT CHECKED`.
|
|
28
|
-
- An indented `removed <item>`, or `changed <item>` with its `old:` and `new:` values.
|
|
29
|
-
- An indented `added <item>`, which only a new Kani assumption, stub or `body <function>` prints. A function or method added in a module that holds a harness, or under one, can shadow a function that a glob import such as `use super::*;` brings in, so a harness calls the new function with no edit to its own body. Every such function or method prints `added body <function>`, whatever its name, except a new harness, whose body is allowed with it. A harness added in a module that held none puts that module's functions in the record, so each of them prints `added body <function>` once. A record made before the other functions' or the methods' bodies were recorded also prints `added body <function>` for each body it did not record. Check a function that existed at the original revision against that revision. Accept a new function only when each recorded body that names it is listed as added or changed and its change is accepted, and revert it when an unchanged recorded body names it, since that body now calls the new function in place of the one it checked. Then record the file again. A `kani::any_where` assumption includes the complete call, including explicit type arguments. Older records used one representation for plain assumptions and generator predicates. For those records, check the assumptions and generator types against the original revision before recording the file again.
|
|
30
|
-
- In a TLA+ module where a local `INSTANCE` introduces substitutions, or that has an indented definition outside a `LET` or a column-0 definition inside one, the helper compares the complete text of each local module it loaded, with comments removed, so a change to a definition that no property uses also needs review. So does a column-0 definition whose header the helper cannot read, such as an infix operator, which it records with the operators it references, whether or not a property references it.
|
|
25
|
+
- An indented `removed <item>`, or `changed <item>` with its `old:` and `new:` values.
|
|
31
26
|
- An indented `file is missing`: the recorded file no longer exists.
|
|
32
|
-
- An indented `not compiled harness <name>`: Kani compiles a stored harness on no route, such as when `Cargo.toml` drops a default feature that a route's `cfg` needs.
|
|
33
|
-
- An indented `not checked against Kani at record, ...`: `record` could not check the file against Kani, so `compare` cannot tell a harness that stopped compiling from one that never compiled, such as one behind a feature that is not a default. When Kani runs at `compare`, an indented `not compiled now harness <name>` follows for each recorded harness that Kani does not compile. When Kani could not run at `compare` either, the next line gives the reason. When nothing else changed, the file prints `NOT CHECKED` instead of `CHANGED`. When `move` merges such an entry with one that `record` checked against Kani, the merged entry keeps the checked entry's harnesses, so `compare` still prints `not compiled harness <name>` for them and needs Kani. A `NOT CHECKED` file does not count as a change, so `compare` exits 0 when no file printed `CHANGED`. Report its harnesses as not checked against Kani, and name each harness on a `not compiled now` line under it.
|
|
34
27
|
- An indented `FAIL <reason>`: the helper could not read the file or ask Kani, which `compare` needs for a harness file that `record` checked against Kani, or Kani compiles a harness from the file under a name that no route the record reads gives. The reason names the problem.
|
|
35
28
|
- `FAIL baseline: <reason>` exits 1, and a `usage:` line exits 2. `record` fails this way for a file it cannot read, such as a harness file that no route the record reads reaches or a Kani form the record cannot read, where `compare` prints an indented `FAIL` under `CHANGED`. Both fail this way for an unsupported or malformed record file.
|
|
36
|
-
- Cannot see:
|
|
37
|
-
- In TLA+, the actions that `Spec` names under `[][...]_vars`, `WF_` or `SF_`. It does follow the subscript of those forms and of `<<A>>_vars`, such as `vars`, in every definition it follows, and it follows an operator that `Spec` names outside those forms, such as a fairness definition, into its actions.
|
|
38
|
-
- In Kani, the body of a function or method outside the modules that hold harnesses, apart from its assumptions, covers and stubs; read `git diff` for those.
|
|
39
|
-
- A route that the record cannot read: a `mod` declaration or `include!` inside a macro like `cfg_if!`, including a `mod $name;` that a macro builds, or inside a block such as a function body, a `#[path]` or `include!` whose path it cannot read, or a file on the way that fails to parse. It cannot tell where such a route leads, so `record` prints `route not read: <reason>`, which names the file and, except for a file that fails to parse, the line, for each one in the harness file's crates. It adds each to every harness's value as `unread(<file>: <route>; ...)`, with the file relative to the harness file's directory. Adding or removing such a route prints `CHANGED`. It does not record the route's guards, and Kani's check fails only when the route gives the harness another module path, so a guard changed on it can print no `CHANGED` line; read `git diff` for it. When no route that it reads reaches the file, `record` fails and names each of them.
|
|
40
|
-
- A Kani harness file outside any Cargo package is read from its text alone, so neither `record` nor `compare` asks Kani which harnesses it compiles.
|
|
41
|
-
- `baseline.py move <record-file> <old file> <new file>` moves a model's record entry to the file the model moved to, reading the record alone, so a later `compare` checks the new file against what the old one specified, including the harnesses that Kani compiled. For a Kani harness moved into a module of its production file, add `--module <old module> <new module>`, each relative to its file, with `crate` for the file's root, such as `--module crate proofs` for harnesses that sat at the old crate's root, even when the production file is `src/queue.rs`. When the new file already has an entry, the two are merged, and an item in both fails the move. It prints `MOVED <old> -> <new>`. Accept a move when `compare` prints `UNCHANGED`, or `NOT CHECKED` for an entry that `record` could not check against Kani, and `git diff` shows the old file's harness lines in the new module with only their indentation changed, plus the `use crate as <name>;` line and the `#[cfg(kani)] mod proofs` lines around them. When the production file's crate has a route that the record cannot read, `compare` prints a `changed harness` line for each moved harness whose `new:` value only adds an `unread(...)` note to its `old:` value; accept those too, then record the new file again. Any other change, such as an edited assertion, needs the evidence its row cites.
|
|
42
29
|
|
|
43
30
|
## Find process protocols
|
|
44
31
|
|
|
@@ -46,7 +46,7 @@ The checker enforces the `.statements` file beside each checked source. Changing
|
|
|
46
46
|
|
|
47
47
|
The file name limits the Lean checker to your model, so another agent's unfinished file does not fail your check.
|
|
48
48
|
|
|
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.
|
|
49
|
+
List plausible bugs in the mutations file, such as `<` instead of `≤`, a missing `+ 1` or a swapped argument. Write each as a `mutation <label>` line, then `-` lines that quote consecutive lines of the model exactly and occur once in it, then `+` lines that replace them. A mutation without `+` lines deletes the quoted text. 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
50
|
|
|
51
51
|
The mutation runner checks the original file against its frozen declarations with the Lean checker before running any mutants. It 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. The runner matches a failing guard or example to one original occurrence and compares their elaborated statements. When an edit overlaps a check, preserve the check’s text so the runner can identify a unique occurrence on both sides of the edit. A failure in a new or ambiguous check gives the mutation no verdict. Add a mutation that breaks the proof by changing the model outside the theorem, 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
52
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Lean helpers
|
|
2
|
+
|
|
3
|
+
The Lean behaviour of the helpers. The [helper reference](helpers.md) holds what every engine shares; read it first.
|
|
4
|
+
|
|
5
|
+
- **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](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. While the build, the audit or the replay runs, the checker writes a line such as `[lean] build: 45s elapsed` to `stderr` after fifteen seconds and every thirty seconds after that. The mutation runner writes the same lines while it runs the checker on the unmutated model. It then writes `[lean] unmutated model: <N>s elapsed` while Lean elaborates that model, and a line such as `[lean] mutation no step: 45s elapsed`, which names the mutation, while Lean elaborates each mutant. 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.
|
|
@@ -46,9 +46,8 @@ to the code you read.
|
|
|
46
46
|
|
|
47
47
|
## Moving a harness
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
the production file that defines the functions it calls:
|
|
49
|
+
Move a harness that an earlier run wrote in a crate of its own into the
|
|
50
|
+
production file that defines the functions it calls:
|
|
52
51
|
|
|
53
52
|
1. Move its helpers and harnesses into the `#[cfg(kani)] mod proofs` at the
|
|
54
53
|
end of the production file, creating the module if the file has none, and
|
|
@@ -86,7 +85,7 @@ Use `kani::any()` for inputs and `kani::assume` for caller constraints. Record
|
|
|
86
85
|
integer widths, input bounds and each assumption beside the harness. If a callee
|
|
87
86
|
needs a stub or a function contract, name that assumption in the header comment.
|
|
88
87
|
Put `#[kani::unwind(N)]` on every harness, above its real loop bounds. The checker
|
|
89
|
-
requires this explicit bound
|
|
88
|
+
requires this explicit bound. A failed unwinding assertion
|
|
90
89
|
means the bound is too low and fails the check. Discovery and verification both
|
|
91
90
|
enable `-Z stubbing`, so documented `#[kani::stub]` attributes work in either step.
|
|
92
91
|
The checker rejects a harness marked `#[kani::should_panic]` when it would verify
|
|
@@ -103,12 +102,11 @@ Add `kani::cover!` witnesses for the boundary or blocking states each property
|
|
|
103
102
|
depends on, such as a full window or an empty queue. The checker rejects
|
|
104
103
|
unsatisfiable, unreachable and undetermined covers, even when Kani exits
|
|
105
104
|
successfully. Ordinary unreachable assertions are allowed because they describe
|
|
106
|
-
impossible panic branches. Every passing harness
|
|
107
|
-
`Satisfied` cover after its assumptions. Successful assertions alone do not
|
|
105
|
+
impossible panic branches. Every passing harness, an existing coverless one
|
|
106
|
+
included, needs a `Satisfied` cover after its assumptions. Successful assertions alone do not
|
|
108
107
|
establish reachability: Kani also labels compiler safety checks as assertions,
|
|
109
108
|
and one before contradictory assumptions can pass while the property is
|
|
110
|
-
unreachable.
|
|
111
|
-
witness. Every cover must have status `Satisfied`.
|
|
109
|
+
unreachable.
|
|
112
110
|
|
|
113
111
|
## Check
|
|
114
112
|
|
|
@@ -121,11 +119,9 @@ python3 <skill-dir>/scripts/mutate.py /absolute/path/to/crate/src/Name.mutations
|
|
|
121
119
|
|
|
122
120
|
Append fully qualified harness names to check only those properties. The helper
|
|
123
121
|
prints one verdict per harness with the unwind bound and number of checks. It
|
|
124
|
-
requires a complete Kani 0.68.0 bundle and Python 3.9 or later. It
|
|
125
|
-
bundle's driver directly,
|
|
126
|
-
A
|
|
127
|
-
paths resolve against the caller's directory before any temporary work begins.
|
|
128
|
-
The helper installs no Kani runtime. `UNAVAILABLE` means not checked; follow the
|
|
122
|
+
requires a complete Kani 0.68.0 bundle and Python 3.9 or later. It runs the
|
|
123
|
+
bundle's driver directly, so it needs no registered Cargo installer and installs
|
|
124
|
+
no Kani runtime. A relative `KANI_HOME` resolves against the caller's directory. `UNAVAILABLE` means not checked; follow the
|
|
129
125
|
printed remedy before making any claim about the code. A compilation
|
|
130
126
|
error, missing harness or incomplete verifier report fails.
|
|
131
127
|
|
|
@@ -137,12 +133,11 @@ production crate, and report the target as not checked by Kani. A harness in a
|
|
|
137
133
|
separate crate that copies the function checks the copy, not the production
|
|
138
134
|
code, so report it as a model and name the copied source and commit.
|
|
139
135
|
|
|
140
|
-
|
|
141
|
-
`
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
and relative paths to external files. Each selected harness must first pass on
|
|
136
|
+
Write each mutation in `<Name>.mutations` as a `mutation <label>` line, one `detects <fully-qualified-harness>` line, `-`
|
|
137
|
+
lines quoting consecutive lines of `<Name>.rs` that occur once in it, and `+`
|
|
138
|
+
lines replacing them. The mutation runner checks a
|
|
139
|
+
temporary copy of the crate's workspace and local dependencies from the original
|
|
140
|
+
crate directory, so Cargo keeps its configuration and relative paths. Each selected harness must first pass on
|
|
146
141
|
the unmutated source; a compiler error or inconclusive check never counts as
|
|
147
142
|
detection. Every harness declared in the adjacent Rust file needs a mutation.
|
|
148
143
|
An explicit property failure or a lost cover witness can detect a mutation;
|
|
@@ -151,9 +146,8 @@ An explicit `detects` may also name a harness in another file; unrelated
|
|
|
151
146
|
harnesses in other files do not contribute to this file’s coverage requirement.
|
|
152
147
|
|
|
153
148
|
Direct checks and discovery run from the crate directory so Cargo reads crate
|
|
154
|
-
and ancestor configuration. Discovery
|
|
155
|
-
|
|
156
|
-
tree. Cargo may create or update its normal lockfile.
|
|
149
|
+
and ancestor configuration. Discovery writes no `kani-list.json` into the
|
|
150
|
+
source tree. Cargo may create or update its normal lockfile.
|
|
157
151
|
|
|
158
152
|
For each fix commit in your row whose fixed code is in the file beside the
|
|
159
153
|
mutations file, add a mutation that restores the code before the fix, with the
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Rust helpers
|
|
2
|
+
|
|
3
|
+
The Kani behaviour of the helpers. The [helper reference](helpers.md) holds what every engine shares; read it first.
|
|
4
|
+
|
|
5
|
+
- **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, requires a satisfied cover witness in each passing harness, rejects failed checks, and prints concrete playback tests when available. It stops each harness after five minutes, or after the limit in `KANI_HARNESS_TIMEOUT` as [setup](setup.md) describes, and fails a harness that reaches the limit with a message that names the setting. Each harness check, here or in the mutation runner, can take up to that limit, so run the command in the background or with a command timeout longer than the total. While Kani builds the crate or checks a harness, the checker and the mutation runner write a line such as `[kani] proofs::claim_keeps_invariant: 45s elapsed` to `stderr` after fifteen seconds and every thirty seconds after that. When code Kani compiles uses a feature newer than Kani's bundled toolchain (error E0658), discovery fails and names that toolchain, and the [Rust brief](rust-brief.md) says what to rewrite or report. Copy [`examples/kani-template/`](../examples/kani-template/src/lib.rs) for a bounded-queue example.
|
|
6
|
+
- **Baseline helper ([`scripts/baseline.py`](../scripts/baseline.py))** on a Kani harness file:
|
|
7
|
+
- In the output of `record`:
|
|
8
|
+
- An indented `not checked against Kani: <reason>` line: Kani is missing or the harness file's Cargo package does not compile, so the entry holds what the file's text shows alone.
|
|
9
|
+
- In the output of `compare`:
|
|
10
|
+
- A Kani harness's value is the `cfg` guards that can switch it off, followed by its `kani::should_panic` and `kani::unwind(<n>)` attributes and the `unread(...)` note that "Cannot see" describes. When more than one route that the record reads leads to the file, the value holds each route as its crate root's path relative to the harness file's directory and its guards, such as `routes(lib.rs: unguarded; main.rs: cfg(feature = "slow"))`, so adding, removing or guarding any route, or moving a guard from one route to another, changes the harness. The item `body <function>` holds, for a harness and for each other free function or method in an `impl` or trait block in a module that holds a harness or under one, such as an input helper or the `any` of an `impl kani::Arbitrary`, the normalized body without comments, without each `kani::cover!` call whose condition cannot run code, which is an item of its own, and without whitespace except one space where two tokens would otherwise join, such as `{let(window,state)=inputs();...}`. The item `items in <module>`, `items in crate` at the file's root, holds the rest of such a module the same way, without its functions or its modules' contents, such as `use super::*;`. For a helper, the value includes its declaration so a change to a qualifier such as `async`, a parameter, return type or `where` clause is visible even when the body stays the same. A method's name preserves literals in its block's header, so `impl Input<'a'>` and `impl Input<'b'>` keep separate records. The name puts the header, without the whitespace that a reformat can change, between angle brackets, such as `proofs::<impl kani::Arbitrary for State>::any`, and its assumptions and covers carry that name. Reformatting `let y=&x;` as `let y = &x;` leaves the body unchanged. A space that separates a compound operator counts, as does spacing between operators inside a macro's input, where the macro can inspect it. A trailing comma that a formatter adds or removes also changes the body. The reader omits an empty cover, a boolean name or literal, a comparison between scalar literals (booleans, numbers, characters or byte characters), and short-circuit combinations of those conditions. It keeps other expressions, including `state.next == 3`, as well as string and byte-string comparisons that can call stubbed library code. Field access can call `Deref` and comparisons can call an implementation of `PartialEq`. Review an added cover with a retained condition for implicit calls and side effects before accepting the change. An older record can report changed bodies once, for covers it omitted or a helper's declaration, and one made before harness, function or method bodies, `items in` or `kani::any_where` types were recorded prints a `previous baseline ...` line once. Check what each names against the original revision before recording the file again.
|
|
11
|
+
- An indented `added <item>`, which only a new Kani assumption, stub or `body <function>` prints. A function or method added in a module that holds a harness, or under one, can shadow a function that a glob import such as `use super::*;` brings in, so a harness calls the new function with no edit to its own body. An added `use`, `const` or macro call can too, so it changes `items in <module>`. Every such function or method prints `added body <function>`, whatever its name, except a new harness whose name never occurs in previously recorded code. A new proof can shadow a function that an older proof calls or passes as a value. When its name occurs in recorded code, check whether the reference resolves to the added proof. Same-named references in other scopes also trigger it. A harness added in a module that held none puts that module's functions in the record, so each of them prints `added body <function>` once. A record made before the other functions' or methods' bodies were recorded, such as those in a module inside a function, prints `added body <function>` for each. Check a function that existed at the original revision against that revision. Accept a new function or item only when each recorded body that names it is listed as added or changed and its change is accepted, and revert it when an unchanged recorded body names it, since that body now calls the new function in place of the one it checked. Then record the file again. A `kani::any_where` assumption includes the complete call, including explicit type arguments.
|
|
12
|
+
- An indented `not compiled harness <name>`: Kani compiles a stored harness on no route, such as when `Cargo.toml` drops a default feature that a route's `cfg` needs.
|
|
13
|
+
- An indented `not checked against Kani at record, ...`: `record` could not check the file against Kani, so `compare` cannot tell a harness that stopped compiling from one that never compiled, such as one behind a feature that is not a default. When Kani runs at `compare`, an indented `not compiled now harness <name>` follows for each recorded harness that Kani does not compile. When Kani could not run at `compare` either, the next line gives the reason. When nothing else changed, the file prints `NOT CHECKED` instead of `CHANGED`. When `move` merges such an entry with one that `record` checked against Kani, the merged entry keeps the checked entry's harnesses, so `compare` still prints `not compiled harness <name>` for them and needs Kani. A `NOT CHECKED` file does not count as a change, so `compare` exits 0 when no file printed `CHANGED`. Report its harnesses as not checked against Kani, and name each harness on a `not compiled now` line under it.
|
|
14
|
+
- Cannot see:
|
|
15
|
+
- In Kani, the body of a function or method outside the modules that hold harnesses, apart from its assumptions, covers and stubs; read `git diff` for those.
|
|
16
|
+
- A route that the record cannot read: a `mod` declaration or `include!` inside a macro like `cfg_if!`, including a `mod $name;` that a macro builds, or inside a block such as a function body, a `#[path]` or `include!` whose path it cannot read, or a file on the way that fails to parse. It cannot tell where such a route leads, so `record` prints `route not read: <reason>`, which names the file and, except for a file that fails to parse, the line, for each one in the harness file's crates. It adds each to every harness's value as `unread(<file>: <route>; ...)`, with the file relative to the harness file's directory. Adding or removing such a route prints `CHANGED`. It does not record the route's guards, and Kani's check fails only when the route gives the harness another module path, so a guard changed on it can print no `CHANGED` line; read `git diff` for it. When no route that it reads reaches the file, `record` fails and names each of them.
|
|
17
|
+
- A Kani harness file outside any Cargo package is read from its text alone, so neither `record` nor `compare` asks Kani which harnesses it compiles.
|
|
18
|
+
- `baseline.py move <record-file> <old file> <new file>` moves a model's record entry to the file the model moved to, reading the record alone, so a later `compare` checks the new file against what the old one specified, including the harnesses that Kani compiled. For a Kani harness moved into a module of its production file, add `--module <old module> <new module>`, each relative to its file, with `crate` for the file's root, such as `--module crate proofs` for harnesses that sat at the old crate's root, even when the production file is `src/queue.rs`. When the new file already has an entry, the two are merged, and an item in both fails the move, but `items in` texts are joined, the new file's first, and dropped when either entry predates them. It prints `MOVED <old> -> <new>`. Accept a move when `compare` prints `UNCHANGED`, or `NOT CHECKED` for an entry that `record` could not check against Kani, and `git diff` shows the old file's harness lines in the new module with only their indentation changed, plus the `use crate as <name>;` line and the `#[cfg(kani)] mod proofs` lines around them. `compare` prints `changed items in <module>` for that line and, when the production file's crate has a route that the record cannot read, a `changed harness` line for each moved harness whose `new:` value only adds an `unread(...)` note to its `old:` value; accept those too, then record the new file again. Any other change, such as an edited assertion, needs the evidence its row cites.
|
|
@@ -10,7 +10,7 @@ The helpers are in the `scripts/` directory of the installed `formal-verify` ski
|
|
|
10
10
|
|
|
11
11
|
Stay in the target repository and run each helper with `bash` and its absolute path. Pass absolute paths to model projects and matrices. Keep the installed skill files read-only, and create models and build outputs in the target repository. Shared tool caches can serve several repositories; each repository determines its own tool requirements and Lean pins.
|
|
12
12
|
|
|
13
|
-
Every runner writes its temporary state into `TMPDIR` (failing cleanly with `FAIL` if an explicitly set `TMPDIR` cannot be created or written) and removes its working directories between matrix runs and on `SIGINT`, `SIGTERM` or `SIGHUP`. `setup.sh tla`, `setup.sh rust` and `setup.sh lean` stop their readiness check on these signals too, including one sent to the `setup.sh` process alone, and end by the signal. Lean builds write into the model project's `.lake` directory, while `lean-check.sh` places its module lists for the audit and the kernel replay in `TMPDIR
|
|
13
|
+
Every runner writes its temporary state into `TMPDIR` (failing cleanly with `FAIL` if an explicitly set `TMPDIR` cannot be created or written) and removes its working directories between matrix runs and on `SIGINT`, `SIGTERM` or `SIGHUP`. `setup.sh tla`, `setup.sh rust` and `setup.sh lean` stop their readiness check on these signals too, including one sent to the `setup.sh` process alone, and end by the signal. Lean builds write into the model project's `.lake` directory, while `lean-check.sh` places its module lists for the audit and the kernel replay in `TMPDIR`, and the Lean checker and the mutation runner keep their analysis program in the cache that the Lean section below names. `setup.sh` (`tla`, `rust`, `lean`, and `storage`) reports `TEMP_DIR` free space, and `SYSTEM_DISK` free space when the temporary directory is on another device. It warns when the active temporary volume, or the system disk while it holds the temporary directory, has less than `FORMAL_MIN_FREE_GIB` free (default `64` GiB). It also lists larger writable `EXTERNAL_VOLUME` mounts so heavy runs can redirect `TMPDIR` onto an external disk. `bash <skill-dir>/scripts/setup.sh storage` runs this storage check alone. Checkers also warn once on `stderr` before starting when active temporary space drops below `10` GiB (or `FORMAL_MIN_FREE_GIB` when set).
|
|
14
14
|
|
|
15
15
|
To stop a checker, a runner suspends the checker and every process it started, then sends them `SIGTERM` and resumes them, so none can start another process meanwhile. This takes a few `ps` calls, a few tens of milliseconds on an idle machine and longer under load. A runner ended in that time by a signal it does not handle, such as `SIGKILL` or `SIGQUIT`, cannot resume them. The checker and the processes suspended so far then stay suspended until something ends them, and the processes it started that were not yet suspended keep running. `SIGINT`, `SIGTERM` and `SIGHUP` do not cause this, because the runner holds them back until the stop finishes and then ends by the signal.
|
|
16
16
|
|
|
@@ -34,7 +34,7 @@ python3 <skill-dir>/scripts/mutate.py /path/to/models/Name.mutations
|
|
|
34
34
|
|
|
35
35
|
The plugin does not download TLC. Save `tla2tools.jar` from the [TLA+ release](https://github.com/tlaplus/tlaplus/releases/tag/v1.7.4) pinned in `scripts/tlc.py` as `~/.cache/tla/tla2tools-v1.7.4.jar`; the setup helper verifies its pinned SHA256 and names that path and release when the file is missing or does not match. Set `TLC_CACHE` to choose another cache directory. Set `TLC_JAR` to use an existing JAR; an explicitly supplied JAR is trusted and must already exist. Matrix and mutation output starts with an `ENGINE` line before any model checks. It gives the version from TLC’s help banner and identifies the pinned release or custom JAR. If a custom build omits its version, the runner records the JAR’s SHA256. The HTML report uses the same label.
|
|
36
36
|
|
|
37
|
-
With Java TLC, the matrix runner requires the JAR and a working Java runtime; with everystate, it needs neither.
|
|
37
|
+
With Java TLC, the matrix runner requires the JAR and a working Java runtime; with everystate, it needs neither. Java TLC also listens on a local port in every run, even on one machine, so where a sandbox denies that, the matrix and mutation runners print `UNAVAILABLE` and exit 3. There, run the checks with `TLC_ENGINE=everystate`, which opens no port. `setup.sh tla` checks a one-state model with Java TLC, so it prints the same line before any model is written. The matrix runner checks for Python 3.9 or later before running, so a failing model can always print its reduced trace. It does not download tools. Each run checks the formula its spec names `Spec` and sees only the modules beside that spec. `TLC_WORKERS` sets the worker count for either engine. Set `TLC_HTML_REPORT=<path>` to write a self-contained offline HTML report (matrix summary, interactive SVG state chain, variable diffs, and copyable Mermaid source for failing and `reach` witness traces) via `scripts/tlc_report.py`; the runner checks the target path after the TLA+ engine and before the first run, prints `UNAVAILABLE` and exits 3 when it cannot write there, and writes the report atomically without changing `stdout` or exit status on success (`tlc.py ready` and `mutate.py` ignore `TLC_HTML_REPORT`). Each run stops after sixty minutes by default; set `TLC_TIMEOUT` to change the limit using a whole number from 1 to 4294967295 with an optional unit `s`, `m` or `h`, such as `90s` or `1h`. For any other value, `setup.sh tla`, the matrix runner and the mutation runner print `UNAVAILABLE` and exit 3 without running TLC. A run that reaches the limit fails with a message naming the limit and `TLC_TIMEOUT`, and a mutation run that reaches it reaches no verdict. During long runs, the runner forwards periodic elapsed-time and `Progress(...)` updates from `tlc.log` to `stderr`. With Java TLC, each run gives the JVM its own `java.io.tmpdir` inside the run directory, so TLC runs started at the same time do not delete each other's copy of the standard modules. A `-Djava.io.tmpdir` in `_JAVA_OPTIONS` overrides it, because the JVM reads that variable after the command line; set the temporary directory with `TMPDIR` instead.
|
|
38
38
|
|
|
39
39
|
The mutation runner reads `Name.mutations` beside `Name.tla` and `Name.matrix`. For each mutation it copies the spec, replaces the listed text, and runs the matrix runner with the one property the mutation names, so it needs the same tools and settings.
|
|
40
40
|
|
|
@@ -85,6 +85,8 @@ python3 <skill-dir>/scripts/mutate.py /path/to/lean-project/Model/Name.mutations
|
|
|
85
85
|
|
|
86
86
|
The setup helper and the Lean checker need Python 3.9 or later as `python3`. The Lean pin lookup and readiness check live in [`scripts/lean.py`](../scripts/lean.py), with the checker's steps. The setup helper runs `lean.py ready`, which checks the version in the project's current `lean-toolchain` and installs it only when it is not ready; it leaves the global default unchanged. `elan run` installs a toolchain that is not installed, even without its install flag, so the Lean checker and the mutation runner first look for the pin in `elan toolchain list` and report a missing toolchain as UNAVAILABLE instead of downloading it. A `lean-toolchain` names a release, such as `leanprover/lean4:v4.35.0`, a toolchain that `elan toolchain link` added, or an absolute path to a toolchain directory. A channel, `stable`, `beta` or `nightly`, or a repository's `lean-toolchain` release name, fails, because elan resolves it to a release online. Lake builds may fetch dependencies declared by the model project. The supplied template has no external Lean packages.
|
|
87
87
|
|
|
88
|
+
The Lean checker and the mutation runner read each model through [`scripts/lean-analysis.lean`](../scripts/lean-analysis.lean). The first time they use a toolchain, they build that file into a program with the toolchain's own `lean` and `leanc`, which takes a few seconds, and keep the program in `~/.cache/agent-formal-verify/lean-analysis`. Set `LEAN_ANALYSIS_CACHE` to choose another directory. There is one program for each toolchain and version of the analysis, each 100 to 180 MB, and building one deletes any that no check has used for seven days. A toolchain directory whose `bin/lean`, libraries in `lib/lean` or `.olean` files change size or modification time gets a new program, so a toolchain rebuilt at the same path does not run a program built against the old Lean. When the toolchain has no `leanc`, or the build fails, they run the file with `lean --run` instead, which gives the same output and takes about one more second per call; a failed build prints why on `stderr`.
|
|
89
|
+
|
|
88
90
|
The Lean checker builds every `.lean` file in the project by its path, so a file that no Lake library owns fails the build instead of going unchecked. It then runs the audit in [`scripts/lean-analysis.lean`](../scripts/lean-analysis.lean) against the modules Lake reports for those files. The checker needs a pin of Lean 4.20.0 or later, the first whose Lake builds a module by its source path, and says so when an older pin fails. The audit lists every declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, so a model needs no `#print axioms` lines. The audit imports the project's modules together, so each model declares its names in a namespace of its own. A file name after the project limits the build and the audit to that file.
|
|
89
91
|
|
|
90
92
|
The mutation runner reads `Name.mutations` beside `Name.lean`. It elaborates each mutated copy with the project's toolchain and built modules, outside the project, and does not install a toolchain.
|
|
@@ -95,7 +97,7 @@ Helpers print `UNAVAILABLE` and exit 3 when a required tool is missing, unusable
|
|
|
95
97
|
|
|
96
98
|
The helpers live in this plugin, not in the target repository. In CI, check out `michael-denyer/agent-formal-verify` at a pinned commit into a separate directory and run the helpers from its `skills/formal-verify/scripts/`. Update that pin deliberately, as for any other tool. A repository that vendors the scripts instead must keep their GPL-3.0-only license headers.
|
|
97
99
|
|
|
98
|
-
Install the chosen runtime and the pinned TLC JAR (or an `everystate` 0.4.6+ binary when running with `TLC_ENGINE=everystate`), and for Rust the pinned Kani, in the CI environment, run the setup helper, then run the matrix runner, Lean checker, Rust checker or mutation runner as a separate step. Cache elan's toolchain directory if useful, and keep the version pins with the models. Use the same `TLC_ENGINE`, `TLC_JAR`, `JAVA` and `EVERYSTATE` settings in setup and verification.
|
|
100
|
+
Install the chosen runtime and the pinned TLC JAR (or an `everystate` 0.4.6+ binary when running with `TLC_ENGINE=everystate`), and for Rust the pinned Kani, in the CI environment, run the setup helper, then run the matrix runner, Lean checker, Rust checker or mutation runner as a separate step. Cache elan's toolchain directory and the Lean analysis directory if useful, and keep the version pins with the models. Use the same `TLC_ENGINE`, `TLC_JAR`, `JAVA` and `EVERYSTATE` settings in setup and verification.
|
|
99
101
|
|
|
100
102
|
```yaml
|
|
101
103
|
- uses: actions/checkout@<commit>
|
|
@@ -23,6 +23,7 @@ Apply each requirement that fits the protocol, and say in the report which did n
|
|
|
23
23
|
- For a protocol between processes or services, give the network and the processes their failures as separate actions: a lost or repeated message, a crash, and a timeout. Inject loss, duplication and crash at any point, through constants such as `LoseAt`, `DupAt` and `CrashAt` whose matrix values cover every point, as `FailAt` does, and let the caller's timer fire at any point while it waits. Allow any in-flight message to arrive next. Keep one entry per send, using a bounded send ID or a count for each payload, so retries with the same request key and payload can both arrive. To model network duplication, deliver a copy without removing it. A crash keeps the durable state and clears the state in memory; a restart action then runs the recovery code. A timeout changes only the caller's state: the request may already have taken effect, or may still arrive and take effect later. For a lease, let the lease expire while its holder still acts on it, as after a pause, so a stale holder's write can reach storage. Give loss, duplication and crash no fairness. Give weak fairness to each process's steps, to delivery of a message that was not lost, to restart, and to the caller's own timer while it waits. Use at least two clients or workers, two or three retries and one crash.
|
|
24
24
|
- Check small instances and boundary cases. Use slot counts of 1, 2 and the shipped count, item counts of 0, 1, 3 and 5, and one, two and three workers.
|
|
25
25
|
- Name a reachable state predicate for each blocking or boundary behaviour the properties depend on, such as a full window, an empty queue, a parked waiter or an injected failure. Add `reach <Operator> | <label-substring>` to its matrix section. It selects the first run whose label contains the substring. A command-line filter skips the reach check if it excludes that selected run.
|
|
26
|
+
- A set of interchangeable model values, such as workers, clients or replicas, makes TLC explore every permutation of them. To merge those states, add `TLC` to `EXTENDS`, define an operator such as `Perms == Permutations(Workers)`, and add `symmetry Perms` to a matrix section. Use it only when renaming the values changes nothing the model checks: `Init`, every action, invariant and reach predicate, and every run constant treat them alike. A `CHOOSE` over the set, a value named in the spec or in another constant such as `Leader=w1`, or an order on the values breaks that. An invariant can then pass falsely or a reach check report a reachable state as never reached, and no runner detects it. A mutation that treats the values unequally gets no sound verdict under symmetry either. TLC can miss a liveness violation under symmetry, so the runner refuses it in a section that checks a `PROPERTY` or `PROPERTIES`. Check the properties in a second section for the same spec, without the line.
|
|
26
27
|
- Check `TypeOK`, the ownership partition, delivery order, no delivery after end or error, the documented error-ordering guarantee, and no double free or leak at `closed`. For liveness, check that each blocking call returns, `close` terminates from every allowed calling state, and a run without `close` reaches the end. Require weak fairness on thread steps except consumer choices and spurious wakeups. Add strong fairness on a mutex acquisition only when a counter-example shows pure starvation by a spuriously waking peer. Name that assumption in the spec.
|
|
27
28
|
- For a protocol between processes or services, check `TypeOK` and the promise whose break harms a user, stated in one sentence from the code, such as "a card is charged at most once". Add a property from this list only when the code makes that promise to its callers:
|
|
28
29
|
- an effect happens at most once per request key, under repeated requests and retries;
|
|
@@ -63,7 +64,7 @@ The matrix runner prints PASS or FAIL per run and a SUMMARY line. A failing run
|
|
|
63
64
|
|
|
64
65
|
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. Witness searches use one worker and ignore deadlock so they can finish exploring a stopped model; `reach:` mutations run with `TLC_WORKERS` because confirming `UNREACHED` explores the full state graph without a witness trace. Attach each `reach` check—especially those paired with `detects reach:<Operator>`—to the smallest boundary `run` that exercises the predicate rather than large fault-injection configurations. 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.
|
|
65
66
|
|
|
66
|
-
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. For a protocol between processes, also try removing the request-key check, acknowledging before the durable write, retrying a permanent error, splitting a compare-and-swap or transaction the code relies on into a separate read and write, and removing the version or token check from a conditional write.
|
|
67
|
+
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. For a protocol between processes, also try removing the request-key check, acknowledging before the durable write, retrying a permanent error, splitting a compare-and-swap or transaction the code relies on into a separate read and write, and removing the version or token check from a conditional write. Write each as a `mutation <label>` line and a `detects <Property>` or `detects reach:<Operator>` line that names the one check that must fail on it. An optional `only <label-substring>` line keeps only the matrix runs whose label contains it. Then come `-` lines that quote consecutive lines of the spec exactly and occur once in it, and `+` lines that replace them. A mutation without `+` lines deletes the quoted text. 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, using only matrix runs where its named check is in scope. The same detector must pass on the original spec at those settings before a mutant can earn credit. Temporal mutations disable TLC's separate deadlock check so that the temporal property itself must fail; a deadlock alone earns no detection. Revise a property it reports as UNCOVERED, and the property or the mutation behind each MISSED line.
|
|
67
68
|
|
|
68
69
|
## Report
|
|
69
70
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# TLA+ helpers
|
|
2
|
+
|
|
3
|
+
The TLA+ behaviour of the helpers. The [helper reference](helpers.md) holds what every engine shares; read it first.
|
|
4
|
+
|
|
5
|
+
- **Matrix runner ([`scripts/tlc-matrix.sh`](../scripts/tlc-matrix.sh))**: runs TLC (or the native `everystate` engine with `-lncheck final` when `TLC_ENGINE=everystate`, requiring no JDK or JAR) with a matrix of constants. It prints an `ENGINE` line naming the checker and version before the first run, then one `PASS` or `FAIL` per run with its state count, then a `SUMMARY` line with the totals (tagged with `(everystate <version>)` when using `everystate`). Stops each run after sixty minutes, or after the limit in `TLC_TIMEOUT` as [setup](setup.md) describes, and forwards periodic elapsed-time and `Progress(...)` updates to `stderr` during long runs. A failing run prints its error trace reduced by [`scripts/tlc_trace.py`](../scripts/tlc_trace.py) to the variables each step changed. Before it checks the engine, the runner rejects each matrix line that could change the cfg beyond itself: a check name, reach or symmetry operator or constant name that is not a TLA+ identifier or is a TLA+ reserved word; a check name, symmetry operator or constant name that is a cfg keyword; and a constant value that holds a comment opener, a string that it does not close, or a cfg keyword outside a string that is not the whole value or a whole set element. So `Mode=INIT`, `Mode={TYPE,VIEW}`, `Mode="INIT"` and `reach INIT | label` pass, and `FailAt={}PROPERTIES` stops the runner. It prints a `FAIL <matrix>:<line>:` line for each and exits 2, and `mutate.py` does the same. Set `TLC_HTML_REPORT=<path>` to also write a self-contained offline HTML report through [`scripts/tlc_report.py`](../scripts/tlc_report.py) with the active engine metadata, the run table, an interactive native SVG state chain, a variable diff panel, and copyable Mermaid `stateDiagram-v2` source for each failing and `reach` witness trace. The runner checks the path after checking the TLA+ engine and before the first run, and a path where it cannot write the report prints an `UNAVAILABLE TLC_HTML_REPORT=...` line with the remedy and exits 3. It replaces the report in one step, and a written report leaves `stdout` and the exit status as they are without one. If the write fails after the runs, the runner prints the same line and exits 1 when a run failed and 3 otherwise. `tlc.py ready` and `mutate.py` ignore the variable. Copy [`examples/tla-template/`](../examples/tla-template/BoundedQueue.tla) to start a spec and its matrix.
|
|
6
|
+
- **Symmetry**: one `symmetry <Operator>` line in a matrix `spec` section adds `SYMMETRY <Operator>` to the cfg of each run and `reach` check of that section, wherever the line stands in it, and to the mutation runs that [`scripts/mutate.py`](../scripts/mutate.py) takes from the section. Both engines read the line. The line of each run and `reach` check of the section says `under symmetry <Operator>`, after the state count when a run passes and before the colon otherwise, as in `PASS BoundedQueue window=4 items=5 workers=3 8019 distinct states found under symmetry Perms`, where 8019 counts one state for each set of states that the symmetry merges. The run's row in the `TLC_HTML_REPORT` table and the title of its trace add the same words to its label. The mutation runner adds them after the run's name in a `DETECTED` line, and a `MISSED` line names each run that passed under symmetry, as in `MISSED <label>: run 'three' passes under symmetry Perms`. In a section that checks a `PROPERTY` or `PROPERTIES`, or that has two `symmetry` lines, the runner prints a `FAIL` line, runs the section without symmetry and exits 1. The mutation runner and the baseline helper stop on that line before any run. The [TLA+ brief](tla-brief.md) says when symmetry is sound.
|
|
7
|
+
- **Baseline helper ([`scripts/baseline.py`](../scripts/baseline.py))** on a TLA+ model:
|
|
8
|
+
- In the output of `compare`:
|
|
9
|
+
- A `symmetry` line added to a section, removed from it or naming another operator prints `CHANGED`, with an `added symmetry` or `removed symmetry` line for each run and `reach` check. So does an edit to the operator's definition.
|
|
10
|
+
- In a TLA+ module where a local `INSTANCE` introduces substitutions, or that has an indented definition outside a `LET` or a column-0 definition inside one, the helper compares the complete text of each local module it loaded, with comments removed, so a change to a definition that no property uses also needs review. So does a column-0 definition whose header the helper cannot read, such as an infix operator, which it records with the operators it references, whether or not a property references it.
|
|
11
|
+
- Cannot see:
|
|
12
|
+
- In TLA+, the actions that `Spec` names under `[][...]_vars`, `WF_` or `SF_`. It does follow the subscript of those forms and of `<<A>>_vars`, such as `vars`, in every definition it follows, and it follows an operator that `Spec` names outside those forms, such as a fairness definition, into its actions.
|