| name | systematic-debugging |
| description | Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes |
Related skills: Write a failing test for the bug with /skill:test-driven-development. Verify the fix with /skill:verification-before-completion.
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 workflow-monitor extension tracks your debugging: it detects fix-without-investigation and counts failed fix attempts, surfacing warnings in tool results. Use workflow_reference with debug topics for additional guidance.
If a tool result contains a ⚠️ workflow warning, stop immediately and address it before continuing.
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, 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)
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. Read stack traces completely. Note line numbers, file paths, error codes.
-
Reproduce Consistently — Can you trigger it reliably? What are the exact steps? If not reproducible → gather more data, don't guess.
-
Check Recent Changes — Git diff, recent commits, new dependencies, config changes, environmental differences.
-
Gather Evidence in Multi-Component Systems — For each component boundary: log what enters, what exits, verify config propagation. Run once to see WHERE it breaks, then investigate that component.
Example (multi-layer system):
echo "=== Secrets available: ==="
echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
echo "=== Env vars in build script: ==="
env | grep IDENTITY || echo "IDENTITY not in environment"
echo "=== Keychain state: ==="
security list-keychains
security find-identity -v
This reveals: Which layer fails (e.g., secrets → workflow ✓, workflow → build ✗)
-
Trace Data Flow — Where does the bad value originate? What called this with the bad value? Keep tracing up until you find the source. Fix at source, not at symptom. See root-cause-tracing.md for the complete technique.
Phase 2: Pattern Analysis
- Find Working Examples — Locate similar working code in same codebase.
- Compare Against References — Read reference implementation COMPLETELY. Don't skim.
- Identify Differences — List every difference, however small. Don't assume "that can't matter."
- Understand Dependencies — What components, settings, config, environment does this need?
Phase 3: Hypothesis and Testing
- Form Single Hypothesis — State clearly: "I think X is the root cause because Y." Be specific, not vague.
- Test Minimally — Make the SMALLEST possible change. One variable at a time. Don't fix multiple things at once.
- Verify Before Continuing — Did it work? Yes → Phase 4. No → Form NEW hypothesis. DON'T add more fixes on top.
Phase 4: Implementation
-
Create Failing Test Case — Use /skill:test-driven-development for writing proper failing tests. MUST have before fixing.
-
Implement Single Fix — ONE change at a time. No "while I'm here" improvements. No bundled refactoring.
-
Verify Fix — Test passes? No other tests broken? Issue actually resolved?
-
If Fix Doesn't Work:
- If < 3 attempts: Return to Phase 1, re-analyze with new information
- If ≥ 3 attempts: STOP (see below)
When 3+ Fixes Fail: Question Architecture
This is NOT a failed hypothesis — it's a wrong architecture.
Pattern indicating architectural problem:
- Each fix reveals new shared state/coupling in different places
- 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.
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 above).
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. |
When Process Reveals "No Root Cause"
If investigation reveals issue is truly environmental, timing-dependent, or external:
- 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.
Supporting Techniques
These techniques are part of systematic debugging and available in this directory:
root-cause-tracing.md — Trace bugs backward through call stack to find original trigger
defense-in-depth.md — Add validation at multiple layers after finding root cause
condition-based-waiting.md — Replace arbitrary timeouts with condition polling
Use workflow_reference for: debug-rationalizations, debug-tracing, debug-defense-in-depth, debug-condition-waiting