agentleFS
REPOZYREPOZY/superpowers-optimized/skills/systematic-debugging/SKILL.md

systematic-debugging

Skill146 starsChanged 7 months agoMITView on GitHub

Invoke BEFORE attempting any fix when a bug, test failure, error, warning, unexpected behavior, or performance regression appears. Enforces hypothesis-driven root cause analysis — no fix without evidence. Triggers on: error messages, stack traces, "it's broken", "not working", "bug", test failures, blank/white screens, "works locally but not in production", performance degradation, console warnings, "can't figure out why". Also routed by using-superpowers for debugging tasks.

190 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-code-review, chinese-commit-conventions and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • obraSkill

    diagnosing-superpowers

    Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

    Also in 20 projects that use this

  • mjunaidcaSkill

    building-chatgpt-apps

    Guides creation of ChatGPT Apps with interactive widgets using OpenAI Apps SDK and MCP servers. Use when building ChatGPT custom apps with visual UI components, embedded widgets, or rich interactive experiences. Covers widget architecture, MCP server setup with FastMCP, response metadata, and Developer Mode configuration. NOT when building standard MCP servers without widgets (use building-mcp-servers skill instead).

    Also in 4 projects that use this

  • mjunaidcaSkill

    building-chat-interfaces

    Build AI chat interfaces with custom backends, authentication, and context injection. Use when integrating chat UI with AI agents, adding auth to chat, injecting user/page context, or implementing httpOnly cookie proxies. Covers ChatKitServer, useChatKit, and MCP auth patterns. NOT when building simple chatbots without persistence or custom agent integration.

    Also in 4 projects that use this

  • +2 more from Leodorareluctant259
  • +5 more from mjunaidca

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 0 are common, 14 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 177 edited versions we read keep these.

  • 14

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do root-cause investigation before proposing fixes.

    line 14
  2. Very specific:

    If known-issues.md exists at the project root, search it for the error message, error code, or failing test name.

    line 25
  3. Distinctive:

    If a match is found, try the documented solution first.

    line 26
  4. Distinctive:

    If no match or the documented solution doesn't work, proceed to Phase 1.

    line 27
  5. Distinctive:

    Read the full error output — not just the last line.

    line 30
  6. Distinctive:

    Check recent changes — what changed since it last worked?

    line 39
  7. Very specific:

    If context-snapshot.json exists at the project root: read it.

    line 40
  8. Distinctive:

    Add instrumentation (logging, breakpoints) at component boundaries.

    line 42
  9. Distinctive:

    Multi-component systems: When the system has multiple components (CI → build → signing, API → service → database), add diagnostic logging …

    line 43
  10. Distinctive:

    Unanimous: test the majority hypothesis.

    line 87
  11. Distinctive:

    Run the smallest possible test/change to validate or disprove it.

    line 94
  12. Distinctive:

    If disproven, discard it entirely and form a new hypothesis.

    line 95
  13. Distinctive:

    Add a failing regression test that reproduces the bug first.

    line 99
  14. Distinctive:

    If 3 fix attempts fail, stop.

    line 118
  15. Distinctive:

    If you catch yourself doing any of these, restart from Phase 1:

    line 122
  16. Distinctive:

    After resolving a bug:

    line 139

“Common” is measured: kept by at least 6 in 10 of the 177 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Systematic Debugging

Do root-cause investigation before proposing fixes.

Iron Law

No fix without evidence for root cause.

This is non-negotiable. Every fix must trace back to a proven root cause. A fix applied without understanding why it works is not a fix — it is a mask.

Four Phases

Phase 0: Check Known Issues

  • If known-issues.md exists at the project root, search it for the error message, error code, or failing test name.
  • If a match is found, try the documented solution first. If it resolves the issue, stop — no further investigation needed.
  • If no match or the documented solution doesn't work, proceed to Phase 1.

Phase 1: Investigate

  • Read the full error output — not just the last line.
  • Reproduce the bug reliably. If you cannot reproduce, you cannot fix. For tests that fail only in certain orderings (test pollution), run bash find-polluter.sh <marker> <test-pattern> from this skill's directory to identify which test is corrupting shared state. Read its exit code — they are not interchangeable:

    ExitMeaning
    0Every matched test ran and none created the marker. A real clean result.
    1Polluter found; it is named in the output.
    2The pattern matched no test files. Nothing ran, so nothing was proven — fix the pattern and re-run. Never report this as clean.
    3The marker already existed before the run. Reset it first; no test can be blamed until you do.
  • Check recent changes — what changed since it last worked?
    • If context-snapshot.json exists at the project root: read it. The changed_files and recent_commits fields answer this immediately without additional git commands.
    • Otherwise: run git log --oneline -10 and git diff HEAD~1..HEAD --name-only.
  • Add instrumentation (logging, breakpoints) at component boundaries.
  • Multi-component systems: When the system has multiple components (CI → build → signing, API → service → database), add diagnostic logging at EACH component boundary before proposing fixes:
    For EACH component boundary:
      - Log what data enters the component
      - Log what data exits the component
      - Verify environment/config propagation
      - Check state at each layer
    
    Run once to gather evidence showing WHERE it breaks
    THEN analyze evidence to identify the failing component
    THEN investigate that specific component
    Example (multi-layer system):
    # Layer 1: Workflow
    echo "=== Secrets available in workflow: ==="
    echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
    
    # Layer 2: Build script
    echo "=== Env vars in build script: ==="
    env | grep IDENTITY || echo "IDENTITY not in environment"
    
    # Layer 3: Signing script
    echo "=== Keychain state: ==="
    security list-keychains
    security find-identity -v
    
    # Layer 4: Actual signing
    codesign --sign "$IDENTITY" --verbose=4 "$APP"
    This reveals which layer fails (e.g., secrets → workflow OK, workflow → build FAILS).
  • Trace data/control flow backward from the error to its source.

Phase 2: Compare Patterns

  • Find a known-good implementation in the repo that does something similar.
  • Compare: behavior, config, assumptions, environment.
  • List concrete differences — these are your investigation leads.

Phase 3: Hypothesize and Test

Self-Consistency Gate — Before committing to a hypothesis, apply multi-path reasoning (see self-consistency-reasoner):

  1. Make 3-5 attempts at the root cause, each from a different starting point: trace forward from inputs, backward from the error, from recent changes, from similar past bugs. Each attempt names the one cause it arrives at — you are not brainstorming alternatives, you are checking whether different routes converge.
  2. Group attempts that name the same cause, then take the majority. Report agreement as a count (e.g. 4/5):
    • Unanimous: test the majority hypothesis.
    • Majority (more than half, not all): test the majority hypothesis; name the minority one and test it next if the majority fails.
    • No majority (half or fewer): STOP. Do not pick a hypothesis. The bug is ambiguous or multi-causal. Gather more evidence (add logging, reproduce under different conditions) before choosing a direction.
  3. These attempts share your context and your blind spots, so agreement is weak evidence and disagreement is strong evidence. The smallest test below — not the vote — is what proves the hypothesis.

Then for the selected hypothesis:

  • State it clearly before testing it.
  • Run the smallest possible test/change to validate or disprove it.
  • If disproven, discard it entirely and form a new hypothesis.
  • Never stack guesses. One hypothesis at a time, tested in isolation.

Phase 4: Fix and Verify

  • Add a failing regression test that reproduces the bug first.
  • Apply one focused fix — never bundle multiple changes.
  • Re-run the tests that cover the fix and confirm the issue is resolved. Scope per verification-before-completion — a root cause that spanned subsystems earns the full suite; a one-module fix earns that module's suite.

Rationalization Table — Do Not Skip Investigation

TemptationWhy it fails
"I know what the bug is"You had a hypothesis, not proof. Test it.
"Quick fix, investigate later"Later never comes. The mask becomes permanent debt.
"It's obviously this one line"Obvious bugs get fixed in 5 minutes. If it were obvious, it would be fixed already.
"Let me try a few things"Shotgun debugging creates new bugs and wastes time.
"The error message tells me exactly what's wrong"Error messages describe symptoms, not causes.
"I'll just revert to a known-good state"Reverts don't teach you what broke or prevent recurrence.

Escalation Rule

If 3 fix attempts fail, stop. Do not attempt a fourth. Discuss architecture with the user before continuing. The bug may indicate a design flaw, not a code defect.

Red Flags

If you catch yourself doing any of these, restart from Phase 1:

  • "Quick fix now, investigate later"
  • Changing multiple things in one attempt
  • Proposing a fix without reproduction evidence
  • Claiming success without re-running verification
  • "It should work now" without running the test
  • Copy-pasting a fix from elsewhere without understanding why it works

Supporting References

  • root-cause-tracing.md — trace bugs backward through the call stack
  • defense-in-depth.md — validation at every data layer
  • condition-based-waiting.md — replace timeouts with condition polling

Post-Fix: Update Knowledge Base

After resolving a bug:

  1. Recurring error? (environment-dependent, configuration, platform-specific, external-state) → offer to add the error→solution mapping to known-issues.md using the format defined in error-recovery.
  2. Permanent constraint discovered? (API limitation, platform behavior, library quirk that will never change) → offer to add it to project-map.md Critical Constraints section via context-management. These are facts every future session needs, not just error→fix mappings.

Related Skills

  • self-consistency-reasoner — multi-path reasoning for root cause diagnosis
  • test-driven-development — write the regression test before the fix
  • verification-before-completion — prove the fix with fresh evidence
  • error-recovery — consult and update project-specific known issues

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.