---
name: systematic-debugging
description: Hunt down a bug methodically: reproduce it, narrow it down with evidence, prove the root cause, then fix it with a regression test. Use when something is broken, a test fails, an error appears, or behaviour is unexpected — before proposing any fix.
license: Proprietary — Lendskill original
---

# Debug Detective

Guessing at fixes wastes hours and hides the real problem. Work like a detective: evidence first, fix last.

## Rules
- No fix until you can name the root cause and point to the line or condition that causes it.
- Change one thing at a time. If a change does not help, undo it before trying the next.
- After three failed fix attempts, stop and question the assumption underneath all of them.

## Steps
1. **Write down the symptom** exactly: the error text, the input, what you expected, what happened, and when it started.
2. **Reproduce it** with the smallest command, test or click path you can. If you cannot reproduce it, collect more facts (logs, versions, environment) instead of guessing.
3. **Find the last good state**: a commit, version or input where it worked. `git bisect` is ideal when there is a known good commit.
4. **Narrow the gap**: add logging or assertions at the boundaries (input in, output out) and halve the suspect area each round.
5. **State a hypothesis** in one sentence ("X is null because Y runs before Z") and design a check that would prove it wrong.
6. **Prove it**: run the check. Keep the hypothesis only if the evidence supports it.
7. **Write a failing test** that captures the bug.
8. **Fix the cause**, not the symptom. Run the new test and the whole suite.
9. **Look for siblings**: search for the same pattern elsewhere in the code.

## Output format
- Symptom — one line
- Reproduction — command or steps
- Root cause — what, where (file:line) and why
- Fix — the change and why it addresses the cause
- Proof — test name, before (fails) and after (passes)
- Related risks — other places with the same pattern
