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 (rushing guarantees rework)
- Manager wants it fixed NOW (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 (CI → build → signing, API → service → database):
Context Management: Use Explore subagent to map component boundaries before instrumenting:
- Prevents main conversation pollution during investigation
- Produces clean summary of architecture for focused debugging
- Essential for large codebases with many layers
Parallel Investigation: For independent components, consider workflow:parallel-agents:
- Investigate multiple components simultaneously
- Converge findings to identify root cause
- Reduces total investigation time for complex systems
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
WHEN error is deep in call stack:
REQUIRED SUB-SKILL: Use debug:root-cause for backward tracing technique
Quick version:
- 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
- Understand the pattern fully before applying
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
- One-off test script if no framework
- MUST have before fixing
- REQUIRED SUB-SKILL: Use core:tdd for writing proper failing tests
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 (step 5 below)
- 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?
Discuss with your human partner before attempting more fixes
This is NOT a failed hypothesis - this is a wrong architecture.
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"
- "Pattern says X but I'll adapt it differently"
- "Here are the main problems: [lists fixes without investigation]"
- Proposing solutions before tracing data flow
- "One more fix attempt" (when already tried 2+)
- Each fix reveals new problem in different place
ALL of these mean: STOP. Return to Phase 1.
If 3+ fixes failed: Question the architecture (see Phase 4.5)
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. |
| "Reference too long, I'll adapt the pattern" |
Partial understanding guarantees bugs. Read it completely. |
| "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 |
Integration with Other Skills
This skill requires using:
- debug:root-cause - Use when error is deep in call stack (see Phase 1, Step 5)
- core:tdd - Use for creating failing test case (see Phase 4, Step 1)
Complementary skills:
- debug:defense-in-depth - Add validation at multiple layers after finding root cause
- testing:condition-wait - Replace arbitrary timeouts identified in Phase 2
- core:verification - Verify fix worked before claiming success
1---2name: systematic3description: Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes - four-phase framework (root cause investigation, pattern analysis, hypothesis testing, implementation) that ensures understanding before attempting solutions4---5
6# Systematic Debugging
7
8## Overview
9
10Random fixes waste time and create new bugs. Quick patches mask underlying issues.
11
12**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
13
14**Violating the letter of this process is violating the spirit of debugging.**
15
16## The Iron Law
17
18```
19NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
20```
21
22If you haven't completed Phase 1, you cannot propose fixes.
23
24## When to Use
25
26Use for ANY technical issue:
27
28- Test failures
29- Bugs in production
30- Unexpected behavior
31- Performance problems
32- Build failures
33- Integration issues
34
35**Use this ESPECIALLY when:**
36
37- Under time pressure (emergencies make guessing tempting)
38- "Just one quick fix" seems obvious
39- You've already tried multiple fixes
40- Previous fix didn't work
41- You don't fully understand the issue
42
43**Don't skip when:**
44
45- Issue seems simple (simple bugs have root causes too)
46- You're in a hurry (rushing guarantees rework)
47- Manager wants it fixed NOW (systematic is faster than thrashing)
48
49## The Four Phases
50
51You MUST complete each phase before proceeding to the next.
52
53### Phase 1: Root Cause Investigation
54
55**BEFORE attempting ANY fix:**
56
571. **Read Error Messages Carefully**
58 - Don't skip past errors or warnings
59 - They often contain the exact solution
60 - Read stack traces completely
61 - Note line numbers, file paths, error codes
62
632. **Reproduce Consistently**
64 - Can you trigger it reliably?
65 - What are the exact steps?
66 - Does it happen every time?
67 - If not reproducible → gather more data, don't guess
68
693. **Check Recent Changes**
70 - What changed that could cause this?
71 - Git diff, recent commits
72 - New dependencies, config changes
73 - Environmental differences
74
754. **Gather Evidence in Multi-Component Systems**
76
77 **WHEN system has multiple components (CI → build → signing, API → service → database):**
78
79 **Context Management:** Use Explore subagent to map component boundaries before instrumenting:
80 - Prevents main conversation pollution during investigation
81 - Produces clean summary of architecture for focused debugging
82 - Essential for large codebases with many layers
83
84 **Parallel Investigation:** For independent components, consider `workflow:parallel-agents`:
85 - Investigate multiple components simultaneously
86 - Converge findings to identify root cause
87 - Reduces total investigation time for complex systems
88
89 **BEFORE proposing fixes, add diagnostic instrumentation:**
90
91 ```
92 For EACH component boundary:
93 - Log what data enters component
94 - Log what data exits component
95 - Verify environment/config propagation
96 - Check state at each layer
97
98 Run once to gather evidence showing WHERE it breaks
99 THEN analyze evidence to identify failing component
100 THEN investigate that specific component
101 ```
102
1035. **Trace Data Flow**
104
105 **WHEN error is deep in call stack:**
106
107 **REQUIRED SUB-SKILL:** Use debug:root-cause for backward tracing technique
108
109 **Quick version:**
110 - Where does bad value originate?
111 - What called this with bad value?
112 - Keep tracing up until you find the source
113 - Fix at source, not at symptom
114
115### Phase 2: Pattern Analysis
116
117**Find the pattern before fixing:**
118
1191. **Find Working Examples**
120 - Locate similar working code in same codebase
121 - What works that's similar to what's broken?
122
1232. **Compare Against References**
124 - If implementing pattern, read reference implementation COMPLETELY
125 - Don't skim - read every line
126 - Understand the pattern fully before applying
127
1283. **Identify Differences**
129 - What's different between working and broken?
130 - List every difference, however small
131 - Don't assume "that can't matter"
132
1334. **Understand Dependencies**
134 - What other components does this need?
135 - What settings, config, environment?
136 - What assumptions does it make?
137
138### Phase 3: Hypothesis and Testing
139
140**Scientific method:**
141
1421. **Form Single Hypothesis**
143 - State clearly: "I think X is the root cause because Y"
144 - Write it down
145 - Be specific, not vague
146
1472. **Test Minimally**
148 - Make the SMALLEST possible change to test hypothesis
149 - One variable at a time
150 - Don't fix multiple things at once
151
1523. **Verify Before Continuing**
153 - Did it work? Yes → Phase 4
154 - Didn't work? Form NEW hypothesis
155 - DON'T add more fixes on top
156
1574. **When You Don't Know**
158 - Say "I don't understand X"
159 - Don't pretend to know
160 - Ask for help
161 - Research more
162
163### Phase 4: Implementation
164
165**Fix the root cause, not the symptom:**
166
1671. **Create Failing Test Case**
168 - Simplest possible reproduction
169 - Automated test if possible
170 - One-off test script if no framework
171 - MUST have before fixing
172 - **REQUIRED SUB-SKILL:** Use core:tdd for writing proper failing tests
173
1742. **Implement Single Fix**
175 - Address the root cause identified
176 - ONE change at a time
177 - No "while I'm here" improvements
178 - No bundled refactoring
179
1803. **Verify Fix**
181 - Test passes now?
182 - No other tests broken?
183 - Issue actually resolved?
184
1854. **If Fix Doesn't Work**
186 - STOP
187 - Count: How many fixes have you tried?
188 - If < 3: Return to Phase 1, re-analyze with new information
189 - **If ≥ 3: STOP and question the architecture (step 5 below)**
190 - DON'T attempt Fix #4 without architectural discussion
191
1925. **If 3+ Fixes Failed: Question Architecture**
193
194 **Pattern indicating architectural problem:**
195 - Each fix reveals new shared state/coupling/problem in different place
196 - Fixes require "massive refactoring" to implement
197 - Each fix creates new symptoms elsewhere
198
199 **STOP and question fundamentals:**
200 - Is this pattern fundamentally sound?
201 - Are we "sticking with it through sheer inertia"?
202 - Should we refactor architecture vs. continue fixing symptoms?
203
204 **Discuss with your human partner before attempting more fixes**
205
206 This is NOT a failed hypothesis - this is a wrong architecture.
207
208## Red Flags - STOP and Follow Process
209
210If you catch yourself thinking:
211
212- "Quick fix for now, investigate later"
213- "Just try changing X and see if it works"
214- "Add multiple changes, run tests"
215- "Skip the test, I'll manually verify"
216- "It's probably X, let me fix that"
217- "I don't fully understand but this might work"
218- "Pattern says X but I'll adapt it differently"
219- "Here are the main problems: [lists fixes without investigation]"
220- Proposing solutions before tracing data flow
221- **"One more fix attempt" (when already tried 2+)**
222- **Each fix reveals new problem in different place**
223
224**ALL of these mean: STOP. Return to Phase 1.**
225
226**If 3+ fixes failed:** Question the architecture (see Phase 4.5)
227
228## Common Rationalizations
229
230| Excuse | Reality |
231|--------|---------|
232| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
233| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
234| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
235| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
236| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
237| "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
238| "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
239| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |
240
241## Quick Reference
242
243| Phase | Key Activities | Success Criteria |
244|-------|---------------|------------------|
245| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
246| **2. Pattern** | Find working examples, compare | Identify differences |
247| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
248| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
249
250## Integration with Other Skills
251
252**This skill requires using:**
253
254- **debug:root-cause** - Use when error is deep in call stack (see Phase 1, Step 5)
255- **core:tdd** - Use for creating failing test case (see Phase 4, Step 1)
256
257**Complementary skills:**
258
259- **debug:defense-in-depth** - Add validation at multiple layers after finding root cause
260- **testing:condition-wait** - Replace arbitrary timeouts identified in Phase 2
261- **core:verification** - Verify fix worked before claiming success