agentleFS
wxxb789wxxb789/hoa/skills/systematic-debugging/SKILL.md

systematic-debugging

Skill3 starsChanged 53 days agoMITView on GitHub

Find a bug's root cause before changing code: build a tight red-capable feedback loop, gather evidence at component boundaries, rank falsifiable hypotheses, then fix once and prove it with a regression test. Use for any test failure, production bug, unexpected behavior, performance regression or build failure — especially under time pressure or after a fix that did not work. Not for exploratory "make it nicer" refactors, and not for a known mechanical change with an already-proven cause.

190 other projects use a version of this, 118 of them edited.

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

36 rules. 7 are common, 27 are distinctive, and 2 are very specific to this project.

  • 7

    Common

    Most of the 177 edited versions we read keep these.

  • 27

    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:

    Core principle: ALWAYS find root cause before attempting fixes.

    line 25
  2. Common:

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

    line 38
  3. Distinctive:

    When a clean repro is hard, spend disproportionate effort building the loop.

    line 47
  4. Distinctive:

    Use for ANY technical issue:

    line 52
  5. Common:

    Don't skip past errors or warnings

    line 87
  6. Common:

    Read stack traces completely

    line 89
  7. Distinctive:

    Action: Read the relevant source files at the named lines.

    line 92
  8. Common:

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

    line 101
  9. Distinctive:

    Property / fuzz loop: when the bug is intermittent wrong output over a broad input space.

    line 111
  10. Distinctive:

    Human-in-the-loop script: only as a last resort: script the human steps and capture their result so the loop stays structured.

    line 114
  11. Distinctive:

    Action: Run the tight loop from the shell:

    line 128
  12. Distinctive:

    Verify environment/config propagation

    line 170
  13. Distinctive:

    Check state at each layer

    line 171
  14. Distinctive:

    Run once to gather evidence showing WHERE it breaks.

    line 173
  15. Common:

    Keep tracing upstream until you find the source

    line 183
  16. Distinctive:

    Action: Search the codebase for the call sites and assignments:

    line 186
  17. Distinctive:

    STOP: Do not proceed to Phase 2 until you understand WHY it's happening.

    line 207
  18. Distinctive:

    Action: Search for the comparable pattern and read the working path end to end.

    line 229
  19. Distinctive:

    If implementing a pattern, read the reference implementation COMPLETELY

    line 233
  20. Distinctive:

    Don't skim — read every line

    line 234
  21. Distinctive:

    Don't assume "that can't matter"

    line 241
  22. Distinctive:

    If the user is present, show the ranked list before testing.

    line 263
  23. Distinctive:

    Test the highest-ranked hypothesis with the smallest possible probe.

    line 268
  24. Distinctive:

    Don't fix multiple things at once.

    line 270
  25. Distinctive:

    Prefer debugger/REPL inspection when available.

    line 271
  26. Very specific:

    If you add logs, tag every temporary line with a unique prefix such as [DEBUG-a4f2] so cleanup is a single search.

    line 272
  27. Distinctive:

    DON'T add more fixes on top

    line 279
  28. Distinctive:

    Don't pretend to know

    line 284
  29. Distinctive:

    Ask the user for help

    line 285
  30. Distinctive:

    MUST have before fixing

    line 298
  31. Distinctive:

    Follow the project's test-first rule.

    line 299
  32. Very specific:

    If fewer than ${DEBUG_MAX_FIXES:-3}: return to Phase 1, re-analyze with new information

    line 322
  33. Distinctive:

    DON'T attempt another fix without an architectural discussion

    line 324
  34. Distinctive:

    Should we refactor the architecture vs.

    line 338
  35. Common:

    If you catch yourself thinking:

    line 348
  36. Distinctive:

    Use the capability, not one product's wrapper name:

    line 391

“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

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.

Method adapted from the public superpowers debugging flow (MIT); the feedback-loop rule, ranked falsifiable hypotheses, and rule-of-three escalation were extended here.

The Iron Law

NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST

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

The Feedback Loop Rule

The feedback loop is the debugging work. Before reading code to build a theory, create or identify a tight command that can go red on the user's exact symptom and green when the bug is fixed. A tight loop is fast, deterministic, agent-runnable, and specific enough to catch this bug — not merely "doesn't crash".

When a clean repro is hard, spend disproportionate effort building the loop. Guessing without a red-capable loop is the failure mode this skill exists to prevent.

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
  • 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)
  • Someone wants it fixed NOW (systematic is faster than thrashing)

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 or warnings
  • They often contain the exact solution
  • Read stack traces completely
  • Note line numbers, file paths, error codes

Action: Read the relevant source files at the named lines. Search the codebase for the exact error string; it usually names the function or condition that produced it.

2. Build a Tight Feedback Loop

  • Can you trigger the user's exact symptom with one command?
  • Does the command fail for this bug and only pass once the bug is fixed?
  • Is it fast enough to run repeatedly?
  • Is it deterministic? For flaky bugs, can you raise the reproduction rate high enough to debug?
  • If not reproducible → gather more data, don't guess.

Ways to construct a loop — try in roughly this order:

  1. Failing test at the seam that reaches the bug: unit, integration, or end-to-end.
  2. HTTP script against a running dev server.
  3. CLI invocation with fixture input, diffing stdout/stderr against expected output.
  4. Headless browser script asserting on DOM, console, or network.
  5. Replay a captured trace: HAR, request payload, event log, queue message, or webhook body.
  6. Throwaway harness that boots the smallest useful slice of the system and calls the failing path.
  7. Property / fuzz loop when the bug is intermittent wrong output over a broad input space.
  8. Bisection harness suitable for git bisect run when the bug appeared between two known states.
  9. Differential loop comparing old vs new version, two configs, two providers, or two datasets.
  10. Human-in-the-loop script only as a last resort: script the human steps and capture their result so the loop stays structured.

Tighten the loop once it exists:

  • Make it faster: cache setup, narrow scope, skip unrelated initialization.
  • Make the signal sharper: assert the exact symptom, not generic success.
  • Make it more deterministic: pin time, seed randomness, isolate filesystem, freeze network.

For non-deterministic bugs, the immediate goal is a higher reproduction rate, not perfection. Run the trigger repeatedly (DEBUG_STRESS_RUNS, default 100), parallelize, add stress, narrow timing windows, or inject sleeps. A bug that reproduces at DEBUG_REPRO_FLOOR (default 0.5) is debuggable; below it, raise the rate first.

Action: Run the tight loop from the shell:

# Run a specific failing test
pytest tests/test_module.py::test_name -v

# Or run a scripted repro
python scripts/repro_bug.py

# Or run a high-repetition flaky repro
for i in $(seq 1 "${DEBUG_STRESS_RUNS:-100}"); do
  pytest tests/test_flake.py::test_name -q || break
done

3. Check Recent Changes

  • What changed that could cause this?
  • Diff, recent commits
  • New dependencies, config changes
# Recent commits
git log --oneline -10

# Uncommitted changes
git diff

# Changes in specific file
git log -p --follow src/problematic_file.py | head -100

4. Gather Evidence in Multi-Component Systems

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

BEFORE proposing fixes, add diagnostic instrumentation:

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.

5. Trace Data Flow

WHEN the error is deep in the call stack:

  • Where does the bad value originate?
  • What called this function with the bad value?
  • Keep tracing upstream until you find the source
  • Fix at the source, not at the symptom

Action: Search the codebase for the call sites and assignments:

# Find where the function is called
grep -rn 'function_name(' src/ --include='*.py'

# Find where the variable is set
grep -rnE 'variable_name[[:space:]]*=' src/ --include='*.py'

Phase 1 Completion Checklist

  • Error messages fully read and understood
  • A tight loop command exists and has been run at least once
  • Loop is red-capable: it asserts the user's exact symptom, not a nearby failure
  • Loop is deterministic, or a flaky bug has a high enough reproduction rate to debug
  • Recent changes identified and reviewed
  • Evidence gathered (logs, state, data flow)
  • Problem isolated to specific component/code
  • Root cause hypotheses can be stated and tested

STOP: Do not proceed to Phase 2 until you understand WHY it's happening.


Phase 2: Pattern Analysis

Find the pattern before fixing:

0. Minimize the Reproduction

Once the loop is red, shrink the repro to the smallest scenario that still goes red. Cut inputs, callers, config, data, and steps one at a time, re-running the loop after each cut. Keep only what is load-bearing for the failure.

Done when removing any remaining element makes the loop go green. A minimal repro narrows the hypothesis space and often becomes the cleanest regression test.

1. Find Working Examples

  • Locate similar working code in the same codebase
  • What works that's similar to what's broken?

Action: Search for the comparable pattern and read the working path end to end.

2. Compare Against References

  • If implementing a pattern, read the reference implementation COMPLETELY
  • Don't skim — read every line
  • Understand the pattern fully before applying

3. Identify Differences

  • What's different between working and broken?
  • List every difference, however small
  • Don't assume "that can't matter"

4. Understand Dependencies

  • What other components does this need?
  • What settings, config, environment?
  • What assumptions does it make?

Phase 3: Hypothesis and Testing

Scientific method:

1. Form Ranked Falsifiable Hypotheses

  • Generate 3–5 plausible hypotheses before testing any single one.
  • Rank them by likelihood and cheapness to falsify.
  • State the prediction each hypothesis makes: "If X is the cause, then changing or observing Y should make Z happen."
  • Discard or sharpen any hypothesis that does not make a testable prediction.

If the user is present, show the ranked list before testing. They may have domain knowledge that instantly re-ranks it. If the user is AFK, proceed with your ranking.

2. Test Minimally

  • Test the highest-ranked hypothesis with the smallest possible probe.
  • Change one variable at a time.
  • Don't fix multiple things at once.
  • Prefer debugger/REPL inspection when available; one breakpoint beats ten logs.
  • If you add logs, tag every temporary line with a unique prefix such as [DEBUG-a4f2] so cleanup is a single search.

3. Verify Before Continuing

  • Did it work? → 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
  • Ask the user for help
  • Research more

Phase 4: Implementation

Fix the root cause, not the symptom:

1. Create Failing Test Case

  • Simplest possible reproduction
  • Automated test if possible
  • MUST have before fixing
  • Follow the project's test-first rule; if it has none, add the regression test anyway

2. Implement Single Fix

  • Address the root cause identified
  • ONE change at a time
  • No "while I'm here" improvements
  • No bundled refactoring

3. Verify Fix

# Run the specific regression test
pytest tests/test_module.py::test_regression -v

# Run full suite — no regressions
pytest tests/ -q

4. If Fix Doesn't Work — The Rule of Three

  • STOP.
  • Count: How many fixes have you tried?
  • If fewer than ${DEBUG_MAX_FIXES:-3}: return to Phase 1, re-analyze with new information
  • If at or above the limit: STOP and question the architecture (step 5 below)
  • DON'T attempt another fix without an architectural discussion

5. If 3+ Fixes Failed: Question Architecture

Pattern indicating an 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 "sticking with it through sheer inertia"?
  • Should we refactor the architecture vs. continue fixing symptoms?

Discuss with the user before attempting more fixes.

This is NOT a failed hypothesis — this is a wrong architecture.


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"
  • "Skip the test, I'll manually verify"
  • "It's probably X, let me fix that"
  • "I don't fully understand but this might work"
  • "Pattern says X but I'll adapt it differently"
  • "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 a new problem in a different place

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

If fix attempts reached the limit (DEBUG_MAX_FIXES, default 3): Question the architecture (Phase 4 step 5).

Common Rationalizations

ExcuseReality
"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 the pattern, don't fix again.

Quick Reference

PhaseKey ActivitiesSuccess Criteria
1. Root CauseRead errors, reproduce, check changes, gather evidence, trace data flowUnderstand WHAT and WHY
2. PatternFind working examples, compare, identify differencesKnow what's different
3. HypothesisForm theory, test minimally, one variable at a timeConfirmed or new hypothesis
4. ImplementationCreate regression test, fix root cause, verifyBug resolved, all tests pass

Harness integration

Use the capability, not one product's wrapper name:

NeedCapability
Read source with line numbersfile-read tool
Find an error string, call site, or patterncodebase search, or grep -rn
Run tests, inspect history, reproduceshell
Research an unfamiliar error or libraryweb search / documentation fetch
Investigate a large multi-component failure in paralleldispatch a read-only investigation subagent; it must report findings and NOT fix

For complex multi-component debugging, the investigation brief is fixed:

Follow systematic-debugging:
1. Read the error message carefully
2. Reproduce the issue with a tight loop
3. Trace the data flow to find root cause
4. Report findings — do NOT fix yet

Error: <paste full error>
File: <path to failing code>
Test command: <exact command>

Configuration

KeyEnvDefault
max_fixesDEBUG_MAX_FIXES3 — the rule-of-three trigger
stress_runsDEBUG_STRESS_RUNS100 — repetitions for a flaky repro
repro_floorDEBUG_REPRO_FLOOR0.5 — reproduction rate worth debugging
log_tag_prefixDEBUG_LOG_TAG_PREFIX[DEBUG- — unique tag for temporary logs

Resolution order and the config-file path are defined once in skill-porting-and-publishing § Configuration; this skill does not restate them. Commands above show the env form with the default inline, so a reader can run them without the config.

No shortcuts. No guessing. Systematic always wins.

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.