Writing a Minimal Reproduction
Delete everything the failure does not need, one element at a time, keeping only the deletions that leave the failure unchanged. The result is one small runnable case with exact versions, commands, and observed output.
A minimal reproduction is the smallest runnable artifact that still exhibits a bug. It is not a summary and not a copy of the failing project; it is the failure reduced until every remaining part is necessary. A maintainer can run it, observe the same wrong behavior, and change one variable at a time.
The short answer
Work backward from the failure and delete one thing at a time. After each deletion, rerun. If the failure survives, keep the deletion; if it disappears, restore the element and try a smaller removal elsewhere. Stop when nothing left can be removed without losing the failure.
A practical order is application code, dependencies, input data, configuration and environment variables, external services, then concurrency and timing. At every step preserve the exact command, exit status, full output, and versions. A reproduction that only fails on your machine has not been minimized; it has been moved.
| Target | Try removing | Keep the removal only if |
|---|---|---|
| Application code | functions, modules, branches | the same error remains |
| Dependencies | third-party packages | the failure is unchanged |
| Input | records, columns, bytes | the failure is unchanged |
| Environment | variables, locale, working directory | the failure is unchanged |
| Timing | sleeps, threads, retries | the failure rate stays comparable |
A minimal example
Suppose a parser fails on one file. Copy that file into an empty directory, add the smallest script that calls the parser, and run an isolated interpreter.
mkdir repro && cd repro
cp ../data/problem.json .
python -I -c 'import json,sys; json.load(open(sys.argv[1]))' problem.json
Now shrink the input. Remove object keys while the traceback stays identical, then halve the byte range until one line remains. When the data is small enough, inline it as a literal and delete the file. Record both sides of the observation:
expected: parse succeeds
actual: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The final artifact should be a directory small enough to paste into a bug report or attach as one archive.
Why this happens
Large projects carry incidental state: installed packages, environment variables, generated files, cached data, and ordering effects. The failure may depend on only a few of them. Reduction is a controlled experiment that separates causal conditions from decoration. It also exposes hidden coupling: if deleting an apparently unrelated module makes the bug vanish, that module was part of the cause.
Path handling is a common example. A relative path can resolve under the reporter's shell and fail under a service or test runner whose working directory differs; the mechanism is explained in why a missing file is reported against a relative path. Removing the path from the reproduction proves whether it matters.
What changes the answer
- Runtime version: test the reported version and one adjacent version, and record both.
- Input size: some failures need a threshold; do not shrink below it.
- Nondeterminism: run the case in a loop and report the failure count, not one run.
- Environment: OS, locale, filesystem case sensitivity, architecture, and environment variables.
- External data: replace services with recorded responses and keep encoding, compression, and line endings intact.
Edge cases
A heisenbug may disappear when logging is added. Capture output in memory or use tracing that does not serialize the race. Confidential data must be replaced while preserving length, encoding, and structure. Dependencies on private packages need a stub that reproduces the call pattern, with the stub stated explicitly. If the bug appears only in a release build, keep the build flags even though they look incidental.
Practical checks
Before publishing, confirm that one command reproduces from a clean checkout, expected and actual output are both stated, versions and install steps are included, the case fails before the fix and passes after it, and no secrets or licensed files remain. Keep the reproduction small enough to read in one sitting; put anything larger in an archive and link to it.
Sources
Revision history
- Published
- Updated
- — Initial publication.