Tests check the cases someone thought to write. formal verification checks every case within a stated scope: every order of steps in a model, every input up to a size, or every input at all.
Some bugs live on paths nobody walks: two retries that overlap, a lock that expires mid-write, state updates that arrive out of order. Ten test runs pass. A year after launch, it happens once, and it’s a double charge or corrupted data.
Tests
- A takes a job and finishes
- B takes the next one and finishes
- One retry, also fine
- All green. In production A stalls once, and the same job runs twice
Formal verification
- Model taking a job, renewing the lease, timing out, retrying
- Walk every possible order
- Hit a bad order
- Hands you a short counterexample in your code's own names
When it’s worth it
- Concurrency and locks: several processes or machines competing for one thing. Job leases, stock counts.
- Retries and “exactly once”: a message must not be delivered twice; an order grants membership once.
- State machines: order status, offline edits that sync later, approval flows.
- Parsers: no input may crash it or be read wrong.
- Unsafe low-level code: memory safety, integer overflow, conditions a data structure must always keep.
Ordinary create-read-update pages, copy and styling don’t need it; a verification skill covers them. /pstack:setup-pstack also offers this once. Say yes if your code has the kinds of logic above and a bug there is costly; otherwise say no, and run it later if that changes.
Copy this first
Let it pick the most valuable target from the code:
/pstack:create-formal-verification-skillIf you already know, name the area and the rule. These two come from the official guide:
/pstack:create-formal-verification-skill the job lease and retry logic. a job must never run twice at once./pstack:create-formal-verification-skill the retry queue. a message must never be delivered twice.Two more from everyday projects:
/pstack:create-formal-verification-skill the payment webhook and membership grant. The provider repeats and reorders webhooks; an order must grant membership exactly once./pstack:create-formal-verification-skill the bookmark sync logic. Two computers each edit bookmarks offline, then reconnect; both end up the same, with nothing lost or duplicated.One sentence with two things is enough: which code to check, and which rule must never break.
How it picks the target
It looks for a promise the code makes, where a break harms users and tests rarely reach the case that breaks it. It picks the most valuable target, not the easiest to verify. If you name an area, it starts there.
How it picks the tool
The question picks the tool. It tells you what it chose and why, so you don’t need to learn these languages:
| What you want to know | Kind of tool | Common examples |
|---|---|---|
| Can events happen in a bad order? | A model checker: a small model of the design, with every order walked | TLA+ (the default for this kind of question, whatever language your code is in) |
| Does the code itself behave for every input: memory safety, overflow, data-structure conditions? | A verifier that runs on the code | Depends on the language: CBMC for C, Kani for Rust |
| Your language has no such verifier | Lots of generated inputs against the real code | Property-based testing: fast-check, Hypothesis |
| It must hold at every size, and a bound isn’t enough | A proof | A proof assistant such as Lean |
The examples column is this site’s; the skill doesn’t prescribe a tool. It prefers one your team can install and run.
What good formal verification looks like
These are the skill’s own standards, and what to check when it hands over:
- True to the code: every part of the model or proof points to code you can open. What the code does in one step is one step in the model. Names come from your project.
- Able to fail: a check you’ve never seen fail proves nothing. Each rule is shown failing once on deliberately broken code (a removed check, two steps swapped), and the check catches it.
- Findings stay findings: if the current code already breaks the rule, it reports that with a counterexample. It doesn’t loosen the rule or the model to pass, and it doesn’t touch product code unless you ask.
- Honest about scope: what was verified, within what bounds, under which assumptions, and what’s left out. A pass covers that model and bound, not the whole system.
- Readable without the tool: the rule and the harm in one plain sentence each. The counterexample told as steps in your code’s words.
- Cheap to rerun: one command, a pinned tool version, fast enough that the next AI runs it on every relevant change.
- Kept in step with the code: it records which files and functions each check covers, and the commit where it last confirmed they match. When that code changes, the next AI knows to look again.
What a counterexample reads like
If the current code really has the bug, you don’t get formulas. You get steps like these:
- 1A takes job 4230-second lease
- 2A stalls for 31 sA long GC pause, say
- 3The lease expiresB takes the same job 42
- 4A wakes up and writesWithout checking it still holds the lease
- 5Job 42 ran twiceThe rule is broken
Each step maps to a place in the code, so you can walk the counterexample through the real code and confirm the model isn’t wrong. To show a PM or designer, use /pstack:statechart: when a check fails, it tells the shortest failing path in plain words; when it passes, it draws how the system moves between states.
/pstack:statechart what the user sees when they edit a note offlineWhat you get
A new skill in your project, named after the code it verifies. Reading only that skill, the next AI can:
- Tell whether a change touches the verified code.
- Run the check with one command.
- Tell a real bug from a modeling mistake.
- Update the verification when a change is intentional.
Before handing it over, it follows the skill once on a scratch change that breaks the rule in the real code, and the check must catch it. Then it drops the change and confirms the check is back where it started. At handoff it tells you:
- what it verified, with which tool, why that tool, and within what bounds;
- what the check found, in plain words;
- how to run it from now on;
- what it doesn’t cover.
It suggests a second target only if it found a close one.
When the code changes: /pstack:maintain-formal-verification-skill
The dangerous case isn’t a failing check. It’s a check that keeps passing after the code changed. It describes code that no longer exists, yet it looks like proof.
When a change goes through the verify skill, the AI updates the verification as it goes. For changes that skipped it (merges, someone editing directly, refactors), run:
/pstack:maintain-formal-verification-skillIt runs the check once as it is, reads every commit since the last confirmation that touched covered code (including renamed, split or moved functions), and updates the model from the code, not from what would make it pass. Each check ends with one outcome:
| Outcome | Meaning |
|---|---|
| in sync | Nothing that matters changed in the covered code, and the check passes |
| updated | The code changed, the verification now describes it, and the check passes |
| bug | The verification describes the current code, and the code breaks the rule. A finding about the code, not drift |
| blocked | It couldn’t bring the check back in line or couldn’t run it; it says why |
A check can be both updated and bug: the update makes it describe the code again, and then the rule fails. When an updated check passes, it breaks the new code on purpose once more to confirm the check still catches it. It changes a rule only when there’s evidence the promise changed on purpose (a doc comment, tests, a changelog, a commit message), and cites it. Verification updates go in a change of their own, separate from any product fix.
How the author uses it
- Released October 18, 2026, in pstack v0.15.27, marked beta. In the announcement, poteto gave two examples: TLA+ models for concurrent state machines, and Kani to check Rust for undefined behavior. poteto says modeling code in TLA+ has already found several bugs, without saying which.
- “The question picks the tool” was tested. In the PR that added the skill, the author tried it on six open-source projects it hadn’t seen: pg-boss, swr, HikariCP, client-go, cJSON and arrayvec. On cJSON (C) and arrayvec (Rust) it chose a verifier that runs on the code every time: CBMC and Kani. An earlier draft that prescribed TLA+ chose TLA+ on both. The author also notes the sample is small, one or two runs per project, so treat it as a lead.
- The author is candid about the maintenance skill. In its PR, poteto ran it 54 times on a TLA+ model of Go’s semaphore (including a version missing a wakeup) and on Python’s cachetools. The conclusion: the skill didn’t make results more correct, because the models already keep verification in step. What it added was breaking the code once more after the update to show the check still catches it: 11 of 11 runs with the skill, 5 of 10 without.
- The author’s pairing (October 21 post): first have the AI draw a statechart with
/pstack:statechartto understand the code, then use the generated TLA+ verification skill to find bugs before users do.
Why it’s worth trying now
Formal verification used to be rare: models and proofs took a lot of work, and few people knew how. AI has cut that cost, and people have been talking about it:
- Martin Kleppmann argues AI will make formal verification mainstream: proofs get cheap to write, and proof checkers catch exactly the mistakes AI makes (post, December 2025).
- Hillel Wayne, who has long taught TLA+, says AI greatly multiplies how much specification you can write (June 2025), and warns that specs AI writes casually often miss what a spec is for (March 2026). That’s why “able to fail” and “true to the code” above matter so much.
- Datadog checks AI-written code with TLA+ specs, simulation testing and Kani (Closing the verification loop, March 2026).
- AWS has long used TLA+ and its own P language to verify the designs of its distributed services (Systems Correctness Practices at AWS).
The full skill text is on this site: /pstack:create-formal-verification-skill, /pstack:maintain-formal-verification-skill, /pstack:statechart.
Stuck?
It says my language has no verifier that runs on the code.
That’s an honest answer. It tests the real code with lots of generated inputs instead of writing a hand model of what the code probably does. Ordering questions aren’t affected: TLA+ doesn’t care what language your code is in.
The check takes too long.
Say: “Shrink the scope until it runs in a few minutes, and state the smaller scope in the handoff.” A check that’s too slow won’t get run on every change, which is the same as not having it.
It reported a counterexample, and I can't tell if it's a real bug or a modeling mistake.
Ask it to “walk the counterexample through the real code, step by step.” If a step can’t happen in the code, the model is wrong; fix the model. If every step can happen, it’s a real bug. If the steps are hard to follow, use /pstack:statechart.
It wants to loosen the rule so the check passes.
No. Reply: “Keep the rule. The current code breaks it; write me the counterexample as steps in the code.” A finding gets reported as a finding; whether and how to fix it is your call.
It passed. Does that mean no bugs?
Only within that model and that scope. Read the “doesn’t cover” part of the handoff, and after the code changes, run /pstack:maintain-formal-verification-skill.