Systematic debugging

From SethGammon/Citadel · View interactive version

Systematic debugging is an AI agent skill from the GitHub repository SethGammon/Citadel. 4-phase root cause analysis: observe, hypothesize, verify, fix. Enforces investigation before any code changes. Emergency stop after 2 failed fixes. Prevents shotgun debugging and fix cascades.

How to use this skill

Skill file

/systematic-debugging — Root Cause Before Fix

Orientation

Use when: root cause is unknown and premature fixes keep failing -- enforces observe -> hypothesize -> verify before touching code.

Don't use when: root cause is already known (use /marshal to implement the fix); the bug is shallow and the stack trace is enough (use /do).

Protocol

Phase 1: OBSERVATION & REPRODUCTION

  1. Read the error message, stack trace, or bug description
  2. Reproduce the issue:
  1. Isolate the failing component/function:

Output: A clear problem statement:

"{Component} does {X} when it should do {Y}, triggered by {condition}"

Phase 2: HYPOTHESIS & VERIFICATION

  1. Formulate up to 3 hypotheses for WHY the bug exists:
  1. For each hypothesis, define a verification step:
  1. Run the verification:

CRITICAL: Do not skip this phase. Do not "just try" a fix. Verify first.

Phase 3: ROOT CAUSE ANALYSIS

Once a hypothesis is confirmed:

  1. Explain WHY the bug happens, not just WHERE:

"A calls B with X, B assumes X > 0, but A passes -1 when {condition}"

  1. Check for related occurrences:

Output: Root cause statement:

"The bug occurs because {cause}. This happens when {trigger}."

Phase 4: IMPLEMENTATION

  1. Write a failing test case that reproduces the bug (if test framework exists)
  2. Apply the minimal fix — change only what's necessary to resolve the root cause
  3. Verify the fix:
  1. If the root cause analysis revealed related occurrences, fix those too

Emergency Stop Rule

If a fix fails TWICE: STOP.

Do not try a third guess. The root cause analysis was wrong. Either:

Three failed fixes in a row means you're guessing, not debugging.

What This Skill Prevents

Contextual Gates

Disclosure: "Debugging [symptom]. Phases 1-3 read-only; will confirm before applying fixes in Phase 4."

Reversibility: amber — Phase 4 applies targeted fixes to source files; undo with git checkout on modified files. Phases 1-3 are read-only.

Trust gates:

Quality Gates

Fringe Cases

Bug is intermittent: Document the triggering conditions as precisely as possible. Reproduce it at least once before forming hypotheses. If it can't be reproduced, stop at Phase 1 and ask for more context.

Two fix attempts have already failed: Invoke the Emergency Stop Rule. Return to Phase 2 with new hypotheses. Do not try a third guess without re-reading the relevant code.

No test framework exists: Skip the "write a failing test" step in Phase 4. Verify the fix manually and document how to reproduce the original bug for future reference.

Error is in a dependency or generated file: Document the root cause but do not modify the dependency. Propose a workaround in the consuming code instead.

Exit Protocol

---HANDOFF---
- Bug: {problem statement}
- Root cause: {one-line cause}
- Fix: {what was changed}
- Verified: {typecheck + tests passing}
- Related: {any similar patterns found and fixed}
---
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.