Systematic Debugging
When This Skill Activates
- Any bug, error, test failure, or unexpected behavior encountered
- Error/exception/traceback/failure appearing in output
- Before proposing any fix -- must investigate root cause first
Natural Language Triggers
- "fix this bug", "why is this failing", "debug this", "it's broken", "something's wrong", "not working"
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):
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
Example (multi-layer system):
# Layer 1: Workflow
echo "=== Secrets available in workflow: ==="
echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
# Layer 2: Build script
echo "=== Env vars in build script: ==="
env | grep IDENTITY || echo "IDENTITY not in environment"
# Layer 3: Signing script
echo "=== Keychain state: ==="
security list-keychains
security find-identity -v
# Layer 4: Actual signing
codesign --sign "$IDENTITY" --verbose=4 "$APP"
This reveals: Which layer fails (secrets -> workflow ok, workflow -> build FAIL)
Trace Data Flow
WHEN error is deep in call stack:
Backward tracing technique:
- 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
- Use the
shipyard:shipyard-tdd skill 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.
Example: Systematic vs Random Debugging
Phase 1: Read error -- "UNIQUE constraint failed: users.email"
Phase 1: Reproduce -- POST /users with email "test@example.com" -- 500 every time
Phase 1: Check changes -- git log shows migration added unique constraint yesterday
Phase 2: Find working -- GET /users works fine; POST /users with new email works
Phase 2: Difference -- failing requests use emails already in database
Phase 3: Hypothesis -- "The endpoint doesn't check for existing email before INSERT"
Phase 3: Test -- Add SELECT before INSERT, confirm 409 Conflict returned
Phase 4: Write failing test for duplicate email, implement check, verify all tests pass
Result: 20 minutes, root cause found, proper fix with test.
- "Probably a database issue" -- restart database -- still fails
- "Maybe the ORM is stale" -- clear ORM cache -- still fails
- "Try adding error handling" -- wrap in try/except, return 500 -- now returns 500 with no info
- "Add more logging" -- still don't know why
- 2 hours later, read the actual error message: "UNIQUE constraint failed"
Result: 2 hours of thrashing, same fix needed.
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)
Your Human Partner's Signals You're Doing It Wrong
Watch for these redirections:
- "Is that not happening?" - You assumed without verifying
- "Will it show us...?" - You should have added evidence gathering
- "Stop guessing" - You're proposing fixes without understanding
- "Ultrathink this" - Question fundamentals, not just symptoms
- "We're stuck?" (frustrated) - Your approach isn't working
When you see these: 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. |
| "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 does not equal 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 |
When Process Reveals "No Root Cause"
If systematic investigation reveals issue is truly environmental, timing-dependent, or external:
- You've completed the process
- Document what you investigated
- Implement appropriate handling (retry, timeout, error message)
- Add monitoring/logging for future investigation
But: 95% of "no root cause" cases are incomplete investigation.
Related Skills
- shipyard:shipyard-tdd - For creating failing test case (Phase 4, Step 1)
- shipyard:shipyard-verification - Verify fix worked before claiming success
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
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: shipyard-debugging3description: Use when encountering any bug, test failure, unexpected behavior, or error message — before proposing any fixes. Also use when you see tracebacks, exceptions, "not working" complaints, build failures, performance problems, or integration issues. If you're tempted to "just try changing X and see if it works", this skill applies. Systematic root cause investigation always comes before fix attempts.4---56<!-- TOKEN BUDGET: 380 lines / ~1140 tokens -->78# Systematic Debugging910<activation>1112## When This Skill Activates1314- Any bug, error, test failure, or unexpected behavior encountered15- Error/exception/traceback/failure appearing in output16- Before proposing any fix -- must investigate root cause first1718## Natural Language Triggers19- "fix this bug", "why is this failing", "debug this", "it's broken", "something's wrong", "not working"2021</activation>2223## Overview2425Random fixes waste time and create new bugs. Quick patches mask underlying issues.2627**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.2829**Violating the letter of this process is violating the spirit of debugging.**3031## The Iron Law3233```34NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST35```3637If you haven't completed Phase 1, you cannot propose fixes.3839## When to Use4041Use for ANY technical issue:42- Test failures43- Bugs in production44- Unexpected behavior45- Performance problems46- Build failures47- Integration issues4849**Use this ESPECIALLY when:**50- Under time pressure (emergencies make guessing tempting)51- "Just one quick fix" seems obvious52- You've already tried multiple fixes53- Previous fix didn't work54- You don't fully understand the issue5556**Don't skip when:**57- Issue seems simple (simple bugs have root causes too)58- You're in a hurry (rushing guarantees rework)59- Manager wants it fixed NOW (systematic is faster than thrashing)6061<instructions>6263## The Four Phases6465You MUST complete each phase before proceeding to the next.6667### Phase 1: Root Cause Investigation6869**BEFORE attempting ANY fix:**70711. **Read Error Messages Carefully**72 - Don't skip past errors or warnings73 - They often contain the exact solution74 - Read stack traces completely75 - Note line numbers, file paths, error codes76772. **Reproduce Consistently**78 - Can you trigger it reliably?79 - What are the exact steps?80 - Does it happen every time?81 - If not reproducible -- gather more data, don't guess82833. **Check Recent Changes**84 - What changed that could cause this?85 - Git diff, recent commits86 - New dependencies, config changes87 - Environmental differences88894. **Gather Evidence in Multi-Component Systems**9091 **WHEN system has multiple components (CI -> build -> signing, API -> service -> database):**9293 **BEFORE proposing fixes, add diagnostic instrumentation:**94 ```95 For EACH component boundary:96 - Log what data enters component97 - Log what data exits component98 - Verify environment/config propagation99 - Check state at each layer100101 Run once to gather evidence showing WHERE it breaks102 THEN analyze evidence to identify failing component103 THEN investigate that specific component104 ```105106 **Example (multi-layer system):**107 ```bash108 # Layer 1: Workflow109 echo "=== Secrets available in workflow: ==="110 echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"111112 # Layer 2: Build script113 echo "=== Env vars in build script: ==="114 env | grep IDENTITY || echo "IDENTITY not in environment"115116 # Layer 3: Signing script117 echo "=== Keychain state: ==="118 security list-keychains119 security find-identity -v120121 # Layer 4: Actual signing122 codesign --sign "$IDENTITY" --verbose=4 "$APP"123 ```124125 **This reveals:** Which layer fails (secrets -> workflow ok, workflow -> build FAIL)1261275. **Trace Data Flow**128129 **WHEN error is deep in call stack:**130131 **Backward tracing technique:**132 - Where does bad value originate?133 - What called this with bad value?134 - Keep tracing up until you find the source135 - Fix at source, not at symptom136137### Phase 2: Pattern Analysis138139**Find the pattern before fixing:**1401411. **Find Working Examples**142 - Locate similar working code in same codebase143 - What works that's similar to what's broken?1441452. **Compare Against References**146 - If implementing pattern, read reference implementation COMPLETELY147 - Don't skim - read every line148 - Understand the pattern fully before applying1491503. **Identify Differences**151 - What's different between working and broken?152 - List every difference, however small153 - Don't assume "that can't matter"1541554. **Understand Dependencies**156 - What other components does this need?157 - What settings, config, environment?158 - What assumptions does it make?159160### Phase 3: Hypothesis and Testing161162**Scientific method:**1631641. **Form Single Hypothesis**165 - State clearly: "I think X is the root cause because Y"166 - Write it down167 - Be specific, not vague1681692. **Test Minimally**170 - Make the SMALLEST possible change to test hypothesis171 - One variable at a time172 - Don't fix multiple things at once1731743. **Verify Before Continuing**175 - Did it work? Yes -- Phase 4176 - Didn't work? Form NEW hypothesis177 - DON'T add more fixes on top1781794. **When You Don't Know**180 - Say "I don't understand X"181 - Don't pretend to know182 - Ask for help183 - Research more184185### Phase 4: Implementation186187**Fix the root cause, not the symptom:**1881891. **Create Failing Test Case**190 - Simplest possible reproduction191 - Automated test if possible192 - One-off test script if no framework193 - MUST have before fixing194 - Use the `shipyard:shipyard-tdd` skill for writing proper failing tests1951962. **Implement Single Fix**197 - Address the root cause identified198 - ONE change at a time199 - No "while I'm here" improvements200 - No bundled refactoring2012023. **Verify Fix**203 - Test passes now?204 - No other tests broken?205 - Issue actually resolved?2062074. **If Fix Doesn't Work**208 - STOP209 - Count: How many fixes have you tried?210 - If < 3: Return to Phase 1, re-analyze with new information211 - **If >= 3: STOP and question the architecture (step 5 below)**212 - DON'T attempt Fix #4 without architectural discussion2132145. **If 3+ Fixes Failed: Question Architecture**215216 **Pattern indicating architectural problem:**217 - Each fix reveals new shared state/coupling/problem in different place218 - Fixes require "massive refactoring" to implement219 - Each fix creates new symptoms elsewhere220221 **STOP and question fundamentals:**222 - Is this pattern fundamentally sound?223 - Are we "sticking with it through sheer inertia"?224 - Should we refactor architecture vs. continue fixing symptoms?225226 **Discuss with your human partner before attempting more fixes**227228 This is NOT a failed hypothesis - this is a wrong architecture.229230</instructions>231232<examples>233234## Example: Systematic vs Random Debugging235236<example type="good" title="Systematic root cause investigation">237**Bug:** API returns 500 on user creation238239Phase 1: Read error -- "UNIQUE constraint failed: users.email"240Phase 1: Reproduce -- POST /users with email "test@example.com" -- 500 every time241Phase 1: Check changes -- git log shows migration added unique constraint yesterday242Phase 2: Find working -- GET /users works fine; POST /users with new email works243Phase 2: Difference -- failing requests use emails already in database244Phase 3: Hypothesis -- "The endpoint doesn't check for existing email before INSERT"245Phase 3: Test -- Add SELECT before INSERT, confirm 409 Conflict returned246Phase 4: Write failing test for duplicate email, implement check, verify all tests pass247248Result: 20 minutes, root cause found, proper fix with test.249</example>250251<example type="bad" title="Random fix attempts">252**Bug:** API returns 500 on user creation2532541. "Probably a database issue" -- restart database -- still fails2552. "Maybe the ORM is stale" -- clear ORM cache -- still fails2563. "Try adding error handling" -- wrap in try/except, return 500 -- now returns 500 with no info2574. "Add more logging" -- still don't know why2585. 2 hours later, read the actual error message: "UNIQUE constraint failed"259260Result: 2 hours of thrashing, same fix needed.261</example>262263</examples>264265<rules>266267## Red Flags - STOP and Follow Process268269If you catch yourself thinking:270- "Quick fix for now, investigate later"271- "Just try changing X and see if it works"272- "Add multiple changes, run tests"273- "Skip the test, I'll manually verify"274- "It's probably X, let me fix that"275- "I don't fully understand but this might work"276- "Pattern says X but I'll adapt it differently"277- "Here are the main problems: [lists fixes without investigation]"278- Proposing solutions before tracing data flow279- **"One more fix attempt" (when already tried 2+)**280- **Each fix reveals new problem in different place**281282**ALL of these mean: STOP. Return to Phase 1.**283284**If 3+ fixes failed:** Question the architecture (see Phase 4.5)285286## Your Human Partner's Signals You're Doing It Wrong287288**Watch for these redirections:**289- "Is that not happening?" - You assumed without verifying290- "Will it show us...?" - You should have added evidence gathering291- "Stop guessing" - You're proposing fixes without understanding292- "Ultrathink this" - Question fundamentals, not just symptoms293- "We're stuck?" (frustrated) - Your approach isn't working294295**When you see these:** STOP. Return to Phase 1.296297## Common Rationalizations298299| Excuse | Reality |300|--------|---------|301| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |302| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |303| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |304| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |305| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |306| "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |307| "I see the problem, let me fix it" | Seeing symptoms does not equal understanding root cause. |308| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |309310</rules>311312## Quick Reference313314| Phase | Key Activities | Success Criteria |315|-------|---------------|------------------|316| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |317| **2. Pattern** | Find working examples, compare | Identify differences |318| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |319| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |320321## When Process Reveals "No Root Cause"322323If systematic investigation reveals issue is truly environmental, timing-dependent, or external:3243251. You've completed the process3262. Document what you investigated3273. Implement appropriate handling (retry, timeout, error message)3284. Add monitoring/logging for future investigation329330**But:** 95% of "no root cause" cases are incomplete investigation.331332## Related Skills333- **shipyard:shipyard-tdd** - For creating failing test case (Phase 4, Step 1)334- **shipyard:shipyard-verification** - Verify fix worked before claiming success335336## Real-World Impact337338From debugging sessions:339- Systematic approach: 15-30 minutes to fix340- Random fixes approach: 2-3 hours of thrashing341- First-time fix rate: 95% vs 40%342- New bugs introduced: Near zero vs common343344---345> Converted and distributed by [TomeVault](https://tomevault.io/claim/lgbarn) — claim your Tome and manage your conversions.346<!-- tomevault:4.0:skill_md:2026-04-11 -->