agentleFS
jacksonwilliamsvajacksonwilliamsva/kiro-skills-library/skills/systematic-debugging/SKILL.md

systematic-debugging

Skill2 starsChanged 7 months agoMITView on GitHub

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

191 other projects use a version of this, 123 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-git-workflow, chinese-code-review 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-git-workflow

    适配国内 Git 平台和团队习惯的工作流规范——Gitee、Coding、极狐 GitLab 全覆盖

    Also in 9 projects that use this

  • Leodorareluctant259Skill

    chinese-code-review

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

    Also in 8 projects that use this

  • SethGammonSkill

    ascii-diagram

    Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.

    Also in 4 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

25 rules. 3 are common, 20 are distinctive, and 2 are very specific to this project.

  • 3

    Common

    Most of the 178 edited versions we read keep these.

  • 20

    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. Common:

    If you haven't completed Phase 1, you cannot propose fixes.

    line 14
  2. Distinctive:

    Use for ANY technical issue: test failures, bugs, unexpected behavior, performance problems, build failures, integration issues.

    line 18
  3. Distinctive:

    Before investigating ANYTHING, build a fast, deterministic reproduction loop.

    line 37
  4. Distinctive:

    Hard gate: Do NOT proceed to Phase 1 until you have a loop you believe in.

    line 50
  5. Distinctive:

    If you genuinely cannot build a loop: Stop and say so. List what you tried.

    line 52
  6. Distinctive:

    Don't skip past errors or warnings

    line 59
  7. Distinctive:

    Read stack traces completely — they often contain the exact solution

    line 60
  8. Common:

    If not reproducible → gather more data, don't guess

    line 66
  9. Distinctive:

    Add diagnostic instrumentation BEFORE proposing fixes:

    line 77
  10. Distinctive:

    Don't fix multiple things at once

    line 129
  11. Distinctive:

    DON'T add more fixes on top

    line 134
  12. Distinctive:

    Don't pretend to know

    line 138
  13. Distinctive:

    MUST have before fixing

    line 146
  14. Very specific:

    Use superpowers:test-driven-development for writing proper failing tests

    line 147
  15. Distinctive:

    Test passes now? No other tests broken?

    line 155
  16. Very specific:

    Remove all [DEBUG-...] instrumentation (grep the tag prefix — designed for easy cleanup)

    line 159
  17. Distinctive:

    Ask: what would have prevented this bug?

    line 160
  18. Distinctive:

    If < 3 attempts: Return to Phase 1, re-analyze with new information

    line 163
  19. Distinctive:

    DON'T attempt Fix #4 without architectural discussion

    line 165
  20. Distinctive:

    Should we refactor architecture vs.

    line 177
  21. Common:

    If you catch yourself thinking:

    line 183
  22. Distinctive:

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

    line 204
  23. Distinctive:

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

    line 236
  24. Distinctive:

    Document what you investigated

    line 238
  25. Distinctive:

    Add monitoring/logging for future investigation

    line 240

“Common” is measured: kept by at least 6 in 10 of the 178 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

The Iron Law

NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST

If you haven't completed Phase 1, you cannot propose fixes. Symptom fixes are failure.

When to Use

Use for ANY technical issue: test failures, bugs, unexpected behavior, performance problems, build failures, integration issues.

Use ESPECIALLY when:

  • Under time pressure (emergencies make guessing tempting)
  • "Just one quick fix" seems obvious
  • You've already tried multiple fixes without success
  • 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)
  • Manager wants it fixed NOW (systematic is faster than thrashing)

The Five Phases

Complete each phase before proceeding to the next.

Phase 0: Build a Feedback Loop

Before investigating ANYTHING, build a fast, deterministic reproduction loop.

Priority order:

  1. Existing test that fails
  2. New test you write
  3. Standalone script
  4. REPL session
  5. HITL (human-in-the-loop) bash script — see hitl-loop.template.sh

Treat the loop as a product:

  • Can I make it faster? Sharper signal? More deterministic?
  • A 30-second flaky loop is barely better than no loop. A 2-second deterministic loop is a debugging superpower.

Hard gate: Do NOT proceed to Phase 1 until you have a loop you believe in.

If you genuinely cannot build a loop: Stop and say so. List what you tried. Ask the user for: (a) access to the reproducing environment, (b) a captured artifact (HAR file, log dump, core dump, screen recording), or (c) permission to add temporary instrumentation.

Phase 1: Root Cause Investigation

BEFORE attempting ANY fix:

  1. Read Error Messages Carefully
    • Don't skip past errors or warnings
    • Read stack traces completely — they often contain the exact solution
    • Note line numbers, file paths, error codes
  2. Reproduce Consistently
    • Can you trigger it reliably? What are the exact steps?
    • Does it happen every time?
    • If not reproducible → gather more data, don't guess
  3. Check Recent Changes
    • What changed that could cause this?
    • Git diff, recent commits, new dependencies, config changes
    • Environmental differences
  4. Gather Evidence in Multi-Component Systems

    WHEN system has multiple components (CI → build → signing, API → service → database):

    Add diagnostic instrumentation BEFORE proposing fixes:

    For EACH component boundary:
      - Log what data enters/exits the component
      - Verify environment/config propagation
      - Check state at each layer
    
    Run once → analyze evidence → identify failing component → investigate that component

    Example (multi-layer system):

    # Layer 1: Workflow
    echo "=== Secrets available: ==="
    echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
    
    # Layer 2: Build script
    env | grep IDENTITY || echo "IDENTITY not in environment"
    
    # Layer 3: Signing
    security find-identity -v
    
    # Layer 4: Actual operation
    codesign --sign "$IDENTITY" --verbose=4 "$APP"

    Reveals: Which layer fails (secrets → workflow ✓, workflow → build ✗)

    Tag every debug log with a unique prefix, e.g. [DEBUG-a4f2]. Cleanup becomes a single grep. Untagged logs survive; tagged logs die.

  5. Trace Data Flow

    See root-cause-tracing.md for the complete backward tracing technique.

    Quick version: Where does the bad value originate? Trace callers upward until you find the source. Fix at source, not at symptom.

Phase 2: Pattern Analysis

  1. Find Working Examples — Locate similar working code in the same codebase
  2. Compare Against References — Read reference implementations COMPLETELY, don't skim. Understand the pattern fully before applying.
  3. Identify Differences — List every difference between working and broken, however small. Don't assume "that can't matter."
  4. Understand Dependencies — What components, settings, config, environment, assumptions does this need?

Phase 3: Hypothesis and Testing

  1. Form Single Hypothesis
    • State clearly: "I think X is the root cause because Y"
    • Be specific, not vague
  2. Test Minimally
    • Make the SMALLEST possible change to test hypothesis
    • One variable at a time
    • Don't fix multiple things at once
  3. Verify Before Continuing
    • Did it work? Yes → Phase 4
    • Didn't work? Form NEW hypothesis
    • DON'T add more fixes on top
  4. When You Don't Know
    • Say "I don't understand X"
    • Don't pretend to know
    • Research more or ask for help

Phase 4: Implementation

  1. Create Failing Test Case
    • Simplest possible reproduction
    • Automated test if possible, one-off script if no framework
    • MUST have before fixing
    • Use superpowers:test-driven-development for writing proper failing tests
  2. Implement Single Fix
    • Address the root cause identified
    • ONE change at a time
    • No "while I'm here" improvements or bundled refactoring
  3. Verify Fix
    • Test passes now? No other tests broken? Issue actually resolved?
  4. Post-mortem: What would have prevented this?
    • State the correct hypothesis in the commit/PR message so the next debugger learns
    • Remove all [DEBUG-...] instrumentation (grep the tag prefix — designed for easy cleanup)
    • Ask: what would have prevented this bug? If the answer involves architectural change, note it but don't act on it now
  5. If Fix Doesn't Work
    • If < 3 attempts: Return to Phase 1, re-analyze with new information
    • If ≥ 3 attempts: STOP and question the architecture (step 6)
    • DON'T attempt Fix #4 without architectural discussion
  6. If 3+ Fixes Failed: Question Architecture

    Pattern indicating architectural problem:

    • Each fix reveals new shared state/coupling in a different place
    • Fixes require massive refactoring to implement
    • Each fix creates new symptoms elsewhere

    STOP and question fundamentals:

    • Is this pattern fundamentally sound?
    • Are we persisting through sheer inertia?
    • Should we refactor architecture vs. continue fixing symptoms?

    Discuss with your human partner before attempting more fixes. This is a wrong architecture, not a failed hypothesis.

Red Flags — STOP and Return to Phase 1

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"
  • "Skip the test, I'll manually verify"
  • "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+)
  • Each fix reveals new problem in different place

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

Human Partner 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.

Anti-Rationalization Table

RationalizationReality
"Issue is simple, don't need process"Simple issues have root causes too. Process is fast for simple bugs.
"Emergency, no time for process"Systematic debugging is FASTER than guess-and-check thrashing.
"Just try this first, then investigate"First fix sets the pattern. Do it right from the start.
"I'll write test after confirming fix works"Untested fixes don't stick. Test first proves it.
"Multiple fixes at once saves time"Can't isolate what worked. Causes new bugs.
"Reference too long, I'll adapt the pattern"Partial understanding guarantees bugs. Read it completely.
"I see the problem, let me fix it"Seeing symptoms ≠ understanding root cause.
"One more fix attempt" (after 2+ failures)3+ failures = architectural problem. Question pattern, don't fix again.
"I think I know what's wrong"Thinking is not evidence. Reproduce it first.
"The error message tells me exactly what's wrong"Error messages describe symptoms, not root causes.
"I'll add logging everywhere"Targeted logging from a hypothesis beats shotgun logging.
"It works on my machine"Environment differences ARE the bug. Reproduce in the failing environment.
"It's probably a flaky test"Flaky tests mask real bugs. Prove it's flaky before dismissing.

Quick Reference

PhaseKey ActivitiesSuccess Criteria
0. Feedback LoopBuild fast repro loopDeterministic, fast reproduction
1. Root CauseRead errors, reproduce, check changes, gather evidenceUnderstand WHAT and WHY
2. PatternFind working examples, compareIdentify differences
3. HypothesisForm theory, test minimallyConfirmed or new hypothesis
4. ImplementationCreate test, fix, verify, post-mortemBug resolved, tests pass

When Process Reveals "No Root Cause"

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

  1. Document what you investigated
  2. Implement appropriate handling (retry, timeout, error message)
  3. Add monitoring/logging for future investigation

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

Supporting Techniques

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

Related skills:

  • superpowers:test-driven-development — Creating failing test case (Phase 4)
  • superpowers:verification-before-completion — Verify fix before claiming success

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.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

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.