agentleFS
yaohuangguanyaohuangguan/agent-playbook/skills/debug-failure/SKILL.md

debug-failure

Skill1 starsChanged 2 days agoMITView on GitHub

Find the root cause of an error, crash, failing test, regression or wrong behaviour, then fix it with a regression test. Use this whenever something is broken or behaves unexpectedly and the cause is not already proven, even if a fix seems obvious. Do not guess at fixes.

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Reproduce it: Run the smallest command that shows the failure.

    line 23
  2. Very specific:

    Check for a recent cause: Run git log --oneline -10 -- <file>.

    line 26
  3. Distinctive:

    Follow the bad value back to where it was created.

    line 31
  4. Distinctive:

    Write down a hypothesis: Use this form: "X fails because Y.

    line 33
  5. Distinctive:

    Test one hypothesis at a time: Add a log, assertion or debugger stop, and run it.

    line 36
  6. Distinctive:

    Look for the same bug elsewhere: Search for the same pattern.

    line 47
  7. Distinctive:

    If three attempts have not worked, stop editing.

    line 53
  8. Distinctive:

    Check your assumptions: the right file, the right branch, a stale build, the right environment, the version that is actually installed.

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “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

Debug a failure

Guessing is the slowest way to debug. A fix that makes the symptom disappear without explaining it usually moves the bug somewhere else. Your job is to explain the failure with evidence, then change as little as possible.

When to use

Any failure whose cause you have not proven. For intermittent test failures, use fix-flaky-test.

Steps

  1. Capture the exact failure. Copy the full error, stack trace, command and input. Read all of it, starting with the first error. Later errors are often side effects.
  2. Reproduce it. Run the smallest command that shows the failure. If you cannot reproduce it, say so and collect more data. Do not "fix" it blind.
  3. Check for a recent cause. Run git log --oneline -10 -- <file>. If it worked before, find the change that broke it. git bisect helps when the range is large.
  4. Read the code at the failure. Open the exact file and line in the trace. Follow the bad value back to where it was created.
  5. Write down a hypothesis. Use this form: "X fails because Y. If that is true, then Z will show it." Choose Z so that it could prove you wrong.
  6. Test one hypothesis at a time. Add a log, assertion or debugger stop, and run it. Change one thing per run, and remove temporary logging afterwards.
  7. Explain the cause. You are ready to fix it when you can say why it fails, why it did not fail before, and why your fix addresses that.
  8. Write the regression test. It must fail on the current code for the same reason as the bug. Follow write-tests.
  9. Fix the cause. Make the smallest change, and run the regression test.
  10. Look for the same bug elsewhere. Search for the same pattern.
  11. Finish. Follow verify-and-report.

Three failed attempts

If three attempts have not worked, stop editing. Revert your experiments, write down what you ruled out, and rethink. Your model of the system is wrong somewhere. Check your assumptions: the right file, the right branch, a stale build, the right environment, the version that is actually installed.

Stop and ask when

  • The failure only appears in an environment you cannot reach.
  • The real fix is much larger than the task, or changes a public contract.
  • The test may be right and the requested behaviour wrong.

Common mistakes

Tempting moveWhy it failsDo this instead
Wrap it in try/catchHides the failureFind why it throws
Add a null checkBad data still reaches this pointFind where the null came from
Change the test to matchRemoves the signalDecide which side is wrong, with evidence
Add a retry or a longer timeoutHides a race or slowdownFind what is slow or racing
Change several things at onceYou cannot tell what workedMake one change per run
Call a failure unrelatedOften it is notCheck it against your baseline

Example

Failure: TypeError: cannot read 'email' of undefined in sendReceipt.

Weak fix: user?.email. The crash stops, and receipts silently stop sending.

Strong work:

Hypothesis: `findUser` returns undefined for deleted users.
Check: logged the id, then queried it. The user was soft-deleted.
Cause: `findUser` filters deleted users, while orders keep their user id.
Fix: use `findUserIncludingDeleted` for receipts.
Regression test: an order from a deleted user still sends a receipt.

Report

Symptom: <exact error>
Reproduce: <command>
Cause: <what is wrong, and why it fails now>
Evidence: <what you ran or read that proves it>
Fix: <what changed>
Regression test: <name, and how it failed before the fix>

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.