Models concurrent and distributed designs in TLA+ or PlusCal and checks them with everystate, a TLC-compatible model checker. Use when asked to write, review, or debug a TLA+ spec, .tla/.cfg files, or TLC output, or to model-check or formally verify a protocol, lock, lease, consensus, replication, WAL, retry, or race condition. Do NOT use for unit or property-based tests (use test-writing), a click-through demo of a proposed state model (use state-prototype), a reader's chart of a checked mod...
4 stars
0 votes
0 copies
8 views
Added September 25, 2026
ai-agentspythonrustgobashnodegitdatabase
Works with
cli
Security analysis
A92/100
mediumInstalls packages at runtime which could introduce malicious dependencies
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Tla Model?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/wilbeibi-tla-model)
---
name: tla-model
description: Models concurrent and distributed designs in TLA+ or PlusCal and checks them with everystate, a TLC-compatible model checker. Use when asked to write, review, or debug a TLA+ spec, .tla/.cfg files, or TLC output, or to model-check or formally verify a protocol, lock, lease, consensus, replication, WAL, retry, or race condition. Do NOT use for unit or property-based tests (use test-writing), a click-through demo of a proposed state model (use state-prototype), a reader's chart of a checked model (use statechart), a lesson teaching TLA+ (use html-lesson), a verify skill kept in a repo (use create-formal-verification-skill), or Lean, Coq, Dafny, or Verus proofs.
compatibility: uv (scripts/tlc.py runs as a uv script, Python 3.10+, no dependencies; scripts/drift.py as one with tree-sitter, Go and Rust); everystate 0.4.6 (npm i -g everystate@0.4.6; found on PATH or at $EVERYSTATE).
---
# tla-model
The deliverable is a checked argument, not a `.tla` file: every property traces to a requirement, every action to an implementation event, and every green result survives mutation.
## Setup
```bash
scripts/tlc.py check examples/MiniLock.tla -c examples/MiniLock.cfg # expect "result: clean", exit 0
```
Missing everystate: `npm i -g everystate@0.4.6` (pinned; `check` prints the everystate version it ran). `scripts/test_tlc.sh` and `scripts/test_drift.sh` self-test the helpers. Run the checker only through `tlc.py`; raw TLC-style flags go after `--tlc-args`. PlusCal: everything between two labels is one atomic step, so put a label wherever another process can interleave; run `scripts/tlc.py translate Spec.tla` (`everystate pcal`) before every check.
`tlc.py check` prints result, everystate version, state counts, and the full trace. Exit 0 clean, 1 violation, 3 setup/parse error, no finished check, or a search its budget stopped. everystate reports no action coverage, so vacuity (a vacuously true pass) is not checked: counterexamples (witness traces included) and mutants are the main evidence. `tlc.py mutant` first checks that the unmutated copy is clean on the cfg, then applies one exact-match edit to any module the spec loads (an MC wrapper's base module works), checks the mutant against the `--expect` property alone, and exits 0 only when that property catches it (`KILLED`).
Long searches: one runs at a time per machine, and a second call queues and says so on stderr. For a matrix of small searches (each under two minutes) and single-threaded liveness runs, `TLA_MODEL_SLOTS=4` lets up to four run at once; run large safety searches, which already use every core, one at a time. After a minute a search prints `progress:` lines with its states, queue, depth, and memory (`rss`). An in-memory checker ends at memory, not time: memory can rise by several GB within a minute, and the queue's direction does not tell whether a search will finish. `--mem-budget GB` (default 80% of physical memory divided by `TLA_MODEL_SLOTS`) stops it with `result: budget (memory)`, `--budget SECS` (default 900, 0 for none) with `result: budget (time)`; then shrink a bound or split the faults across cfgs. Before changing the representation so a search finishes (symmetry, a view, fewer variables; [REFERENCE.md](REFERENCE.md#reductions)), measure the distinct states per depth level, the depth a finished smaller cfg reaches, and each candidate reduction on the smallest cfg with the same number of process instances: a factor f per instance gains at most f^n, and if that cannot close the gap, shrink a bound or split the faults instead. Run anything you expect to pass two minutes in the background. An unchanged spec, cfg, and everystate version reprint the kept result with a `cached:` line, so a matrix rerun costs only what changed; a mutant reuses its baseline and, when repeated, its own search. Comments are not compared, so fixing one costs no search; `--fresh` searches again.
A question about an existing spec or TLC output needs only `check` and the matching step below. Create files only when asked to model or verify a system. Keep that work in `spec/` beside the code: `modeling-brief.md`, `<Name>.tla`, one cfg per concern, `cex/`, `report.md`.
## Loop
A model earns each piece it keeps: grow it only for the question, a bug-history mechanism, or a fault the user confirmed, and prune before the report (Report). If any `tlc.py` call runs in a sandbox, give every call of the effort the same `TLA_MODEL_SESSION`, and copy the sandbox's `runs.jsonl` back before it goes away; a script that wraps `tlc.py` passes `TLA_MODEL_SESSION` through and never sets one of its own.
1. **Brief before spec.** Fill [BRIEF-TEMPLATE.md](BRIEF-TEMPLATE.md) into `spec/modeling-brief.md`. Aim the question where bugs have lived: search `git log` and the issue tracker for fix, race, crash, deadlock, corrupt, and stale on the core files, group the hits by mechanism, and note where the code departs from the reference algorithm. If the bugs need no interleaving, crash, or fault, and small inputs to the real code can be enumerated, stop and recommend exhausting the code (test-writing) instead. Build the event→action table from the code you read, not from the paper the design resembles; a textbook Raft is not the user's Raft. Cite code by symbol (`path::Function`, a line number only as a second pointer: lines move), and record what you read in `spec/MODELED` (`rev=` the commit, or the pull request's head for an unmerged change, then the paths); `scripts/drift.py suggest spec/` turns the `path::Name` and `file:line` citations into `spec/SYMBOLS` lines to review. For every fact a guard reads, list each code path that writes or contributes to it, found by searching the type or field (`rg`), not only the function in hand: a second writer or a source the model leaves out is where a model goes wrong about the code. Where a step is a database transaction, fill the brief's atomicity audit: a guard holds only if every writer of the fact it reads takes the same lock. List every open question and stop until the user answers. *Done:* every REQUIRED slot filled; the user has confirmed the fault model, atomicity, and exclusions.
2. **Grow the spec one layer at a time**: variables → `TypeOK` → `Init` → one named action → `Next`, then the next action. Run `check` after each layer. A layer that adds a variable adds it to `vars` and to the `UNCHANGED` of every action that does not set it. Give each action a comment naming its implementation event. *Done:* clean.
3. **Safety.** Add the invariants from the brief to a safety cfg. Any violation other than a witness goes to step 6.
- Keep `CHECK_DEADLOCK TRUE`; turn it off only when termination is the intended end state, and say so.
- Check a rule about what may ever happen (one leader per term, one value per index) over a history variable that records each event and that no action reads: an invariant over current state misses a violation a later step erases.
- Bound fault injections (crashes, drops, timeouts) with counters; leave normal operations unbounded.
- Run the bounds matrix from the brief, smallest first, in two tiers. The fast tier is every property and every must-fail cfg at the smallest bounds, plus one tight cfg per bug-history mechanism, under five minutes in total; it reruns every round. The deep tier holds the larger bounds and reruns before the report (kept results skip the cfgs whose modules did not change). When a round doubles a fast row's states or seconds, move the row to the deep tier or shrink it in that round.
- Witness the question and each bug-history mechanism, because a green run proves nothing about a scenario the model never reaches: define `NoX == ~Scenario`, make `NoX` the only invariant of its own cfg, expect `result: safety (NoX)`, and read the trace. For any other action, `tlc.py fired` is the evidence that it happens; it needs no witness cfg.
- Witness the success path too (two writes both commit): a model that refuses all work satisfies every safety property.
*Done:* every brief property is enabled in at least one cfg, checked by reading the cfgs; the question, the success path, and each bug-history mechanism have a witness trace, and the user has confirmed the question's trace is the case they meant; `scripts/tlc.py fired Spec.tla -c <each cfg>` names no action that is neither fired by a kept trace, switched off by a constant the report lists, nor shown reachable ([REFERENCE.md](REFERENCE.md#checker-gotchas)).
4. **Liveness, only after safety is clean.** Use one cfg per temporal property: everystate does not name which temporal property failed. Never use `SYMMETRY` in a liveness cfg. Liveness on a large model is bounded by memory ([REFERENCE.md](REFERENCE.md#checker-gotchas)). Each `WF`/`SF` term carries a comment naming the real mechanism behind it (FIFO queue, retransmit, lease expiry). If no mechanism exists, delete the term and report the starvation trace as a finding. Delete a term no liveness property needs: a must-fail cfg still ends in the same stuck state without it. Before reaching for `SF` because `WF` fails on an action that is only sometimes enabled, check that the model is not looser than the code (a guard that lets a step repeat which the code runs once); `SF` would hide that. *Done:* `scripts/tlc.py lint spec/` reports no finding: every fairness term names its mechanism, and no spec is left with no liveness cfg unless the report says why.
5. **Prove the properties bite.** Start with the bug history: revert each historical fix in the model and expect the violation that bug caused. Use a constant that switches the fix off only for a landed fix or an open issue, which a later reader reruns; a design guard or a rejected alternative is a text mutant, which costs the spec nothing ([real examples](REFERENCE.md#worked-examples)). A property that stays green there misses a bug the code really had. Then, for each invariant, delete the guard it depends on, and swap each fix for the weaker design a reasonable engineer would pick (a quorum that need not overlap, a read that skips the barrier): a deleted guard only shows the property notices an obviously broken model. For each liveness property, drop its fairness term:
```bash
scripts/tlc.py mutant spec/Lock.tla -c spec/Safety.cfg --replace '/\ lock = None' '/\ TRUE' --expect Mutex
```
`OLD` must match exactly once, so include the neighbouring text if it doesn't. `--expect` must be an invariant or property the cfg lists, or `deadlock` on a cfg that checks it. A mutant that no longer parses exits 3 and proves nothing. A `SURVIVED` result means the property is too weak, redundant, or guards an unreachable action. An invariant of the form `done => P` holds in every behaviour that never reaches `done`, so a mutant that keeps the system from finishing survives it: pair it with a liveness property that `done` is reached (step 4). When a whole mechanism is deleted and every brief property stays green, the mechanism may defend nothing the system promises: once the user confirms the properties cover the promises, report it as a removal candidate. Make an unreachable action reachable in the model; a stronger or deleted property needs the user's approval (step 6). *Done:* each row of the brief's bug-history table has its kind and an outcome: the mutant that reproduces it, or why the model cannot (the abstraction that hides it, entered in the delta ledger), or why it is not a design-level bug. Every property has at least one `KILLED` mutant. A weaker-design swap that is `SURVIVED` is a sentence in the report, not a matrix row, unless a finding rests on it.
6. **Counterexample loop.** Write each violation to `spec/cex/NNN.md` from [CEX-TEMPLATE.md](CEX-TEMPLATE.md): the first bad state, the code event and allowed fault behind each step, and the class (design, spec, property, config/bounds, mapping, or fairness/assumption).
- REQUIRED: change exactly one of model, property, or cfg per round. Replay the trace, then rerun the fast tier.
- REQUIRED: a guard added in a round cites the code check it models (lock, CAS, version or etag compare) by symbol. Only for a design-class fix (step 7) may it name the mechanism the code will gain instead. A guard with neither assumes the race away.
- Never weaken, strengthen, or delete a property, or add fairness or a `CONSTRAINT` to turn a run green, without the user's approval.
7. **Back to code.** A design-class counterexample is confirmed only when a test or fault-injection run against the implementation reproduces it and has actually been run. Otherwise report it as unconfirmed with the missing step. Check a proposed fix in the model before it lands in code: make it the round's one change and rerun both tiers; a rejected fix comes with the trace it misses. Keep the reproducing test as a committed regression, one step per model step (test-writing). Keep the counterexample as a cfg that switches the fix off and must fail, and comment the code guard with the spec and that cfg (`Lock.tla`, `NoFence`), so whoever deletes the guard knows what to rerun. To show a counterexample or the checked model to a reader, use statechart. For high-stakes specs, add refinement, or log real runs and check each one with `scripts/tlc.py trace` ([REFERENCE.md](REFERENCE.md#linking-spec-to-code)).
8. **Independent review.** Hand only the brief, spec, cfgs, and report to a reviewer with fresh context, such as a new session or another person. Ask them to attack it with the review checklist in [REFERENCE.md](REFERENCE.md#review-checklist) and to write the findings to `spec/review.md`, so a reviewer session that ends before it reports loses nothing. A finding becomes a model round (step 6) only when a run shows a verdict differs, for example a variant the reviewer ran; otherwise it becomes a delta-ledger row or a report sentence.
## Report (`spec/report.md`)
Prune first. For each cfg, switch, witness, fairness term and mutant row, name the one thing it carries: a property's only kill, a bug-history row, the question's witness, a finding or ledger row that cites it, or the only trace that fires an action. Delete a piece that carries none; bound to 0 in the large cfgs, or move to the deep tier, a piece that stands only for a fault the user confirmed; rerun both tiers. The report states the current model only: round history belongs in the commit log.
- Per cfg: its tier, the everystate version line, spec and code revision, constants and bounds, generated/distinct states, depth, and result, copied from one final run of both tiers, never typed from an earlier run.
- Mutants: each property, its mutation, and KILLED/SURVIVED; each bug-history row's kind and outcome. Count only landed fixes when giving a number.
- Witnesses: each scenario, its cfg, trace length, and whether the user confirmed it.
- Counterexamples: id, class, confirmed or unconfirmed, fix, and linked test or issue.
- Assumptions in force: fault model, atomicity choices, every fairness term and its mechanism, every `CONSTRAINT`, every restriction `Init` adds beyond the code's real start state (fixed membership, empty logs), and every feature a cfg switches off with a constant.
- Not verified: behaviors outside the bounds or exclusions, any claim that needs a parametric proof (TLAPS or an inductive invariant), and a delta ledger of each place the model is weaker than or lags the code, updated in the change that moves the protocol. Each ledger row and each exclusion names the symbol (`path::Name`) whose change would falsify it, and `spec/SYMBOLS` lists it. Before relying on a result, `scripts/drift.py check spec/` names each listed function, constant, or type whose code changed since `MODELED`'s revision, and each symbol a `.md` or `.tla` file in `spec/` cites that `SYMBOLS` lacks (`uncited`); re-read the changed ones and list the uncited.
Claim only what the report shows, and never call a green run a proof: "No counterexample with 3 nodes, 2 values, queue ≤ 2" is the strongest sentence it supports.