TLA+ checked 18 million states of our payment protocols
At Catena, we take money movement extremely seriously. When an AI agent asks us to move money, it has to happen exactly once and within the agent’s limits, no matter what else is going on at the same time.
Timing is what makes that hard. Two requests arrive at once, a server crashes partway through a payment, a retry lands after the original already went through, and the steps run in an order nobody planned for.
Traditional tests rarely catch these. A test runs the steps in one order, the one its author wrote down, and a timing bug needs a different one.
So we tried TLA+. You write down how part of your system behaves, and a tool called TLC tries every order its steps can run in. We call each of those write-ups a model. Our first four models found four edge cases our tests had missed, and we closed all four quickly.
How it works
A model describes your system with a few variables, such as whether a hold (money set aside for a payment) is still held, and how far each request has got. A state is one set of values for those variables. A step changes some of them in one go, like a single database transaction. Then you write down rules that must always be true, such as “a hold is released at most once.”
TLC starts from the first state and tries each step that can happen next, then each step after those, and keeps going until there are no new states left. If a state breaks a rule, TLC stops and shows you the exact steps that got there.
Here’s a toy example: two requests each check that a hold is still held, then release it. Press Run to watch a re-creation of TLC’s search (it runs in your browser and prints the same trace and counts as the real tool).

Both requests check before either one releases, so the hold is released twice. The fix is to check and release in one step, with a single update that releases the hold only if it’s still held. Switch to the fixed version and run it again: no order breaks the rule.
Two catches. TLC only checks within the limits you set, such as two requests at a time, or one server crash partway through, so a bug that needs three requests won’t show up in a check with two. And a model only covers what it describes: if it leaves something out, such as clock time, TLC can’t find a bug that depends on it.
What we’ve modeled so far
We started with the parts of Catena behind agents’ payments, where many requests act on the same records at once. Our first four models cover:
- intents: an agent’s request for Catena to do something, like make a payment;
- intent payments: how a payment stays within the agent’s limits;
- the signing ceremony: how a payment plan gets signed before it runs;
- transaction nonces: the counter that keeps transactions in order when many requests share one signing account.
Each model starts from promises the code makes, the way the toy starts from “a hold is released at most once.” We work those promises out from what the code is meant to do, and turn them into rules TLC can check.
A model is a separate description of the code, so it can go wrong in two ways, and we check for both. Some checks are meant to fail: they model the code as it was before a fix, and TLC must find the old bug again. If it doesn’t, a change to the model has hidden the bug it was built to catch. And every step that stands for our code links to the lines it describes, so a script we run before trusting a model tells us which of those lines have changed.
Claude Code agents wrote the models and ran TLC, and a second set of agents checked each model against the code. An engineer chose what to model and which fixes to make.
All of it runs on a laptop. Here is the largest check for each model:
| Model | States | Time |
|---|---|---|
| Intents | 2,141 | about a second |
| Intent payments | 1,650,930 | five to seven minutes |
| Signing ceremony | 5,038,566 | about five minutes |
| Transaction nonces | 11,037,712 | about four minutes |
What the models found
For each of the four edge cases, TLC showed us an order of steps that broke a rule. We wrote a test that replayed that order against the real code, watched it fail, and then fixed the code. All four fixes are in production.
Edge cases like these are rare and hard to reproduce, and code that moves money has to handle every one of them. Each one we close makes Catena tighter and safer for the agents and people who use it.
It’s early, and four models is a small start. We’re picking the next parts of the product to model now.
By the way, if you’d like to work with AI agents that check each other’s work on code that moves money, we’re hiring.
