Systematic Debugging
Overview
Random fixes waste time and create new bugs. Quick patches mask underlying issues.
Core principle: ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
Violating the letter of this process is violating the spirit of debugging.
The Iron Law
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
If you haven't completed Phase 1, you cannot propose fixes.
When to Use
Use for ANY technical issue:
- Test failures
- Bugs in production
- Unexpected behavior
- Performance problems
- Build failures
- Integration issues
Use this ESPECIALLY when:
- Under time pressure (emergencies make guessing tempting)
- "Just one quick fix" seems obvious
- You've already tried multiple fixes
- Previous fix didn't work
- You don't fully understand the issue
Don't skip when:
- Issue seems simple (simple bugs have root causes too)
- You're in a hurry (systematic is faster than thrashing)
The Four Phases
You MUST complete each phase before proceeding to the next.
Phase 1: Root Cause Investigation
BEFORE attempting ANY fix:
Read Error Messages Carefully
- Don't skip past errors or warnings
- They often contain the exact solution
- Read stack traces completely
- Note line numbers, file paths, error codes
Reproduce Consistently
- Can you trigger it reliably?
- What are the exact steps?
- Does it happen every time?
- If not reproducible -> gather more data, don't guess
Check Recent Changes
- What changed that could cause this?
- Git diff, recent commits
- New dependencies, config changes
- Environmental differences
Gather Evidence in Multi-Component Systems
WHEN system has multiple components:
BEFORE proposing fixes, add diagnostic instrumentation:
For EACH component boundary:
- Log what data enters component
- Log what data exits component
- Verify environment/config propagation
- Check state at each layer
Run once to gather evidence showing WHERE it breaks
THEN analyze evidence to identify failing component
THEN investigate that specific component
Trace Data Flow
- Where does bad value originate?
- What called this with bad value?
- Keep tracing up until you find the source
- Fix at source, not at symptom
Phase 2: Pattern Analysis
Find the pattern before fixing:
Find Working Examples
- Locate similar working code in same codebase
- What works that's similar to what's broken?
Compare Against References
- If implementing pattern, read reference implementation COMPLETELY
- Don't skim — read every line
Identify Differences
- What's different between working and broken?
- List every difference, however small
- Don't assume "that can't matter"
Understand Dependencies
- What other components does this need?
- What settings, config, environment?
- What assumptions does it make?
Phase 3: Hypothesis and Testing
Scientific method:
Form Single Hypothesis
- State clearly: "I think X is the root cause because Y"
- Write it down
- Be specific, not vague
Test Minimally
- Make the SMALLEST possible change to test hypothesis
- One variable at a time
- Don't fix multiple things at once
Verify Before Continuing
- Did it work? Yes -> Phase 4
- Didn't work? Form NEW hypothesis
- DON'T add more fixes on top
When You Don't Know
- Say "I don't understand X"
- Don't pretend to know
- Ask for help
- Research more
Phase 4: Implementation
Fix the root cause, not the symptom:
Create Failing Test Case
- Simplest possible reproduction
- Automated test if possible
- MUST have before fixing
Implement Single Fix
- Address the root cause identified
- ONE change at a time
- No "while I'm here" improvements
- No bundled refactoring
Verify Fix
- Test passes now?
- No other tests broken?
- Issue actually resolved?
If Fix Doesn't Work
- STOP
- Count: How many fixes have you tried?
- If < 3: Return to Phase 1, re-analyze with new information
- If >= 3: STOP and question the architecture
- DON'T attempt Fix #4 without architectural discussion
If 3+ Fixes Failed: Question Architecture
Pattern indicating architectural problem:
- Each fix reveals new shared state/coupling/problem in different place
- Fixes require "massive refactoring" to implement
- Each fix creates new symptoms elsewhere
STOP and question fundamentals:
- Is this pattern fundamentally sound?
- Are we "sticking with it through sheer inertia"?
- Should we refactor architecture vs. continue fixing symptoms?
Red Flags — STOP and Follow Process
If you catch yourself thinking:
- "Quick fix for now, investigate later"
- "Just try changing X and see if it works"
- "Add multiple changes, run tests"
- "Skip the test, I'll manually verify"
- "It's probably X, let me fix that"
- "I don't fully understand but this might work"
- "Here are the main problems: [lists fixes without investigation]"
- "One more fix attempt" (when already tried 2+)
ALL of these mean: STOP. Return to Phase 1.
Common Rationalizations
| Excuse |
Reality |
| "Issue is simple, don't need process" |
Simple issues have root causes too. Process is fast for simple bugs. |
| "Emergency, no time for process" |
Systematic debugging is FASTER than guess-and-check thrashing. |
| "Just try this first, then investigate" |
First fix sets the pattern. Do it right from the start. |
| "I'll write test after confirming fix works" |
Untested fixes don't stick. Test first proves it. |
| "Multiple fixes at once saves time" |
Can't isolate what worked. Causes new bugs. |
| "I see the problem, let me fix it" |
Seeing symptoms != understanding root cause. |
| "One more fix attempt" (after 2+ failures) |
3+ failures = architectural problem. Question pattern, don't fix again. |
Quick Reference
| Phase |
Key Activities |
Success Criteria |
| 1. Root Cause |
Read errors, reproduce, check changes, 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 |
Real-World Impact
From debugging sessions:
- Systematic approach: 15-30 minutes to fix
- Random fixes approach: 2-3 hours of thrashing
- First-time fix rate: 95% vs 40%
- New bugs introduced: Near zero vs common
1---2name: systematic-debugging3description: Use when encountering any bug, test failure, or unexpected behavior. Requires root cause investigation before proposing fixes.4---56# Systematic Debugging78## Overview910Random fixes waste time and create new bugs. Quick patches mask underlying issues.1112**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.1314**Violating the letter of this process is violating the spirit of debugging.**1516## The Iron Law1718```19NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST20```2122If you haven't completed Phase 1, you cannot propose fixes.2324## When to Use2526Use for ANY technical issue:27- Test failures28- Bugs in production29- Unexpected behavior30- Performance problems31- Build failures32- Integration issues3334**Use this ESPECIALLY when:**35- Under time pressure (emergencies make guessing tempting)36- "Just one quick fix" seems obvious37- You've already tried multiple fixes38- Previous fix didn't work39- You don't fully understand the issue4041**Don't skip when:**42- Issue seems simple (simple bugs have root causes too)43- You're in a hurry (systematic is faster than thrashing)4445## The Four Phases4647You MUST complete each phase before proceeding to the next.4849### Phase 1: Root Cause Investigation5051**BEFORE attempting ANY fix:**52531. **Read Error Messages Carefully**54 - Don't skip past errors or warnings55 - They often contain the exact solution56 - Read stack traces completely57 - Note line numbers, file paths, error codes58592. **Reproduce Consistently**60 - Can you trigger it reliably?61 - What are the exact steps?62 - Does it happen every time?63 - If not reproducible -> gather more data, don't guess64653. **Check Recent Changes**66 - What changed that could cause this?67 - Git diff, recent commits68 - New dependencies, config changes69 - Environmental differences70714. **Gather Evidence in Multi-Component Systems**7273 **WHEN system has multiple components:**7475 **BEFORE proposing fixes, add diagnostic instrumentation:**76 ```77 For EACH component boundary:78 - Log what data enters component79 - Log what data exits component80 - Verify environment/config propagation81 - Check state at each layer8283 Run once to gather evidence showing WHERE it breaks84 THEN analyze evidence to identify failing component85 THEN investigate that specific component86 ```87885. **Trace Data Flow**89 - Where does bad value originate?90 - What called this with bad value?91 - Keep tracing up until you find the source92 - Fix at source, not at symptom9394### Phase 2: Pattern Analysis9596**Find the pattern before fixing:**97981. **Find Working Examples**99 - Locate similar working code in same codebase100 - What works that's similar to what's broken?1011022. **Compare Against References**103 - If implementing pattern, read reference implementation COMPLETELY104 - Don't skim — read every line1051063. **Identify Differences**107 - What's different between working and broken?108 - List every difference, however small109 - Don't assume "that can't matter"1101114. **Understand Dependencies**112 - What other components does this need?113 - What settings, config, environment?114 - What assumptions does it make?115116### Phase 3: Hypothesis and Testing117118**Scientific method:**1191201. **Form Single Hypothesis**121 - State clearly: "I think X is the root cause because Y"122 - Write it down123 - Be specific, not vague1241252. **Test Minimally**126 - Make the SMALLEST possible change to test hypothesis127 - One variable at a time128 - Don't fix multiple things at once1291303. **Verify Before Continuing**131 - Did it work? Yes -> Phase 4132 - Didn't work? Form NEW hypothesis133 - DON'T add more fixes on top1341354. **When You Don't Know**136 - Say "I don't understand X"137 - Don't pretend to know138 - Ask for help139 - Research more140141### Phase 4: Implementation142143**Fix the root cause, not the symptom:**1441451. **Create Failing Test Case**146 - Simplest possible reproduction147 - Automated test if possible148 - MUST have before fixing1491502. **Implement Single Fix**151 - Address the root cause identified152 - ONE change at a time153 - No "while I'm here" improvements154 - No bundled refactoring1551563. **Verify Fix**157 - Test passes now?158 - No other tests broken?159 - Issue actually resolved?1601614. **If Fix Doesn't Work**162 - STOP163 - Count: How many fixes have you tried?164 - If < 3: Return to Phase 1, re-analyze with new information165 - **If >= 3: STOP and question the architecture**166 - DON'T attempt Fix #4 without architectural discussion1671685. **If 3+ Fixes Failed: Question Architecture**169170 **Pattern indicating architectural problem:**171 - Each fix reveals new shared state/coupling/problem in different place172 - Fixes require "massive refactoring" to implement173 - Each fix creates new symptoms elsewhere174175 **STOP and question fundamentals:**176 - Is this pattern fundamentally sound?177 - Are we "sticking with it through sheer inertia"?178 - Should we refactor architecture vs. continue fixing symptoms?179180## Red Flags — STOP and Follow Process181182If you catch yourself thinking:183- "Quick fix for now, investigate later"184- "Just try changing X and see if it works"185- "Add multiple changes, run tests"186- "Skip the test, I'll manually verify"187- "It's probably X, let me fix that"188- "I don't fully understand but this might work"189- "Here are the main problems: [lists fixes without investigation]"190- **"One more fix attempt" (when already tried 2+)**191192**ALL of these mean: STOP. Return to Phase 1.**193194## Common Rationalizations195196| Excuse | Reality |197|--------|---------|198| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |199| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |200| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |201| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |202| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |203| "I see the problem, let me fix it" | Seeing symptoms != understanding root cause. |204| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |205206## Quick Reference207208| Phase | Key Activities | Success Criteria |209|-------|---------------|------------------|210| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |211| **2. Pattern** | Find working examples, compare | Identify differences |212| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |213| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |214215## Real-World Impact216217From debugging sessions:218- Systematic approach: 15-30 minutes to fix219- Random fixes approach: 2-3 hours of thrashing220- First-time fix rate: 95% vs 40%221- New bugs introduced: Near zero vs common