Detloop
Find timing bugs in Python asyncio services and replay a failing run from its seed.

The problem
Distributed asyncio tests can pass hundreds of times before a delayed message or a node crash exposes a race. Finding the bug is only half the job. To diagnose it, you need to recreate the order of events that caused it.
Detloop runs asyncio tests with a virtual clock, seeded scheduling and a simulated network. It records the decisions behind a failure so you can replay the run, reduce the fault sequence and inspect the events in an offline report.
What it does
- Explore a range of seeds from pytest or the CLI, with simulated message delays, network partitions and node crashes.
- Check invariants during a run and detect inconsistencies such as stale reads with a bounded linearizability checker.
- Replay a saved failure, shrink the fault sequence and open a self-contained HTML report with node timelines and operation history.
How it works
- 1
A custom asyncio event loop runs standard tasks, futures and streams. When no callbacks are runnable, the virtual clock jumps to the next timer.
- 2
Each simulated node keeps asyncio's callback order. Seeded decisions choose which node runs next and control network timing, workload randomness and faults.
- 3
A failing run writes a trace and a replay manifest. Exact replay checks the recorded decisions for divergence. The shrinker reruns candidates and keeps a simpler sequence when it preserves the failure signature.
Decisions worth noting
Keep real I/O outside the simulation
Detloop rejects documented sources of nondeterminism such as real sockets, threads and TLS. Replay depends on the code, configuration and Python minor version.
Give incomplete runs their own outcome
A run that hits a budget or exceeds the checker's search limit is marked incomplete, so CI can distinguish it from a passing run.