TLC: an explicit-state model checker

TLC turns a TLA+ spec into an executable artifact. It generates every reachable state, then checks your properties against the entire state space — mechanically and exhaustively.

How TLC works

  1. Parse the module and its model (.cfg) — which properties to check, and any constant bindings.
  2. Enumerate initial states — all states satisfying Init.
  3. Explore reachable states — breadth-first: apply Next to each state, deduplicate, repeat.
  4. Check properties — evaluate each invariant and temporal formula on every state (and, for liveness, on behaviors).
  5. Report — either "no error" with coverage stats, or a reproducible error trace.

Watch it explore — and find a bug

The diagram below is a tiny state graph. State s4 violates the invariant TypeOK. Press Run check to see breadth-first exploration and the error trace TLC reconstructs.

Click "Run check" to explore the state space.
Error: Invariant TypeOK is violated. The behavior up to this point is: State 1: <Initial predicate> x = 0 State 2: <Next line ...> x = 1 State 3: <Next line ...> x = 2 State 4: <Next line ...> x = -1 <-- TypeOK says x >= 0 Result: 4 states generated, 1 violating state found.

What TLC checks

CheckKindConfigured as
Type invariantSafetyINVARIANT
State invariantsSafetyINVARIANT
Temporal formulasLivenessPROPERTY
Deadlock detectionLivenessbuilt in (a state with no successor)

A TLC model is declared in a .cfg file alongside the module:

SPECIFICATION  Spec
INVARIANT      TypeOK
PROPERTY       Live

The counterexample is the product

TLC's real value isn't the green checkmark — it's the trace you get when something fails. The trace is a concrete sequence of states from a valid initial state to the violation, so you can replay the bug and understand exactly which interleaving broke your design.

Reproducible

The trace is deterministic — feed it back and TLC walks the same path. No flaky tests, no "it works on my machine."

Minimal

TLC finds the shortest path to the violation (breadth-first), so the trace is the smallest scenario that exposes the bug.

The limit: state-space explosion

The reachable state space grows exponentially with the spec's variables. That's the fundamental constraint on all explicit-state model checkers. TLA+ practice has standard countermeasures:

TechniqueWhat it does
Symmetry setsCollapse states that are permutations of each other (identical processes, messages).
Model valuesReplace a large/unbounded data set with a few abstract tokens.
State constraintsBound the search (e.g. limit queue length) for a partial, targeted check.
ApalacheA symbolic model checker for TLA+ that reasons about sets of states, extending reach.
A bound is still useful

Even a small model (a handful of processes, a bounded queue) routinely finds the concurrency bugs that ship to production. You don't need an exhaustive 1030-state search to be valuable.

Made with Aii CloudReport