
What it is
An AI agent is a long program with slow, costly and flaky steps: model calls that cost money, tools behind rate limits, a person who takes hours to approve something. If the process dies halfway, you either pay for every model call again or resume blindly and send the email twice.
Tenacity runs those workflows so a crash doesn’t matter. Workflow code is ordinary Go. Every decision it makes is recorded in an append-only event log, and a crashed workflow resumes on any worker by replaying that log:
- Log first. Each step is committed to the run’s event log before anything acts on it.
- Replay instead of restart. Finished steps return their recorded results. A new worker replays a run in under a millisecond. If the code no longer matches its history, the run stops with a diff.
- Effects happen once. Each activity gets an idempotency key that stays the same on every retry, for payment and email APIs to deduplicate on.
- Fenced leases. Lease tokens only go up, even across database crashes, so a late worker can’t overwrite a newer one.
Timers and signals survive restarts, so a run can wait three days for a person to approve. Token and dollar budgets reserve before each model call and settle after it.
I also built a product page with a simulated demo. You kill the worker, the server or the database at any point and watch the run recover, next to a ledger of what a plain script would have redone.
How it works
In cluster mode the servers run a Raft group that decides which server owns each shard.
The server batches concurrent commits on each shard into one fsync. Workers keep runs in memory between tasks, so the server sends only new events instead of the whole history. In cluster mode the servers run their own Raft group to decide which one owns each shard, and every shard write is fenced by an epoch.
The agent layer runs model calls as activities with streaming and heartbeats. It also has human approval through signals, a replay debugger, and OpenTelemetry traces computed from history. The example research agent runs on OpenRouter models or offline.
Results
Every number is recorded in the repo’s evidence log with its date, commit, hardware, command and raw output.
| Test | Result |
|---|---|
| Crash tests on Postgres | 396 server kills and 29 kills of Postgres itself mid-run: 0 duplicate or missing effects out of 18,000 |
| 1,000-agent acceptance gate | Workers killed every second: 34,308 model calls, each billed exactly once, every run completed |
| Recovering a killed model call | about 60 s → 8 to 9 s with streamed calls and heartbeats |
| History sent per workflow task | up to 298 events → 3 with sticky caches (200-step run) |
| Starts per second, 64 clients, full durability | 389 → 2,299 with group commit |
| Postgres next to SQLite (same VM and disk) | 1,076 starts/s vs 620 from 16 clients |
| Raft and ownership simulation | 10,000 seeds per profile, 0 safety violations, 9 of 9 planted bugs caught |
The crash harness has a negative control: run it with deduplication turned off and it must fail.
I built it in eleven milestones: the single-node engine, crash safety, sharding and timers, Raft and cluster mode, the agent layer, benchmarks, group commit, fewer fsyncs, streaming and heartbeats, sticky caches, and the Postgres backend. There are 24 written design decisions.
Limits
- All numbers come from one Windows laptop.
- Cluster mode runs on one machine with shared storage, and only on SQLite for now.
Stack
Go, SQLite (pure Go driver), Postgres 17, a Raft implementation of my own with a deterministic simulator, OpenTelemetry, OpenRouter. The product page is one HTML file with no build step.