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 actively tracks your debugging: it detects fix-without-investigation and counts failed fix attempts. Use
workflow_referencewith debug topics for detailed guidance.
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.
- •
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.mdfor 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-developmentfor 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.
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