Pangram verdict · v3.3
We believe that this entire text is human-written.
AI likelihood · overall
HumanArticle text · 1,478 words · 2 segments analyzed
Rohan PadhyeResearch fellow At Antithesis, we love finding bugs in distributed systems. But Antithesis can also help eliminate certain classes of bugs by using a combination of AI and formal methods to prove the correctness of complex design choices. In this post, we demonstrate the paradigm on two Raft implementations, production libraries from etcd and HashiCorp. Although they’re implementing the same protocol, there are significant differences in the approaches the two use. We used AI, TLA+, and Antithesis to formally model the two libraries with trace validation. We iterated between model checking, Antithesis testing, and proof attempts, each of which exposed bugs in the code or gaps in the model. We patched bugs and refined the model until it was provable, and until every test run was conformant. Our model handles several extensions to the core Raft algorithm including pre-votes, snapshots, leadership transfers, and, for etcd-raft only: read indexes for linearizability, async storage writes, and membership changes (where etcd’s implementation intentionally deviates from the Raft paper). The final proofs establish core Raft safety properties such as Election Safety, Leader Completeness, and State-Machine Safety. In other words, our process established that once we applied the workarounds and fixes needed, the specific designs (scoped to the features we modeled) embodied in HashiCorp Raft and etcd-raft actually offer the same guarantees that the Raft paper does. We make the artifacts available for open review: HashiCorp Raft formalized etcd-raft formalized Isn’t Raft already verified? Earlier this year, we wrote about how we keep finding bugs in every major Raft implementation we test with Antithesis. This was surprising, because the underlying Raft protocol has been extensively studied, formally specified, and rigorously proven correct (under a set of assumptions). In that post, we pointed out that many implementations subtly deviate from those assumptions, re-design the algorithm for performance, and/or extend the core Raft protocol with unverified extensions – thereby introducing bugs. Since then, advances in AI have made automated theorem proving and formal verification of complex systems much more scalable, making it feasible to connect a specification to its implementation. So we set out to formally verify not just the core Raft protocol, but the specific designs implemented by production Raft libraries, incorporating custom data structures, different modes of concurrency, and various extensions such as pre-votes, leadership transfers, snapshots, and (in the case of etcd-raft) membership changes. Formally modeling Raft implementations A key challenge in applying formal methods is to identify a level of abstraction that both allows us to reason mathematically about desired properties, and bridges the gap between specification and implementation. We are not yet at the point of reasoning directly at the level of assembly instructions or even programming language semantics in order to verify distributed safety properties in production systems. Both Anthropic/Theorem’s OSS-Verify and Google DeepMind’s AlphaProof Code only model single-threaded assembly code; whereas distributed systems are concurrent. The most widely used approach models the software as a state-transition system in a specification language such as TLA+, and checks invariants over these transitions for finite state spaces. TLA+ models can either be hand-written by experts, or these days, inferred directly from the code using AI. This approach has its own limitations, but is increasingly popular. The next challenge, then, is showing that the TLA+ model corresponds to the actual software that will run in production. For our demonstration, we used Claude Fable 5.2 to automatically infer TLA+ models from the implementations of HashiCorp Raft and etcd-raft and then manually reviewed the safety properties declared in the specifications. The etcd-raft repository has a TLA+ model crafted for trace validation that is now out of date, and is not designed for ease of proof. The Specular project produced models of etcd-raft and hashicorp-raft, but those models are designed for trace validation, not ease of proof, and the TLAPS leaderboard indicates that they remain unsolved as of 20 Nov 2026. We had to manually provide guidance on which features to model or leave out, what scenarios to specify for model checking, and make one refinement to the auto-generated safety properties. While AI is generally bad at inferring properties, in this case we simply instructed the agent to express the core safety properties defined in the Raft paper. But how do we know the model corresponds to the software? That’s where Antithesis helps. We used the recently launched Antithesis plugin to automatically set up a test cluster, an input-generating workload designed to handle all the features captured in the model, and assertions that correspond to the model’s safety properties. The software was then tested under fault injection while being fed random inputs, exercising various code paths and thread / message interleavings. For this demonstration, we developed a lightweight trace validation kit that allowed the software running in Antithesis to emit structured log events that correspond to state transitions in the TLA+ specification. Any test execution that produced a trace that did not conform to some path in the model got flagged. A non-conformant trace could indicate incorrect instrumentation of the trace logging itself, or more seriously, a modeling error or a real bug in the system. We instructed our AI agent to diagnose which one of these it might be, using Antithesis as necessary, and continue iterating until the traces and the inferred model converged. Invariants, model checking, and bug fixes For both Raft models, the specification expresses the following safety properties, taken directly from the Raft paper: Election Safety: at most one leader can be elected in a given term. Log Matching: if two logs have an entry with the same index and term, they agree on every entry up to that index. Leader Completeness: a leader’s log contains every entry committed in earlier terms. State Machine Safety: no two nodes apply different entries at the same index to their state machine (the state machine itself is not modeled). Before trying to prove anything, we verified that these invariants hold on bounded instances using TLC, the standard TLA+ model checker. These instances, also synthesized by our AI agent, specify various bounds: clusters are usually three nodes, a single client value, at most a couple of terms of leader election, logs that are limited to a few entries, with only a handful of network messages in flight. These bounds sound tiny, but they’re sufficient to create several interesting cases: competing elections, a deposed leader still replicating, log entries overwritten and re-replicated, crashes in the middle of an operation, etc. We also model checked various configurations of the Raft libraries, e.g. with pre-vote or snapshotting features enabled and disabled. These “small” instances can reach a state space of over 1.6 million states, which TLC explores exhaustively. We also included some larger problems which were only checked via random simulation. If model checking triggered a safety violation, we attempted to reproduce it as an assertion failure locally or in Antithesis; if the software couldn’t exhibit the behavior, the model had to be tightened. Overall, our process was an iterative loop consisting of model checking (flagging invariant violations), trace validation (flagging deviations), model refinement (to fix design flaws or conformance), and software patching (to fix bugs). In some ways, this approach is similar to and inspired by Specular. However, given their goal of finding bugs, Specular’s approach involved using AI to identify buggy scenarios before writing models, which meant that static analysis was doing a lot of the heavy lifting. In contrast, our models are intended to be more general and prove safety of the full design. Along the way, we encountered bugs in both systems, including previously known open issues such as hashicorp/raft#695 and etcd-io/raft#551, as well as new ones such as hashicorp/raft#746 and etcd-io/raft#558. In our internal repository, we applied a total of 7 patches across the two implementations. In each case, our goal was to make the system and model pass both verification and validation. We also encountered a few additional crash bugs, but those don’t violate safety. But bounded model checking only shows the absence of bugs in a small state space. The only way to get assurance for unbounded input sizes is via rigorous mathematical proof. Proofs, assurances, and limitations There are two good techniques for proving invariants correct for the whole specification: using a theorem prover integrated into TLA+ called TLAPS, or by translating the model into Veil, a library for the Lean proof assistant for modeling state-transition systems. We used both, delegating the task of proof construction to Claude Fable 5.2. We used Veil’s official tla-to-veil LLM skill for the model translation, and the recommended approach of validating this via bounded equivalence checking, using TLC and Veil’s own model checker, on our previously stored instances. Ideally, a TLAPS proof provides the best assurance, since it can attest to safety properties defined on the TLA+ model itself. However, we decided to translate TLA+ to Veil and attempt proofs in Lean.
Why?