# Diagnose

> Find the root cause of a bug from live evidence on the real system, then guard the fix with a test. Use when something is broken, the build breaks or a build or

- Skill: `ilexpwh/diagnose` (Agent Skill)
- Install (CLI): `npx get-skill add ilexpwh/diagnose`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ilexpwh/diagnose/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: Ilexpwh (https://skillmd.com/u/ilexpwh)
- Updated: 2026-12-02
- Page: https://skillmd.com/skills/ilexpwh/diagnose

---

---
name: diagnose
description: Find the root cause of a bug from live evidence on the real system, then guard the fix with a test. Use when something is broken, the build breaks or a build or job fails, it crashes, throws an exception, returns errors or 500s, a stack trace or error log is pasted, a test fails, fails intermittently or is flaky, it worked yesterday, or the user asks why, debug this, investigate, troubleshoot, or what broke. Not for speed work (performance) or confirming a released fix (prove-it-live).
metadata:
  phase: build
---

# Diagnose

A root cause proven by a run on the real system, with dead ends recorded, and a test that fails without the fix.

## When to use
- A bug report, a stack trace, errors in logs, 5xx responses, a crash, a failing or flaky test.
- "It worked yesterday", "what broke", "why does it do this".
- Step 2 of the `bug-fix` playbook.

**Not for:** slowness with no error (`performance`), checking that a released fix works (`prove-it-live`), or new behaviour with no defect (`tdd`).

## Steps
1. **Open a diagnosis file.** In run mode create the ledger's `run/evidence/<id>-diagnosis.md`; otherwise a scratch file. Write the symptom as one observable sentence ("`POST /orders` returns 500 for carts with a coupon on staging since 09:40 UTC"), where it was seen, and an empty table: hypothesis | how to test | result | status. Every later step writes to this file. *Done when:* the symptom sentence names the surface, the input and the wrong result.
2. **Reproduce it yourself.** Trigger the symptom on the surface where it was seen: run the failing command, replay the request, drive the UI (`build-harness` if nothing can). Don't ask the user to reproduce what you can trigger (`no-homework`). If it won't fire, match conditions one at a time: same data, same version, same config, concurrency, timing, a clean environment. *Done when:* one command shows the symptom, or the file lists what you tried and which condition is still missing.
3. **Read the live system.** Within the stake tier (`autonomy-by-stakes`), collect: application logs (`kubectl logs <pod> --since=2h`, `kubectl describe pod <pod>`, `journalctl -u <unit>`), the trace for one failing request id, error and saturation metrics around the first occurrence, recent config or flag changes, and the version that was running (image digest, deployed commit). Use `ssh` to staging only if the tier allows it, and only to read. Check the profile and `AGENTS.md` for cluster, namespace and log locations before asking. Save redacted excerpts beside the diagnosis file. *Done when:* the first failing timestamp and the version running then are written down, or marked unknown with the reason.
4. **Localise.** Name the failing layer: UI, API, data, dependency, config, build, infrastructure, or the test itself. For a regression, find the change: diff the last good and first bad versions, or run `git bisect run <repro command>`. *Done when:* one component (and, for a regression, one commit or config change) is named, with the evidence that points there.
5. **Reduce.** Strip the repro down: smallest input, fewest services, shortest code path that still fails. *Done when:* the minimal repro runs in seconds, or the file says why it can't get smaller.
6. **Prove the cause, not the first suspect.** Write at least two hypotheses that fit the evidence. For each, name a run that would rule it out (a crafted input, a toggle, added logging, a revert), run it and record the result. Continue until one survives and explains every observation, including why it started when it did. Ask "why" until the answer is a design, data or config fact, not just a line number. Record each refuted hypothesis under Dead ends in the next checkpoint, and the cause with `python3 -I "$LEDGER" --root <workspace> decide --task <task> --decision 'Root cause: <mechanism>' --why '<the run that proved it>' --evidence evidence/<id>-diagnosis.md` (`LEDGER` is `../ledger/scripts/ledger.py` from this folder; in Claude Code `${CLAUDE_SKILL_DIR}/../ledger/scripts/ledger.py`). *Done when:* one mechanism is confirmed by a run, the alternatives are refuted, and the cause is a `decide` entry.
7. **Guard it with a failing test.** Turn the minimal repro into a test at the narrowest level that can see it, then follow `../tdd/SKILL.md`: red, the smallest fix at the cause, green, full suite. *Done when:* the test fails on the unfixed code and passes with the fix.
8. **Hand on.** The fix goes to `review-change`, then `land`, then `prove-it-live` against the original symptom on the original surface. *Done when:* the tracker row names the next skill, or a blocker records one exact human step.

## Red flags
| If you're thinking | Do this instead |
|---|---|
| "That's plausibly the cause, let's fix it." | A plausible cause is one hypothesis. Refute at least one alternative with a run before fixing. |
| "Can't reproduce locally; I'll ask the user to try again." | Reproduce where it was seen: logs, a replayed request, staging if the tier allows. Ask only with the specific reason it's out of reach. |
| "A retry, a null check or a dedupe makes it go away." | That hides the symptom. Fix where the bad state is made, and explain why it started now. |
| "I'll add a few defensive changes that might help." | Ship only what the evidence supports. Revert anything a refuted hypothesis motivated. |
| "Which cluster and namespace was it again? I'll ask." | Read the profile and `AGENTS.md` first. Environment facts are recorded once, not re-taught. |
| "I need the database password; I'll ask the user to paste it." | Never. Have them sign in through the tool's own login, or record a blocker (`secrets-stay-out`). |
| "The tool denied `kubectl exec`; a debug pod would get around it." | Record it in `blocked` and continue with what's allowed (`denied-means-stop`). |
| "The new test passes, the bug is fixed." | The symptom was on the target. Close it with `prove-it-live` (`seen-working`). |

## Verify
- [ ] One command reproduces the symptom, or the missing conditions are written down.
- [ ] Evidence came from the real target, with the version that was running.
- [ ] At least two hypotheses were tested; refuted ones are recorded as dead ends.
- [ ] The root cause is a `decide` entry pointing at the diagnosis file.
- [ ] A test fails without the fix and passes with it.

## Reply
```
Symptom: <one sentence>, seen on <target> at <version>, since <time, time zone>.
Root cause: <mechanism> at <file:line or config key>. Introduced by <commit or change, or unknown>.
Proof: <the run that confirmed it>. Ruled out: <hypothesis → the run that refuted it>.
Fix: <one line>. Guard test: <file>::<name>, red → green.
Evidence: <path to diagnosis file>.
Next: <review-change | land | prove-it-live | blocked: exact command>.
```

## Credits
The reproduce, localise, reduce, fix, guard order and bisection for regressions follow Addy Osmani's `debugging-and-error-recovery` in addyosmani/agent-skills. Reproducing on the real surface yourself, ruling hypotheses out until one survives, and proving the mechanism on the live process follow pstack's `bug-fix` and `runtime-forensics` playbooks by Lauren Tan.

