| name | systematic-debugging |
| description | Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes |
Systematic Debugging
Core Principles
- Iron Law: NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST. Proposing fixes before completing Phase 1 is prohibited.
- Core Principle: Always find the root cause. Symptom fixes are failures.
- When to Use: Mandatory for all technical issues (test failures, production bugs, build/integration errors), especially under time pressure or after previous fix attempts failed.
Process: The Four Phases
Phase 1: Root Cause Investigation
- Read Errors Carefully: Examine complete stack traces, line numbers, file paths, and error codes.
- Reproduce Consistently: Establish reliable trigger steps. Gather data if non-reproducible; do not guess.
- Check Recent Changes: Analyze
git diff, recent commits, dependencies, configurations, and environment differences.
- Multi-Component Instrumentation:
- Trace Data Flow: Trace backward from error site to data origin. Fix at source, not symptom (see
root-cause-tracing.md).
Feedback Loop Construction Strategies
Construct a deterministic, high-efficiency feedback loop using one of these 10 strategies:
- CLI Snapshot: Capture and compare CLI outputs across runs for instant diffing.
- Playwright E2E: Automate browser interactions and UI assertions to reproduce frontend states.
- Captured Trace Replay: Replay recorded network traffic or execution traces to reproduce exact runtime contexts.
- Differential Loops: Run failing and working implementations side-by-side to pinpoint divergence.
- Log Tailing: Stream filtered log channels in real-time to observe dynamic event flows.
- Unit/Integration Isolation: Extract the failing subsystem into a standalone, minimal test harness free of external dependencies.
- State Dumpers: Serialize in-memory data structures to disk at key milestones for offline analysis.
- Mock Servers: Replace flaky or slow third-party services with deterministic stubs.
- Benchmark Loops: Execute high-frequency profiling loops to expose performance bottlenecks and memory leaks under load.
- Smoke Test Scripts: Author lightweight, single-command shell scripts executing the precise reproduction path.
Loop Tightening Rules
- Sub-2-Second Feedback Goal: Optimize test harnesses to complete iterations in under 2 seconds (
<2s).
- Non-Deterministic Repro Stress Testing: For flaky or intermittent bugs, run the reproduction script repeatedly (100+ executions) to force consistent reproduction and verify fix reliability.
Phase 2: Pattern Analysis
- Find Working Examples: Locate similar, functioning code in the repository.
- Read References Fully: Read reference implementations line-by-line; do not skim.
- Compare Differences: Document every discrepancy (configurations, environment, inputs) between working and broken states.
- Analyze Dependencies: Identify environmental and configuration assumptions.
Phase 3: Hypothesis and Testing
- Multi-Hypothesis Ranking Mandate: Generate 3 to 5 distinct, falsifiable hypotheses ("X causes Y because of Z") before testing any changes.
- Rank Hypotheses: Order by probability and verification cost (effort/time). Document the list clearly.
- Test Minimally in Ranked Order: Test the highest-ranked hypothesis using the smallest isolated change. Change one variable at a time.
- Verify/Reset: If successful, proceed to Phase 4. If failed, revert changes completely, eliminate the hypothesis, move to the next ranked hypothesis, and repeat. Do not accumulate speculative fixes.
- Acknowledge Ignorance: Explicitly state unknown factors; research or ask for help rather than guessing.
Phase 4: Implementation
- Failing Test Case: Write an automated, minimal reproduction test (see
superpowers:test-driven-development).
- Single Fix: Resolve root cause with one focused change. Avoid bundled refactoring or unrelated edits.
- Verify: Confirm the fix passes and regressions are zero (see
superpowers:verification-before-completion).
- Failure Threshold (3-Fix Limit):
- < 3 fixes failed: Revert, return to Phase 1, and re-analyze.
- ≥ 3 fixes failed: STOP immediately. Do not attempt fix #4. Proceed to step 5.
- Architectural Analysis: If 3+ fixes fail, the issue is architectural rather than local.
- Indicators: Fixes reveal coupling, require massive refactoring, or cause regressions elsewhere.
- Action: Halt, re-evaluate pattern soundness, and consult with your human partner before writing more code.
Diagnostics & Red Flags
Red Flags: STOP and Return to Phase 1
- Thinking: "Let's change X and see if it works."
- Proposing solutions before tracing data flow or collecting logs.
- Bundling multiple experimental changes or skipping test validation.
- Attempting a 4th fix without architectural discussion.
Human Partner Redirection Signals
- "Is that not happening?" (Assumed without verifying)
- "Will it show us...?" (Missing instrumentation/evidence)
- "Stop guessing" (Proposing fixes without tracing)
- "Ultrathink this" (Symptom-fixing instead of structural review)
Common Rationalizations
| Excuse | Reality |
|---|
| "Issue is too simple/urgent for process" | Process is faster than guess-and-check thrashing. |
| "I'll write tests after fixing" | Untested fixes fail. Test-first prevents regression and confirms the fix. |
| "Multiple changes save time" | Loses variable isolation and introduces new bugs. |
| "One more fix attempt" (after 2 failures) | 3+ failures indicate architectural issues, not a missing tweak. |
Environmental / Non-Reproducible Issues
If the issue is purely external or timing-dependent:
- Document the complete scope of the investigation.
- Implement robust handling (retry policies, timeouts, fallback error states).
- Inject monitoring and logging for future forensics.
Reference Map
root-cause-tracing.md: Backward tracing through execution stack.
defense-in-depth.md: Multi-layer validation after root cause identification.
condition-based-waiting.md: Eliminating arbitrary delays with condition polling.