Skip to content

About

Check TLA+ designs in Vis: verdicts, step-by-step stories, Mermaid state diagrams and trace conformance, with the everystate model checker.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

vis-everystate

Ask whether a design can break its promise, and get the exact run that breaks it.

vis-everystate gives the agent in Vis a TLA+ model checker, everystate. The checker does not use Java. A TLA+ model describes a system as states and the steps that change them. The agent turns your design into a small model, explores every state it can reach, and retells a failure step by step in the terms of your code.

FAILED: invariant NoLostUpdate is violated after 4 steps (12 distinct states, 13 generated, depth 5).

1. Start: pc = (w1 :> "read" @@ w2 :> "read"), saved = (w1 :> 0 @@ w2 :> 0), count = 0
2. Read(w1): pc (w1 :> "read" @@ w2 :> "read") → (w1 :> "write" @@ w2 :> "read")
3. Read(w2): pc (w1 :> "write" @@ w2 :> "read") → (w1 :> "write" @@ w2 :> "write")
4. Write(w1): pc (w1 :> "write" @@ w2 :> "write") → (w1 :> "done" @@ w2 :> "write"), count 0 → 1
5. Write(w2): pc (w1 :> "done" @@ w2 :> "write") → (w1 :> "done" @@ w2 :> "done")

Two workers run x = counter.get(), then counter.set(x + 1). Both read 0, so the second write also stores 1 and one increment is lost. With the increment under a lock, modeled as one step, the check covers all 4 reachable states and passes. The skill shows this model in full.

Install

For the Python runtime, use Vis 0.8.0 or newer and Python 3.12 or newer. For the Babashka runtime, use a Vis release with Babashka extension support.

vis-agent extension install Blockether/vis-everystate --trust

Then run /reload in Vis. The checker uses a prebuilt everystate wheel for your platform:

Platform Requirement
macOS, Apple silicon macOS 11 or later
Linux x86_64 glibc 2.35 or later (Ubuntu 22.04, Debian 12, Fedora 36)
Linux arm64 glibc 2.35 or later
Windows x64 Windows 10 or later

Runtimes

Vis selects the implementation for the agent runtime. Both implementations have the same four tools.

  • Python: Run vis-agent set runtime python. The Python extension loads the checker in its process.
  • Babashka: Put uv on PATH and run vis-agent set runtime babashka. The Babashka extension uses uv to set up Python 3.12 and the pinned everystate wheel. The first call can require a download. The checker runs in a separate process. It does not need the Vis Python runtime.

In a Babashka session, call (tla/check "models/Counter.tla"). To set options, add a final map. For example, call (tla/diagram "models/Counter.tla" {:variables ["count"]}).

Tools

Create models/Counter.tla and models/Counter.cfg from the fixed counter in the skill. For models/Three.cfg, copy Counter.cfg and change Workers to {w1, w2, w3}.

await tla.check("models/Counter.tla")                          # verdict; story and trace on a failure
await tla.check("models/Counter.tla", config="models/Three.cfg")  # another configuration
await tla.diagram("models/Counter.tla", variables=["count"])   # the state graph, one node per count
await tla.conform("models/Counter.tla", "run.jsonl")           # a run recorded with TLA_TRACE=run.jsonl
await tla.pcal("models/Algorithm.tla")                         # your PlusCal, translated in place

Without config, tla.check uses the .cfg with the same base name. config can also be the configuration text (more than one line). A pass holds for the model at its bounds, for example two or three workers. The start of verdict.headline is the result:

  • PASSED: the search covered every reachable state and no property failed.
  • FAILED: an invariant, a property, an assumption or the deadlock check failed. When there is a counterexample, story retells it, trace holds every state as plain data and mermaid draws it. A liveness story ends with the cycle that can repeat forever, or the state where the run can stay.
  • INCOMPLETE: the search stopped early. It is not a pass.
  • NOT CHECKED: no state satisfies the initial conditions.
  • ERROR: the model does not parse or evaluate. message and location say why and where.

From Python

In py3, call the tools as await tla.check("models/Counter.tla"); the SDK calls below are synchronous. In your own extension, or in a script bound to Vis, call the same tools through the SDK:

from blockether import vis

verdict = vis.tools.tla.check("models/Counter.tla")
print(verdict.passed, verdict.headline)
if not verdict.passed:
    print("\n".join(verdict.story))

print(vis.tools.tla.diagram("models/Counter.tla", variables=["count"]).mermaid)

A Verdict also holds status, trace and mermaid. Outside Vis the call raises vis.errors.NotBound.

The skill

The extension ships the formal-verification skill, and Vis loads it with the extension. It teaches one method: name the promise, model the steps that can interleave, check, retell the failure in the terms of the code, break the model on purpose before you trust a pass, and report the bounds. It has a few modeling rules and one worked example, the lost update above.

To compare a real run with a model, the skill gives a short observe logger that appends a JSON line only when TLA_TRACE names a file, and the rules to merge the logs of several processes. The trace format is in trace.schema.json.

Correctness and speed

We cross-checked everystate against TLC 2.19, the reference TLA+ model checker, on 81 configurations from the TLA+ examples and six focused cases. Verdicts, property names, state counts and counterexample lengths agree, and the state graphs agree for one and four search threads. On an Apple M-series laptop, a 655,200-state Bakery check takes 1.8 s in process.

Development

uv sync
VIS_CONTRACT_SCHEMA_DIR=/path/to/vis/packages/vis-contract/resources/vis-contract/schema \
  uv run --with pytest --with jsonschema pytest tests -q
(cd babashka && bb test)
uv run --with ruff ruff format . && uv run --with ruff ruff check .

The tests run the same models through both implementations when bb is on PATH. Set VIS_CONTRACT_SCHEMA_DIR to the schema directory in a Vis checkout to check vis-extension.json. See RELEASING.md to publish a release.

About

Check TLA+ designs in Vis: verdicts, step-by-step stories, Mermaid state diagrams and trace conformance, with the everystate model checker.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages