You Can SIM Everything A developer building the Fiber payment-channel network on Nervos used AI coding agents to set up deterministic simulation testing (DST) with Tokio's turmoil library, after finding that AI code reviews and AI-written unit tests kept surfacing new bugs on each pass. The DST harness places clocks, I/O and randomness inside a simulated environment, injects faults such as delayed peer responses, random offline drops and unexpected crashes, and drives every random choice from a PRNG so a failed run can be reproduced from the commit ID and seed. The developer reports that each bug an AI review catches can be converted into a new fault injection or random scenario, so the test suite compounds rather than accumulating isolated unit tests. You Can Sim Everything Endless AI Reviews Since I started using AI, I’ve enjoyed using it most on side projects. Without strict testing or conventions to worry about, I can just enjoy the feeling of features pouring out. Work projects are a different story. We still have to care about software engineering and make sure every release behaves properly, and that’s where AI starts to struggle. AI code reviews can catch plenty of bugs, yet they quickly turn into a slog: every pass turns up a bunch of issues, and fixing them just leads to even more issues on the next pass. Meanwhile, the unit tests AI writes are full of holes, packed with wrong assumptions and useless checks. If we need stricter guarantees around implementation details and program state, all AI can do is write more unit tests to try to cover every state. The problem is that it’s hard to be sure those tests actually work, and reviews still find bugs anyway. With subscription token limits continuing to shrink, I needed a tool that can reliably catch bugs on its own instead of leaning on AI reviews. Deterministic Simulation Tests DST stands for Deterministic Simulation Testing. A few years ago, I read a post from TigerBeetle about how they use DST to keep their software reliable, then completely forgot about it until the term popped up on Twitter again. With agents around now, it felt like the right time to actually try it. Building a DST setup used to eat up too much engineering time, whereas with agents it only costs some tokens, and it sounded like the exact fix for my problem. The way I think about DST is simple: put external dependencies like clocks, I/O, and randomness inside a simulated environment, inject faults on purpose, and run all kinds of scenarios through the software. Because each scenario runs alongside multiple randomly injected faults, we can check whether the system still holds its invariants under unexpected combinations of failures. Everything random in the simulation - which fault fires and when - is driven by a PRNG. So whenever a run fails, all we need is the commit ID and the seed to reproduce it deterministically. With DST, we don’t have to maintain a huge pile of unit tests to cover every path. DST mixes and matches faults randomly, which is hard to do with unit tests. It’s also much easier to maintain over time: whenever an AI review catches a bug, we can take whatever generalizes and turn it into a new fault injection or random scenario in DST. That way, each bug fix doesn’t just add one isolated test - it adds a test that compounds with every other fault scenario, letting the test suite grow cleanly alongside the project. In Practice The first project I tried this on was Fiber https://github.com/nervosnetwork/fiber . Fiber is a payment channel network where nodes talk over P2P, run complex protocols to execute transactions, and have to defend against Byzantine attacks. All the ways those things can fail together make it a natural fit for DST. I asked an agent to analyze the codebase. It suggested using Tokio’s turmoil to simulate network faults and adding a few fault-injection hooks into our own code. Most of the simulation code lives in a separate crate, while the existing codebase just needs a handful of hooks for simulation mode. cfg all feature = "simulation", not target arch = "wasm32" crate::simulation::before actor message myself.get id .await; That change was about what I expected. Those external boundaries rarely move, while most day-to-day churn happens in the protocol interactions and business logic. Next, I had the agent inject faults into P2P communication and protocol exchanges, like making peers deliberately delay responses, drop offline at random, or crash unexpectedly. While running DST across random seeds, the agent kept hitting bugs in the simulation harness itself the code driving the simulation . Luckily, it spotted that the harness was at fault and fixed it right away. After that, it surfaced 6 real state-handling bugs in Fiber. Six bugs was way fewer than I expected. The faults we were injecting were still pretty basic, and we weren’t checking many invariants yet. So what faults should we inject next, and what state checks were we missing? I figured maybe we could learn something from history. The only thing we learn from history is that we learn nothing from history. We can, however, learn from Git history. So I had the agent scan Fiber’s last 100 commits, pull out the bug fixes, and group them by failure type. I wanted to know: could our current DST setup actually catch the bugs we’d already run into in the past? Based on those past bugs, the agent added several new fault types and tuned the injection strategy. After that round, the number of bugs it reported jumped to around 20. Dealing with AI Hallucinations As I had the agent keep fleshing out DST, I noticed it would sometimes hallucinate badly and build “fake simulations”: we wanted to test a piece of real protocol logic, and the agent ended up mocking that logic away too. Sometimes it caught and fixed these mistakes during later reviews, yet a few bogus paths always slipped through and stayed in the codebase. Take the code below. We should have been simulating at the P2P or network layer so we could exercise our actual protocol. Instead, the agent added special simulation-only hooks that completely bypassed things like the peer handshake. /// Register the output queue for a simulated TCP link. cfg all feature = "simulation", not target arch = "wasm32" RegisterSimulatedPeer { pubkey: Pubkey, sender: crate::simulation::SimulatedPeerSender, features: FeatureVector, reply: RpcReplyPort