"Find the root cause of a bug and fix it with proof: reproduce the failure, test competing explanations, trace the cause from trigger to symptom, and fix it behind a regression test. Use when something is broken, failing, flaky, slower than it used to be, or behaving differently than expected."
Recursos
2Instal·la
npx skillscat add zacharticulatev/compound-memory/debug Instal·la des del registre de SkillsCat.
Debug
Explain why the failure happens, from trigger to symptom with no gaps, and
change the code so it cannot happen again. A fix without an explanation is a
guess that happened to pass.
Done when: a check that reproduced the symptom now passes (for a rare bug,
its measured failure rate dropped to zero over enough runs to show it), a
regression test failed before the fix and passes after it, or the report says
why no test could reach it; the temporary instrumentation is gone; and the
causal chain is written down.
Steps
Ground. Read what the project already knows about this area:
memory/bugs-and-risks.md(known bugs and open hypotheses), the matching
lessons, recent commits on the suspect paths, and related issues or PRs.
Read every comment on a linked issue: an open fix PR may be the answer, and
a merged attempt that did not hold rules that fix out.node "${CLAUDE_SKILL_DIR}/../../scripts/lessons.mjs" --query "<symptom>" --paths <path>,<path>Build a loop that goes red. Name one command you have already run that
fails on the user's exact symptom (not merely "it errors"). Best is one that
gives the same verdict every run in seconds;references/techniques.md
lists ways to build one. A rare, slow, or timing bug may only allow a loop
that fails some of the time or takes minutes: measure its failure rate and
use it. A bug seen only in production may only allow instrumentation and a
wait for the next occurrence. If you cannot build any loop, say so, list
what you tried, and ask for what would make one (access to the failing
environment, a captured log or trace). A hypothesis formed before you can
observe the failure is a guess. Once it is red, cut inputs, callers,
configuration, and steps one at a time until removing any one turns it
green; that minimal case becomes the regression test. Redact secrets from
every command and output you show.Audit assumptions. List what you believe about the failing path and mark
each belief verified or assumed. The bug usually lives in an assumed one.Compete. Rank a few hypotheses, each with the prediction that would
prove it wrong. When a person is present, show the ranking before testing
and go on without waiting; they often know which one just changed. Design
the observation that tells the leaders apart, and run it.references/techniques.mdhas ways to narrow a search.Trace the chain: trigger, each step, symptom, every link backed by an
observation. A gap in the chain is the next thing to observe.Fix the cause. The root is the first place the system did something it
should not, not the place the symptom surfaced. Ask whether the state that
broke the code is legitimate: if it is, handle it where it broke; if it
should never exist, find what produced it, because a guard there would hide
the bug. Retries, swallowed errors, clamped values, and dropped state hide
it the same way, and a workaround that needs a paragraph to justify it marks
code to fix. A fix that reverses behavior a test or the docs assert on
purpose is the user's call; unattended, leave it unapplied as an open item.
Write the regression test beside the tests that own the behavior, at a seam
that replays the call pattern that failed (strengthen an over-mocked test
rather than add a second); when no such seam exists, say so and hand it on
as an architecture finding. Watch it fail, fix, watch it pass, run the
broader suite, and fix every other place with the same fault. Run the
original loop again: the user's symptom, not only the new test.
Then remove the instrumentation you added (mark itDEBUG-TEMPwhen you add
it;git diff | grep DEBUG-TEMPfinds what is left), unless the signal is
worth keeping as a permanent log line.After three failed fixes, stop patching. The model of the system is
wrong somewhere. Revisit the assumptions, question the design, and tell the
user what you have ruled out.Record. State the confirmed cause in the fix's commit message. In a
project with memory, updatememory/bugs-and-risks.md: the confirmed cause
in its own field, rival hypotheses kept as hypotheses.
Offerlearn capturewhen the cause would surprise the next engineer, andlearn correctwhen this class of bug can be made impossible.
Report
**Symptom:** what failed, where, for whom
**Reproduction:** the check, and its failing output
**Cause:** the chain from trigger to symptom
**Fix:** what changed, and why it addresses the cause
**Proof:** the regression test and suite results, observed, and the original
loop's result after the fix
**Residual risk:** what this fix does not coverWorks with
- Reads: bugs and risks, lessons, the verification skill, Git history.
- Hands off: the fix to
reviewandship; lessons and checks tolearn. - Alone: works in any repository with no memory tree.
Paths in this skill and its references are relative to this skill's directory
(${CLAUDE_SKILL_DIR}). Outside Claude Code, that is the directory holding this
file.