Systematic 4-phase debugging methodology for complex, intermittent, or mysterious issues. Use when investigating bugs, race conditions, or unexplained failures.
A disciplined, evidence-based approach to debugging that prevents guessing and ensures root cause discovery.
Goal: Create reliable reproduction steps before ANY investigation.
Actions:
Key Questions:
Output: Clear reproduction steps that reliably trigger the issue.
Goal: Reduce the search space from "entire codebase" to "specific component."
Techniques:
Binary Search:
Git Bisect (for regressions):
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
# Git will checkout commits for testing
# After each test:
git bisect good # or git bisect bad
# Continue until culprit found
Code Elimination:
Environment Isolation:
Output: "The bug is in [specific component/function/line range]"
Goal: Know exactly WHY the bug occurs, not just WHERE.
Scientific Method:
Logging Strategy:
// Add strategic logging at boundaries
console.log("[DEBUG] Function entry:", { input, state });
console.log("[DEBUG] After processing:", { result, sideEffects });
console.log("[DEBUG] Function exit:", { returnValue });
Common Root Causes:
| Symptom | Likely Causes |
|---|---|
| Works locally, fails in CI | Environment differences, timing, resources |
| Intermittent failure | Race condition, flaky network, resource contention |
| Works then stops working | State mutation, memory leak, cache poisoning |
| Wrong data | Type coercion, encoding, timezone, precision |
| Silent failure | Swallowed exception, async error, missing await |
Output: Clear explanation of the root cause with evidence.
Goal: Fix the issue and prevent regression.
Fix Process:
Verification Checklist:
Prevention:
DO NOT:
DO:
1. REPRODUCE → Can I reliably trigger this?
2. ISOLATE → Where exactly is it failing?
3. DIAGNOSE → Why is it failing?
4. FIX → How do I fix it permanently?
## Bug Investigation: [Title]
### Reproduction
- Steps to reproduce
- Environment details
- Frequency
### Isolation
- Search method used
- Scope narrowed to
### Root Cause
- What's actually wrong
- Why it happens
- Evidence
### Fix
- Code changes made
- Test added
### Prevention
- How to prevent similar bugs
- Documentation updates