A lightning-fast TLA+ model checker. It reads .tla specs and TLC .cfg files, checks every
reachable state, and reports results in TLC's format. No Java needed.
Find race conditions, deadlocks and lost updates in your design before they reach your code.
> use everystate's formal verification skill to find race conditions in my amazing software
⏺ Write(Store.tla)
// ... models load() and save() from store.ts
⏺ Bash(npx everystate Store.tla)
Error: Invariant NoLostUpdates is violated.
State 2: <Load("a")> a read 0
State 3: <Load("b")> b read 0
State 4: <Save("a")> memory = 1
State 5: <Save("b")> memory = 1
⏺ Found a race. Two overlapping requests both load before either saves,
so one update is lost. Fix: make load-and-save atomic.
(Condensed. The spec is examples/Store.tla; the skill is
skills/formal-verification.)
- Safety and liveness checking, fairness, symmetry,
VIEW,ALIAS. - TLC-compatible text output, exit codes,
-toolframing and-dump. - Random simulation (
-simulate) for models too large to enumerate, with seeded, reproducible runs. - Trace conformance (
everystate conform): check a log of the real system against the spec. - Parallel search (
-workers N) with results identical to one worker. - States in memory, or in a SQLite database (
-store sqlite:FILE; from JavaScript, a Durable Object's storage). - A PlusCal translator (
everystate pcal) with the Java translator's output, byte for byte. - The standard and community modules are built in.
- One native binary, or WebAssembly for Node, Bun and workers.
npm install -g everystate # prebuilt binary for Linux, macOS and Windows
brew install mattzcarey/tap/everystate
cargo install everystate # or build from sourceexamples/Counter.tla:
---- MODULE Counter ----
EXTENDS Naturals
VARIABLE n
Init == n = 0
Next == n < 5 /\ n' = n + 1
Spec == Init /\ [][Next]_n
TypeOK == n \in 0..5
NeverFour == n /= 4
====examples/Counter.cfg:
SPECIFICATION Spec
INVARIANT TypeOK
INVARIANT NeverFour
CHECK_DEADLOCK FALSE
everystate examples/Counter.tlaError: Invariant NeverFour is violated.
Error: The behavior up to this point is:
State 1: <Initial predicate>
n = 0
State 2: <Next line 6, col 9 to line 6, col 27 of module Counter>
n = 1
...
State 5: <Next line 6, col 9 to line 6, col 27 of module Counter>
n = 4
5 states generated, 5 distinct states found, 0 states left on queue.
Exit status is 12, as with TLC.
everystate -json examples/Counter.tla{"status":"invariant","name":"NeverFour","generated":5,"distinct":5,"queue":0,"depth":5,
"trace":[{"action":null,"state":{"n":"0"}},{"action":"Next","state":{"n":"1"}}, ...]}The npm package also exports the engine compiled to WebAssembly:
import { check } from 'everystate';
const { result } = check({
root: 'Counter',
modules: { Counter: tlaSource },
config: 'SPECIFICATION Spec\nINVARIANT NeverFour\nCHECK_DEADLOCK FALSE',
});
result.status; // 'invariant'
result.name; // 'NeverFour'checkAsync runs the same check in a worker with a large stack, for deeply recursive specs.
The WebAssembly build is about 2x slower than native and cannot use the file-based community
operators.
Every call runs in a new instance of the module, so a process that lives long can call check and
checkAsync as often as it likes: nothing of a call stays in memory once the JavaScript engine has
collected its instance, and the result does not depend on the calls before it. 2,000 checks of a
29-state specification in one process stay under 105 MB of resident memory in Node 22 (around 85 MB
most of the time) and 71 MB in Bun (not measured in a Worker); the new instance costs about 10 ms
per call in Node and 2 ms in Bun. The
Rust crate is made for one check per process, as the command is: a check does not free what it
parsed, and the next check in the same process would inherit its string table, whose order decides
what CHOOSE picks (ARCHITECTURE.md, "One check per process").
-workers N (or -workers auto, one per core) searches on N threads in the native binary. State
counts, depth, verdict and the counterexample are the same as with one worker. Operators whose
effect depends on exploration order (Print, TLCSet/TLCGet registers, RandomElement,
IOUtils, ...) are evaluated by the sequential search; if they occur repeatedly the run continues
with one worker and says so. A specification that reads TLCExt!Trace is searched by one worker
throughout: the behaviour that leads to a state is the order of the search. Liveness checking,
simulation and conform run on one thread, and the WebAssembly build is single-threaded.
A safety check already keeps little per state in memory (see Speed). What still stays there
is the values that states share and, with temporal properties, -dump, or a specification that prints
or sets TLC registers, every state. A state store keeps the states in a SQLite database instead;
verdict, counts, depth and counterexample are the same.
cargo build --release --features sqlite # the SQLite store is an optional cargo feature
everystate -store sqlite:states.db Spec.tla- What stays in memory is 40 to 65 bytes per state (the fingerprints and a few numbers), not the states. On MCLamportMutex (724,274 states) peak memory goes from 119 MB to 63 MB for 7 % more time, with 98 MB on disk.
- It pays where states are large and mostly different. Where the default search already keeps a state in a few bytes (models whose states share most of their values, such as actors exchanging messages), a store saves little and the check runs several times slower, because with a store the search cannot use value ids or the step cache.
- One worker (
-workersis noted and not used). Temporal properties and-dumpwork, with the state graph still in memory.-simulateandconformkeep no states and use no store. - The database is the working storage of one run, in one table (
everystate_chunks) that a check empties when it starts: give it a file of its own. Nothing else can read it, a check cannot be continued from it, and the fingerprint set is in memory, so the number of states is still bounded by memory (about 15 to 20 million per GB). - The prebuilt binaries of the npm package and the Homebrew formula are built without the feature.
From JavaScript, pass the storage as store: anything with a synchronous exec(query, ...bindings)
that returns the rows of the result. A Durable Object's SQLite storage is one, so a check in a
Cloudflare Worker can keep its states there instead of in the isolate's 128 MB:
import { DurableObject } from 'cloudflare:workers';
import { check, init } from 'everystate';
import wasm from 'everystate/everystate.wasm'; // in a Worker this import is a compiled WebAssembly.Module
export class Checker extends DurableObject {
async fetch(request: Request) {
const { root, modules, config } = await request.json();
await init(wasm);
const { result } = check({ root, modules, config, store: this.ctx.storage.sql });
return Response.json(result);
}
}This example has not been run on Cloudflare. What is tested is the same three statements against Node's
built-in node:sqlite behind the same exec interface (test/store.test.ts). The check is one
synchronous call, so it has to fit in the CPU time of one request. A row holds about 64 kB of states
(more by the state that crossed that mark and 4 bytes per state), so one state must fit in a row of the
storage.
When a model is too large to enumerate, everystate -simulate num=10000 Spec.tla generates random
behaviours of up to -depth steps (default 100) and checks invariants, action properties, deadlock
and temporal properties on each, printing TLC's simulation output. A pass means only that no
generated behaviour violates a property. Without num= it runs until it finds an error, as TLC
does; with -json it stops after 1000 behaviours. Every run prints its seed; pass it back with
-seed to repeat the run exactly. From JavaScript:
check({ root, modules, config, simulate: { traces: 10000, seed: 1 } }).
Two differences from TLC: a deadlock is reported only for a state with no successor (TLC's
simulator also reports one when a CONSTRAINT excludes every successor), and a state predicate
given as PROPERTY is checked on the initial states (TLC's simulator skips it). Random choices
differ from Java TLC's, so the same seed gives a different run there.
everystate pcal translates the PlusCal algorithm in a module with the output of the Java
translator (pcal.trans 1.12): the same TLA+, layout and checksums, the same .old backup and
.cfg handling, the same options (-wf, -sf, -wfNext, -nof, -termination, -label,
-labelRoot, -lineWidth, ... and the PlusCal options (...) line), in p-syntax and c-syntax.
---- MODULE Transfer ----
EXTENDS Naturals, TLC
(* --algorithm transfer
variables alice = 10, bob = 10, money \in 1..20;
begin
Withdraw: alice := alice - money;
Deposit: bob := bob + money;
Check: assert alice >= 0;
end algorithm *)
====everystate pcal Transfer.tla # writes the translation into Transfer.tla, and Transfer.cfg
everystate Transfer.tla # "Failure of assertion at line 9, column 13."When a module is model-checked and its algorithm or translation no longer matches the checksums
in the \* BEGIN TRANSLATION line, everystate prints TLC's warning; everystate pcal --check File.tla reports the same without checking a model. From JavaScript,
translatePlusCal(source, options) translates the text of a module. -spec and -myspec are not
supported. npm run conformance:pcal compares the translator with the Java one.
A pass verifies the model. To check that the running code behaves like it, log what the code does and ask whether that run is a behaviour of the spec:
everystate conform -trace run.jsonl Charge.tla{"state": {"sent": 0, "charges": 0}}
{"action": "Send", "state": {"sent": 1}}
{"action": "Handle", "state": {"charges": 2}}
Each line is a step: optionally the action, and whichever variables the code knows. The report
names the first line the spec does not allow, what it expected, and which steps were possible
there. Exit status 0 conforms, 20 does not (21 bad trace, 22 limit reached). -hidden N allows
unlogged steps, -stutter snapshots, -behavior prints a full matching behaviour, -json
structured output. From JavaScript: conform({ root, modules, config, trace }). Details are in
the skill.
A run the spec allows is also held to what the configuration checks on states and steps: its
INVARIANTs on every state matched to a line (exit status 12), and of its PROPERTY entries the
action properties [][A]_v on every step, unlogged ones included, and the predicates on the
initial state (exit status 13). A trace that leaves variables or steps out can match several
behaviours of the spec. A violation is then reported only when the trace leaves no doubt: every
behaviour that matches the trace up to some line has one, be it of an invariant or of a property
(a later line can settle what an earlier one left open). When only some do, the run conforms and
a note says which check could not be decided. Temporal formulas (liveness, fairness) are not checked, because a recorded run is
finite; a pass names them in a note.
skills/formal-verification teaches a coding agent to
model-check a design with everystate: choose the promise, model the steps, run the check, see it
fail, report the counterexample in the code's words. It comes with a worked example
(example/Charge.tla). Copy the folder into your agent's skills directory, for example
.claude/skills/.
everystate [options] SPEC[.tla]
-config FILE configuration file (default: SPEC.cfg)
-deadlock do not check for deadlock
-json one JSON result object
-tool TLC's machine-readable message framing
-dump dot,actionlabels FILE write the state graph
-workers N|auto search with N threads
-store sqlite:FILE keep the states in a SQLite database (a build with --features sqlite)
-DTLA-Library=DIR[:DIR...] more directories to look for modules in, after the spec's own
Exit status: 0 success, 10 assumption, 11 deadlock, 12 safety, 13 liveness, 150 parse error, 151 config error.
Environment: actions and invariants are compiled before the search, and a cache of local steps
reuses work between states that agree on what a step reads (a fixed-size table, 32 MB per worker,
EVERYSTATE_STEP_CACHE_MB; used only where it measures faster during the run). Results are the
same either way. EVERYSTATE_STEP_CACHE=off turns the cache off; EVERYSTATE_EVAL=tree uses the
tree-walking interpreter alone.
Real TLC is the reference (details in CONFORMANCE.md).
Which TLC. everystate follows TLC's development build of 6 November 2026
(tlaplus/tlaplus@d8fb231): the gates run side by
side with that tla2tools.jar. It is newer than the latest release, TLC 2.19 (tla2tools 1.7.4), and
where the two differ everystate does what the newer one does. The difference you are most likely to
meet: SUBSET, UNION and DOMAIN now have the precedence the language definition gives them (8, 8
and 9; through 2.19 they bound as tightly as 10 to 13). So UNION S \cup T, which 2.19 reads as
(UNION S) \cup T, is a precedence conflict in current TLC and here: write the parentheses, which
every version accepts. (The first line of output reads "TLC2 Version 2.19": that names the latest
release, not the build followed.)
Checked against it:
- tlaplus/Examples, models up to 5 s: 122 of 122 match on result and exact state counts.
- TLC's own
test-modelsuite, run side by side withtla2tools.jar: 389 of 414 match. - pstack
statechartcorpus: 33 of 33 outputs byte-identical.
Wall-clock seconds for the whole process on a 4-core Linux machine, median of 3, against tlc-rs (a Rust port of TLC's safety checking), tla-ts 0.0.10 (run by Node) and Java TLC. The first three models are tla-ts's own benchmarks. A dash means the checker does not support the model or the worker option. Every checker that completes a model reports the same state counts.
| Model | Distinct states | everystate | tlc-rs | tla-ts | TLC |
|---|---|---|---|---|---|
| Commit | 282,251 | 4.14 | 13.44 | 6.76 | 7.20 |
| Philosophers | 128,889 | 0.83 | 3.64 | 2.12 | 2.33 |
| Queue | 44,044 | 0.08 | 0.27 | 0.55 | 0.94 |
| Paxos | 1,207 | 0.95 | - | 6.47 | 2.25 |
| MCBakery | 655,200 | 8.29 | - | 20.86 | 13.26 |
| MCLamportMutex | 724,274 | 13.78 | 41.26 | 27.80 | 17.31 |
| MCbtree | 374,727 | 12.47 | - | 17.95 | 34.86 |
| MCLamportMutex, 4 workers | 724,274 | 3.66 | - | 25.15 | 10.70 |
| MCbtree, 4 workers | 374,727 | 4.34 | - | 17.43 | 12.78 |
| 122 tlaplus/Examples models: total seconds | 46.8 | - | 180.1 | 203.3 | |
| 122 tlaplus/Examples models: correct | 122 | 39 | 116 | 122 |
With one worker everystate is the fastest of the four on every model that runs long enough to measure: 3.0x to 11.4x faster than tlc-rs, 1.4x to 6.8x faster than tla-ts and 1.2x to 11.3x faster than TLC. tlc-rs uses the least memory on the models it supports. All 15 models, four-worker results, memory and the method are in BENCHMARK.md.
Memory: a safety check does not keep a state once it has been expanded, so beyond the values that
states share it holds 40 to 65 bytes per distinct state (the fingerprint twice, the parent and the
action), with any number of workers: 732 MB for a 14-million-state model. A counterexample's states
are found again by taking its steps. With temporal properties or -dump the states and the graph
are all in memory, in a compact form: a state is four bytes per variable, with every distinct value
of a variable kept once, and a step of the graph is eight bytes. The check of the properties itself
holds the product of the graph and the properties' automaton for one branch at a time, which is then
the larger part. A model of 482,756 states with large states (vector clocks, a set of messages, a
history per node) and two properties peaks at 160 MB with one worker and 236 MB with four; one of
1,267,765 small states, 6.5 million steps and six branches at 662 MB and 727 MB. The states of a
specification that reads TLCExt!Trace are kept in memory as well.
A fingerprint set outside memory and continuing an interrupted check (the states themselves can be kept
in SQLite, see above; the fingerprints, 24 to 48 bytes per state, cannot yet), Java module overrides, TLCExt!Trace in
simulation (it is an error there; model checking has it), and TLAPS proof checking (proofs
are parsed and skipped). Labels and subexpression selectors (Op!lab(x), Op!2, Op!<<, Op!@, Op!(x)) work
except in a few rare forms, which are reported as errors: a selector applied to an operator defined in a LET or
in a standard module, the left operand of a /\ b /\ c written without parentheses, the argument tuple of
f[a, b], and the body of a recursive function definition (docs/TLC_NOTES.md, section 12).
npm run build # native binary and wasm/everystate.wasm
npm test # WASM API, pretty-printer and community-module testsHow the code is organised, the rules that keep it sound and how to debug it: ARCHITECTURE.md.
Releases use changesets: add one with npx changeset in your pull request,
then merge the "Version Packages" pull request that appears. That bumps package.json and
Cargo.toml, and .github/workflows/release.yml builds the binaries and publishes to npm and
crates.io (trusted publishing, no tokens).
An earlier pure-TypeScript engine is in the git history at commit e8c67ce (npm everystate@0.1.0).
MIT