Exterminating Heisenbugs

October 16, 2026 • 8 min read

Exterminating Heisenbugs

In the last post, I gave an analogy of software as a roomful of bugs between a floor (what the language guarantees automatically) and a ceiling (a full formal proof the program meets its spec). Three complementary moves shrink the room. Correct-by-construction raises the floor by adding more universal guarantees. Correct-by-verification pushes walls in from the side by proving specific programs against their specs. Screens—testing of various kinds—try to catch what still lives in the gap.

One category of bug eats a disproportionate share of debugging time and resists ordinary testing. These are the bugs that depend on the environment's randomness. Something small shifts in the environment—a packet arriving slightly late, say, or a thread scheduled in an unexpected order—and the system misbehaves in a way that you can't reproduce on your laptop. Jim Gray named them in 1985: Heisenbugs, by analogy to Heisenberg's uncertainty principle, because the act of observing them often makes them disappear. A debugger or an added log statement perturbs timing enough that the bug stops reproducing. Gray contrasted them with Bohrbugs (named for the Bohr atom): "solid, easily detected by standard techniques, and hence boring." Of 132 software faults Gray recorded in Tandem's spooler, only one was a Bohrbug. (Gray wrote this decades before Breaking Bad, but as always he was foresighted. In prod, at 3 AM, the Heisenbugs are the ones who knock.)

Heisenbugs are hard for a structural reason: the program's behavior silently depends on choices made by the external environment—choices that nobody writes down in a program. Most people don't write tests for issues outside their codebase, so the problems don't get reproduced during testing.

To make progress, the best move is to stop letting the environment make those choices silently. Two approaches tackle this seriously. One builds a better screen. The other raises the floor and puts a tailored screen on top.


Simulation testing

The ideal defense would be a magical oracle: a mechanism that systematically explores every behavior the environment could produce—every possible input, every message ordering, every combination of failures—and reports whether any of them produces a bug. These unrecorded environmental choices are the "blank space" developers rarely test. Because the choices happen outside the program, no amount of staring at the code reveals them.

Like all oracles, this one is infeasible. But we can approximate it with simulation testing: tools that take over the sources of randomness the environment usually controls—schedulers, clocks, networks, failures—and systematically explore the behaviors those sources can produce.

Shuttle and Loom do this at the thread-scheduling level in Rust; Turmoil does it for the network under Tokio. Antithesis generalizes further: it runs your entire system as a black box in a deterministic hypervisor, giving the same replay guarantees without requiring any language-level hooks.

Reproducibility is the big win: a bug you can replay is a bug you can fix. But the space of possible environmental behaviors is combinatorial, and no sampling budget can cover it to the depth of practical deployment. As explained in my previous post, model checkers exhaustively check small configurations, and other approaches (fuzzing, property-based testing) use directed random probes. Both categories are incomplete heuristics. We cannot implement the oracle; the screens approximate it well, but still have holes.


Raise the floor, then screen what's left

The second approach is structurally different. Instead of approximating the oracle with a better screen, it raises the floor: the language refuses to compile programs that could silently depend on environmental randomness. Most Heisenbugs then become impossible to express. The ones that remain are confined to clearly marked regions where a tailored screen can focus.

This is what Hydro does. Every source of non-determinism that could perturb the program's behavior has to be acknowledged in the type system. If an unordered stream of messages reaches an operator that cares about ordering, the type system either demands a proof that the operator is commutative—so the ordering doesn't matter—or demands that the ambiguity be wrapped in a nondet! block. Every dependency on the environment's randomness is either proven handled or explicitly flagged.

The formal name for this guarantee is eventual determinism: Shadaj Laddad introduced it in his Ph.D. dissertation and formalized it for streaming computation in the Flo paper at POPL 2025.

Hydro's built-in model checker—HydroSim—then focuses entirely on the nondet! blocks, in either exhaustive (model-checking) or fuzzing mode. Everything outside those blocks is deterministic by construction, so a single pass covers each deterministic path. The screen's whole budget concentrates on the handful of flagged corners where the environment can actually perturb the result.

That concentration is the second payoff of the floor-raise, and it is a big one, in the Big-O sense and in practice. Simulation testers like Shuttle or Antithesis have to spread a fixed testing budget over the entire program's behavior space. HydroSim spreads the same budget over a space that is dramatically smaller—exponentially smaller, in cases where a commutativity proof lets the simulator skip whole permutation groups. This allows HydroSim to reinvest the saved budget in deeper, larger scenarios inside the regions that remain.. To push the screen analogy, HydroSim uses the same amount of wire as other simulation harnesses, but in a much smaller area, producing a finer mesh.


Who proves the properties?

Hydro's floor-raise rests on claims like "this closure is commutative" or "this one is idempotent." Today those claims are the programmer's responsibility: Hydro's type system accepts manual_proof! annotations, and the determinism guarantees ride on them being true. A misdeclared closure would compile fine and silently violate the determinism the type system promises.

The long-term answer is to prove them with automated techniques, as explored in the last chapter of Conor Power's Ph.D. dissertation. We are now beginning to implement that idea in the Hydro codebase, via integration with Verus so that an SMT solver discharges these obligations at build time. The proofs are typically small, and the specifications come from the type system rather than the programmer. For example, the Hydro type system dictates that a Rust closure in a fold over an unordered stream must be proved commutative; the proof may be only a few lines of equational reasoning, which is exactly where deductive verification works well. The type system identifies the obligation automatically, and the solver discharges it once at build time. The resulting guarantee carries into every test run and deployment.


Where each wins

The two approaches have different roles to play in today's software ecosystem.

Runtime-level testers are powerful when the program under test was written in a language that lacks Hydro-style non-determinism tracking. If you have a Rust service that races in interesting ways, Shuttle gives you deterministic replay. Antithesis extends the same idea to arbitrary systems under test, which is a big deal if you can't change the language the system is written in. The price is coverage: if you don't know what to test, you have to test a combinatorial mixture of every possibility, which forces you to spend your testing budget quite broadly—it's a big screen with a loose mesh.

Language-level elimination raises the floor at compile time by refusing to let the bug be written in the first place. Where non-determinism really must survive, developers mark those regions explicitly and the testing budget focuses on them. This requires buying into the language, which is a bigger commitment than running a test harness. The payoff is that most Heisenbugs become impossible to express; the ones that remain are confined to a handful of flagged regions where the testing budget can be spent surgically.

In my opinion, the second approach is a better bet going forward. The payoff is the one we've already covered: fewer bugs can be expressed in the first place, and the ones that remain live in a smaller space the screen can cover more thoroughly. The historical cost of adopting a restrictive type system has also fallen sharply in the LLM era: when the compiler refuses a program, an assistant can usually explain why and suggest a fix.

That said, the two approaches can be combined nicely. Hydro's type system narrows the places where non-determinism can live to its nondet! blocks. HydroSim provides a complementary runtime-level tester to catch bugs in those narrow places. I hope to see this one-two punch in more programming environments in the coming years; in the interim, I strongly recommend the runtime testing and verification tools discussed above and in my previous post.


Joseph M. Hellerstein

Joseph M. Hellerstein

UC Berkeley CS Prof.
AWS VP/Distinguished Scientist
Hydro-ologist.

© 2026 Joseph M. Hellerstein. All rights reserved.