Skip to main content

Systematic Debugging

Investigate any bug, test failure, or unexpected behavior using a root-cause-first methodology. Does not cover performance profiling, load testing, or monitoring setup. Produces a verified root cause diagnosis with a single targeted fix backed by a failing test.

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

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:

  1. Read Error Messages Carefully — Don't skip past errors. Read stack traces completely. Note line numbers, file paths, error codes.

  2. Reproduce Consistently — Can you trigger it reliably? What are the exact steps? If not reproducible, gather more data, don't guess.

  3. Check Recent Changes — Git diff, recent commits, new dependencies, config changes, environmental differences.

  4. Gather Evidence in Multi-Component Systems — For each component boundary: log what data enters, log what data exits, verify environment/config propagation, check state at each layer. Run once to gather evidence showing WHERE it breaks.

  5. Trace Data Flow — See references/root-cause-tracing.md for the complete backward tracing technique. Quick version: Where does bad value originate? What called this with bad value? Keep tracing up. Fix at source, not symptom.

Phase 2: Pattern Analysis

  1. Find Working Examples — Locate similar working code in same codebase
  2. Compare Against References — Read reference implementations COMPLETELY, don't skim
  3. Identify Differences — List every difference, however small
  4. Understand Dependencies — What components, settings, config, environment does this need?

Phase 3: Hypothesis and Testing

  1. Form Single Hypothesis — State clearly: "I think X is the root cause because Y"
  2. Test Minimally — SMALLEST possible change, one variable at a time
  3. Verify Before Continuing — Worked? Phase 4. Didn't work? NEW hypothesis. Don't stack fixes.
  4. When You Don't Know — Say so. Ask for help. Research more.

Phase 4: Implementation

  1. Create Failing Test Case — Use the test-driven-development skill
  2. Implement Single Fix — ONE change at a time, no "while I'm here" improvements
  3. Verify Fix — Test passes? No other tests broken? Issue resolved?
  4. If Fix Doesn't Work — Count attempts. If < 3: return to Phase 1. If >= 3: STOP and question the architecture.
  5. If 3+ Fixes Failed: Question Architecture — Is this pattern fundamentally sound? Are we stuck through inertia? Discuss with your human partner before 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"
  • "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]"
  • Proposing solutions before tracing data flow
  • "One more fix attempt" (when already tried 2+)

ALL of these mean: STOP. Return to Phase 1.

Your Human Partner's Signals You're Doing It Wrong

  • "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

When you see these: STOP. Return to Phase 1.

Reference: Read references/debugging-rationale.md for the Common Rationalizations table, Quick Reference summary, and Real-World Impact statistics.

When Process Reveals "No Root Cause"

If investigation reveals issue is truly environmental, timing-dependent, or external:

  1. You've completed the process
  2. Document what you investigated
  3. Implement appropriate handling (retry, timeout, error message)
  4. Add monitoring/logging for future investigation

But: 95% of "no root cause" cases are incomplete investigation.

Supporting Techniques

These techniques are available in the references/ directory:

  • references/root-cause-tracing.md — Trace bugs backward through call stack to find original trigger
  • references/defense-in-depth.md — Add validation at multiple layers after finding root cause
  • references/condition-based-waiting.md — Replace arbitrary timeouts with condition polling

Related skills:

  • test-driven-development — For creating failing test case (Phase 4, Step 1)
  • verification-before-completion — Verify fix worked before claiming success

Search Framework Explorer

Search agents, skills, and standards