fix-flaky-test
Fix a flaky test
Stop the most tempting non-fix in software: re-running a test until it goes green, calling it fixed, and shipping the bug. A flaky test fails non-deterministically — green sometimes, red sometimes, usually worse under CI load than locally. The flake is a real signal about the system: ordering, timing, shared state, or a leaking resource. The only acceptable resolution is to reproduce it, name the nondeterminism, fix the cause, and prove the fix by looping the same test under the conditions in which it failed. This guide is the flake-stabilization discipline; it works in any repo and any test runner. Treat its rules as a discipline you hold yourself to — nothing enforces them at edit time.
A test that fails deterministically after a change is an ordinary defect — load write-fix.
Authoring new tests is write-testing. This guide stabilizes a test that already exists and
already named itself flaky.
Before you start, open references/notes.md and copy it into a working
notes file for this run — it is the session frame for this work; fill it in as you go (don't
reconstruct the structure from memory). It scaffolds the flake category, the reproduction protocol
and evidence, the hypothesis tracker, the fix evidence, and the self-review.