Code Lab
pstack Explained: Find a One-Step State Machine Bug with TLA+
CODE LAB · PROJECT SPOTLIGHT
pstack TypeScript · MIT
Check a state model and explain the shortest path to a broken rule.
Preview: GitHub · cursor/plugins
Lauren Tan’s All Code Is Slop (Except Mine) talks about turning recurring review comments into checks the coding agent can run. One of the tools in her pstack plugin is statechart. Give it a TLA+ specification and it can ask TLC to check its behavioral rules, then explain any counterexample as a sequence of recognizable actions. Original AI Engineer talk.
Model a rule before writing the fix
In the upstream MediaPlayer example, playback and volume are separate state variables. The player begins stopped with normal volume. The LoudWhenStopped invariant forbids the combination of stopped playback and loud volume. In the original YouTurnItUp action, normal volume is enough to enable the action, so a user can turn the volume up while the player remains stopped. Pinned original model.

See how pstack reconstructs the shortest path
After TLC explores the model, pstack walks the resulting transition graph. The loop below starts with the initial states, visits their neighbors in breadth-first order, and stores the first incoming edge for each reached state. A later pass can follow those incoming edges backward from a state that breaks an invariant.
Code copyright 2026 Lauren Tan. MIT license.
Run the original and fixed fixtures
Use the pinned pstack/skills/statechart directory with a supported Node version and TLC. We supplied portable Temurin Java 25 and the checksum-verified TLC 1.7.4 jar through the documented JAVA and TLA2TOOLS variables. From the scripts directory, run each fixture into its own new output folder.
node statechart.ts test/corpus/MediaPlayer/MediaPlayer.tla --view test/corpus/MediaPlayer/view.mjs --out out-original
node statechart.ts test/corpus/MediaPlayerFixed/MediaPlayerFixed.tla --view test/corpus/MediaPlayerFixed/view.mjs --out out-fixed
The first run exited 1 and reported one step to the broken state: turn the volume up while stopped. The fixed fixture prevents that transition with a guard on YouTurnItUp. It exited 0 with LoudWhenStopped holding. Both generated reports and Mermaid charts matched the checked-in fixture outputs. The fixed configuration omits the original EventuallyStops liveness check. Our comparison covers the shared volume invariant and the declared example models. Pinned fixed model · Runtime and invocation guide.
Choose what to verify in your own project
Start with a rule you can explain to a user, such as a save indicator appearing only after persistence. Write its model, inspect the shortest failing sequence, and use it to guide a test of the running application. A checked model establishes a result within its modeled states and actions. The application test checks whether the implementation and the model agree.

Read our Cursor plugin manifest walkthrough for the repository’s plugin format. This story came from MINDUNG’s breakdown of Lauren Tan’s talk.
