1.8 KiB
1.8 KiB
name, description
| name | description |
|---|---|
| systematic-debugging | Use when debugging complex bugs, unexpected test failures, race conditions, or production anomalies. Enforces a rigorous scientific debugging method over trial-and-error edits. |
Systematic Debugging — The Scientific Method for Bug Fixing
Core Discipline
Never guess, shotgun edit, or apply speculative fixes without proving the root cause. Follow the 5-phase scientific debugging loop.
Phase 1: Reproduce & Isolate
- Deterministic Reproduction: Create a minimal, self-contained test case or command that reliably reproduces the failure.
- Eliminate Variables: Strip away unrelated components, mocks, or background noise.
- Capture Ground Truth: Inspect actual inputs, outputs, error codes, and stack traces — do not rely on memory or assumptions.
Phase 2: Formulate Hypotheses
- Brainstorm candidate root causes based on observed behavior.
- Rank hypotheses by likelihood.
- For each hypothesis, define an empirical test: "If hypothesis X is true, observing Y will yield Z."
Phase 3: Test Hypotheses (Binary Search & Instrumentation)
- Add targeted logs, breakpoints, or assertion guards at key boundary points.
- Use bisection (git bisect or code division) to narrow down when/where state deviates from expected invariants.
- Invalidate or confirm hypotheses one by one.
Phase 4: Root Cause Fix
- Fix the underlying design flaw, invariant violation, or race condition — not just the symptom.
- Verify that the fix does not break related code or introduce regressions.
- Clean up all temporary debug logging and instrumentation.
Phase 5: Regression Prevention
- Commit the automated reproduction test (unit/integration test) alongside the fix.
- Add explicit invariants or typing to prevent this class of bug at compile or boot time.