How to reproduce a bug reliably every time
bug reproduction, minimal reproducible example, environment isolation, flaky bugs, reproduction checklist
Reproduction Is Step Zero
You cannot debug a bug you cannot reproduce. A non-reproducible bug gives you no signal -- you cannot know whether your fix worked or whether the bug just failed to appear. Before writing a single fix, make the bug happen on demand.
Steps to Reliable Reproduction
First, capture the exact inputs, state, and environment that triggered the failure. This means OS, runtime version, input data, user session state, network conditions -- anything that differs between runs. Second, strip away everything unrelated. A minimal reproducible example (MRE) is the smallest input set that still causes the failure.
// Full broken function -- hard to debug
function processOrder(user, cart, coupon, session, flags) { ... }
// MRE: narrowed to the actual fault
function applyDiscount(price, coupon) {
return price - coupon; // bug: coupon is a string, not a number
}
console.log(applyDiscount(100, "20")); // outputs 10020 not 80
Flaky Bugs
Some bugs are timing-dependent, environment-dependent, or data-dependent. For these, add logging around the suspected area and run it many times until the failure appears. Once it appears in logs, treat those log conditions as your reproduction recipe. Never declare a flaky bug fixed until it has been absent under the exact conditions that previously triggered it.
