| name | systematic-debugging |
| description | Systematic debugging - four-phase process, find root cause before fixing |
Systematic Debugging
Overview
Random fixes waste time and create new bugs.
Core principle: ALWAYS find root cause before attempting fixes.
The Iron Law
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
NO INVESTIGATION WITHOUT MEMORY RECALL FIRST
The Five Phases
Phase 0: Memory Recall (MANDATORY FIRST STEP)
- Extract keywords from error (error type, component, project)
- Query memory database for related past experiences
- Review results:
- Found relevant experience? → Apply directly, skip to Phase 4
- Partial match? → Use as starting point
- Nothing? → Proceed to Phase 1, remember to record solution later
Phase 1: Root Cause Investigation
- Read error messages carefully — don't skip, read completely
- Reproduce consistently — exact steps, every time?
- Check recent changes — git diff, new deps, config changes
- Gather evidence in multi-component systems — log at each component boundary, run once to find WHERE it breaks
- Trace data flow — where does bad value originate? Trace backward to source
Phase 2: Pattern Analysis
- Find working examples in same codebase
- Compare against references — read completely, don't skim
- Identify every difference between working and broken
- Understand dependencies — settings, config, environment, assumptions
Phase 3: Hypothesis and Testing
- Form single hypothesis: "I think X is the root cause because Y"
- Test minimally — smallest possible change, one variable at a time
- Verify before continuing — worked? → Phase 4. Didn't? → New hypothesis
Phase 4: Implementation
- Create failing test case — simplest reproduction, automated if possible
- Implement single fix — ONE change, no "while I'm here" improvements
- Verify fix — test passes, no other tests broken
- If 3+ fixes failed → STOP, question architecture, discuss before more attempts
Red Flags - STOP and Follow Process
- "Quick fix for now, investigate later"
- "Just try changing X"
- Proposing solutions before tracing data flow
- "One more fix attempt" (when already tried 2+)
ALL of these mean: STOP. Return to Phase 1.
Quick Reference
| Phase | Key Activities | Success Criteria |
|---|
| 0. Memory Recall | Extract keywords, query memory | Output recall summary |
| 1. Root Cause | Read errors, reproduce, gather evidence | Understand WHAT and WHY |
| 2. Pattern | Find working examples, compare | Identify differences |
| 3. Hypothesis | Form theory, test minimally | Confirmed or new hypothesis |
| 4. Implementation | Create test, fix, verify | Bug resolved, tests pass |