agentleFS
milad-raeisimilad-raeisi/senior-skills/skills/systematic-debugging/SKILL.md

systematic-debugging

Skill4 starsChanged 15 days agoMITView on GitHub

Root-cause-first debugging. Use for any bug, failing or flaky test, crash, exception, wrong output, hang, memory leak, performance regression, or "works on my machine" problem, before proposing any fix, and especially after a first fix attempt didn't work. Replaces guess-and-patch with reproduce, isolate, hypothesize, test, fix at the root, and lock it in with a regression test.

191 other projects use a version of this.

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

We split this skill into the rules it gives an agent

9 rules. 0 are common, 7 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 178 edited versions we read keep these.

  • 7

    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:

    Rule: no fix without (1) a reproduction and (2) a root cause you can explain, including why the code behaves this way and not just where it …

    line 14
  2. Distinctive:

    Read the entire error: message, stack trace, logs before the failure, exit code.

    line 18
  3. Distinctive:

    If it doesn't reproduce: compare environments (versions, config, env vars, data, OS, time zone, locale, concurrency).

    line 20
  4. Distinctive:

    Minimize the input: Remove half the data, config, or steps.

    line 28
  5. Distinctive:

    Binary-search the code path: Add assertions or logs at the midpoint between "input is right" and "output is wrong".

    line 29
  6. Distinctive:

    Keep a short hypothesis log.

    line 35
  7. Very specific:

    Write a failing test that reproduces the bug first (see test-driven-development).

    line 46
  8. Very specific:

    Search for siblings: the same mistake often exists in other places (rg for the pattern).

    line 48
  9. Distinctive:

    Run the new test (it passes), then the full relevant suite (nothing else broke).

    line 49

“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 fastest way to fix a bug is to stop guessing. Each guess-and-patch cycle feels quick but leaves the real cause in place, adds code that hides symptoms, and teaches you nothing. A root cause you can state in one sentence, backed by a reproduction, is the only finish line.

Rule: no fix without (1) a reproduction and (2) a root cause you can explain, including why the code behaves this way and not just where it breaks.

Phase 1: Reproduce

  • Read the entire error: message, stack trace, logs before the failure, exit code. The answer is often in the line people skip.
  • Get a reliable reproduction, ideally a single command or a failing test. Note the exact inputs, environment, versions, and steps.
  • If it doesn't reproduce: compare environments (versions, config, env vars, data, OS, time zone, locale, concurrency). The difference is the clue.
  • For flaky failures, loop it (for i in $(seq 50); do <cmd> || break; done), fix random seeds, and vary timing or parallelism to make it deterministic.

Phase 2: Isolate

Shrink the search space until the cause has nowhere to hide:

  • What changed? git log -p --since=... on the affected files. When there's a known-good commit, bisect: git bisect start <bad> <good>, then git bisect run <test-cmd>, and git bisect reset when done so the repo returns to your branch. Bisect turns hours of reasoning into minutes of mechanical search.
  • Minimize the input. Remove half the data, config, or steps; keep the half that still fails.
  • Binary-search the code path. Add assertions or logs at the midpoint between "input is right" and "output is wrong".
  • Compare working and broken. A similar case that works is a gift: diff the two paths.
  • Check assumptions explicitly. Print the actual values, types, versions, and paths instead of believing what they should be.

Phase 3: Hypothesize and test

Keep a short hypothesis log; it stops you from circling:

H1: cache returns stale user after update -> predict: bypassing cache fixes it -> result: still fails -> rejected
H2: update writes to primary, read hits a lagging replica -> predict: reading from primary fixes it -> result: confirmed by query log

Change one variable at a time. Prefer experiments that can falsify the hypothesis. A hypothesis that can't fail tells you nothing.

Phase 4: Fix at the root

  • Write a failing test that reproduces the bug first (see test-driven-development). It must fail for the right reason.
  • Fix the cause, not the symptom. A try/catch, null check, retry, or sleep that makes the symptom disappear is a patch over a cause you haven't found; use one only if you can explain why it's the correct behavior.
  • Search for siblings: the same mistake often exists in other places (rg for the pattern).
  • Run the new test (it passes), then the full relevant suite (nothing else broke).

The three-strikes rule

If three fix attempts have failed, stop patching. Three misses mean your model of the system is wrong. Go back to Phase 1 with fresh eyes: re-read the error, question the assumption you've been most sure about, and consider whether the design itself is the problem. Report this honestly rather than trying a fourth variation.

Debugging report

**Symptom:** what the user saw.
**Root cause:** one or two sentences: what was wrong and why it produced the symptom.
**Evidence:** the reproduction, and the observation that confirmed the cause.
**Fix:** what changed and why it addresses the cause.
**Verified:** regression test (fails before, passes after) and full suite result.
**Related risks:** similar code checked, or worth checking.

Anti-patterns

Tempting moveWhat to do instead
"Let me try changing X and see"Form a hypothesis that predicts the outcome first
Fixing the first suspicious thing you seeConfirm it's the cause with an experiment
Adding retries or sleeps to make a flaky test passFind the race or ordering dependency
Catching and logging the exceptionFind why it's thrown
Several changes at onceOne variable per experiment
"Fixed" without re-running the reproductionRe-run it; see evidence-before-claims

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.