systematic-debugging
Systematic Debugging — Root Cause First
Iron Law
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.
If you're about to change code to "try something," STOP. Investigate first.
The 4 Phases
Phase 1: Root Cause Investigation
-
Read the error — Read the FULL error message, stack trace, and logs. Not just the first line.
-
Reproduce — Can you make the error happen consistently? If not, gather more data before changing anything.
-
Check recent changes — What changed since it last worked?
git log --oneline -10 git diff HEAD~3 -
Gather evidence — Don't theorize without data. Check database state, API responses, config values.
Phase 2: Pattern Analysis
-
Find working examples — Is there similar code in the project that works? Compare it.
-
Compare — What's different between working and broken code?
-
Check dependencies — Is the issue in your code or something upstream? Check library versions, external API changes.
Phase 3: Hypothesis and Testing
- Form ONE hypothesis — "The error occurs because X"
- Test minimally — Change ONE thing to verify
- If wrong — Return to Phase 1, don't stack guesses
Phase 4: Implementation
- Write a failing test that reproduces the bug
- Fix the root cause (not the symptom)
- Verify the test passes
- Run full test suite — no regressions
- Document the failure — Log what failed and why for future reference
Rationalizations That Mean STOP
| Thought | Reality |
|---|---|
| "Let me just try this quick fix" | That's guessing. Investigate first. |
| "It's probably X" | Probably is not certainly. Verify. |
| "I'll fix it and see if it helps" | You're changing code without understanding. |
| "Multiple things might be wrong" | Fix one thing at a time. |
| "I've seen this before" | Verify in THIS codebase. Don't assume. |
When You're Stuck (3+ Failed Fixes)
Don't keep guessing. Escalate:
- Document what you tried and what happened
- List your symptoms, what you investigated, and hypotheses tested
- Ask for help with specific questions, not "it doesn't work"
- Share the evidence you've gathered so others don't repeat your investigation