lootlog/monorepo / .agents/skills/diagnosing-bugs
diagnosing-bugs
VerifiedDiagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.
Diagnosing Bugs
A discipline for hard bugs. Scale the investigation to the defect and explain when a phase is impractical or unnecessary. Follow AGENTS.md for permissions, running applications, and required verification.
Phase 1 — Build a feedback loop
Prefer a focused pass/fail signal that catches the reported bug. Use code inspection to locate the relevant path and build the cheapest useful reproduction; scale setup effort to the defect and available environment.
Ways to construct one — try them in roughly this order
- Failing test at whatever seam reaches the bug — unit, integration, e2e.
- Curl / HTTP script against a running dev server.
- CLI invocation with a fixture input, diffing stdout against a known-good snapshot.
- Headless browser script (Playwright / Puppeteer) — drives the UI, asserts on DOM/console/network.
- Replay a captured trace. Save a real network request / payload / event log to disk; replay it through the code path in isolation.
- Throwaway harness. Exercise the relevant code in isolation when a small harness suffices. Respect the repository rule against starting applications and keep fakes at genuine external boundaries.
- Property / fuzz loop. If the bug is "sometimes wrong output", run 1000 random inputs and look for the failure mode.
- Bisection harness. If the bug appeared between two known states (commit, dataset, version), automate "boot at state X, check, repeat" so you can
git bisect runit. - Differential loop. Run the same input through old-version vs new-version (or two configs) and diff outputs.
- HITL bash script. Last resort. If a human must click, drive them with
scripts/hitl-loop.template.shso the loop is still structured. Captured output feeds back to you.
Use the loop to distinguish causes and verify the eventual fix.
Tighten the loop
Treat the loop as a product. Once you have a loop, tighten it:
- Can I make it faster? (Cache setup, skip unrelated init, narrow the test scope.)
- Can I make the signal sharper? (Assert on the specific symptom, not "didn't crash".)
- Can I make it more deterministic? (Pin time, seed RNG, isolate filesystem, freeze network.)
A 30-second flaky loop is barely better than no loop; a 2-second deterministic one is tight — a debugging superpower.
Non-deterministic bugs
Measure the reproduction rate. Use bounded retries, controlled concurrency, or a pinned seed when they improve the signal. Avoid unbounded stress or brittle timing changes; report residual flakiness.
When you genuinely cannot build a loop
State what you tried and which evidence is missing. Continue useful static analysis, caller tracing, and inspection of available logs or artifacts. Ask only for information or access that materially blocks the remaining work; production instrumentation requires appropriate authorization. Label hypotheses as unverified and distinguish a proposed or partially verified fix from a reproduced and verified fix.
Completion criterion — a tight loop that goes red
When a loop is practical, establish that it is tight and red-capable: you can name one command — a script path, a test invocation, a curl — that you have already run at least once (paste the invocation and its output), and that is:
- Red-capable — it drives the actual bug code path and asserts the user's exact symptom, so it can go red on this bug and green once fixed. Not "runs without erroring" — it must be able to catch this specific bug.
- Deterministic — same verdict every run (flaky bugs: a pinned, high reproduction rate, per above).
- Fast — seconds, not minutes.
- Agent-runnable — you can run it unattended; a human in the loop only via
scripts/hitl-loop.template.sh.
If no executable reproduction is practical, record the limitation and continue with the available evidence. Code inspection can guide hypotheses and reproduction work, but is not evidence that a runtime reproduction passed.
Phase 2 — Reproduce + minimise
When a loop is available, run it and confirm that it reproduces the reported bug.
Confirm:
- The loop produces the failure mode the user described — not a different failure that happens to be nearby. Wrong bug = wrong fix.
- The failure is reproducible across multiple runs (or, for non-deterministic bugs, reproducible at a high enough rate to debug against).
- You have captured the exact symptom (error message, wrong output, slow timing) so later phases can verify the fix actually addresses it.
Minimise
Once it's red, shrink the repro to the smallest scenario that still goes red. Cut inputs, callers, config, data, and steps one at a time, re-running the loop after each cut — keep only what's load-bearing for the failure.
Why bother: a minimal repro shrinks the hypothesis space in Phase 3 (fewer moving parts left to suspect) and becomes the clean regression test in Phase 5.
Minimise until the reproduction isolates the relevant behavior well enough to test a cause. If reproduction is unavailable, keep that limitation explicit while evaluating hypotheses from other evidence.
Phase 3 — Hypothesise
Rank plausible causes from the evidence. Consider alternatives when the cause is ambiguous; do not invent a fixed number of hypotheses for an obvious defect.
Each hypothesis must be falsifiable: state the prediction it makes.
Format: "If is the cause, then will make the bug disappear / will make it worse."
If you cannot state the prediction, the hypothesis is a vibe — discard or sharpen it.
Show the ranked list to the user before testing. They often have domain knowledge that re-ranks instantly ("we just deployed a change to #3"), or know hypotheses they've already ruled out. Cheap checkpoint, big time saver. Don't block on it — proceed with your ranking if the user is AFK.
Phase 4 — Instrument
Each probe must map to a specific prediction from Phase 3. Change one variable at a time.
Tool preference:
- Debugger / REPL inspection if the env supports it. One breakpoint beats ten logs.
- Targeted logs at the boundaries that distinguish hypotheses.
- Never "log everything and grep".
Tag every debug log with a unique prefix, e.g. [DEBUG-a4f2]. Cleanup at the end becomes a single grep. Untagged logs survive; tagged logs die.
Perf branch. For performance regressions, logs are usually wrong. Instead: establish a baseline measurement (timing harness, performance.now(), profiler, query plan), then bisect. Measure first, fix second.
Phase 5 — Fix + regression test
Write the regression test before the fix — but only if there is a correct seam for it.
A correct seam is one where the test exercises the real bug pattern as it occurs at the call site. If the only available seam is too shallow (single-caller test when the bug needs multiple callers, unit test that can't replicate the chain that triggered the bug), a regression test there gives false confidence.
If no correct seam exists, that itself is the finding. Note it. The codebase architecture is preventing the bug from being locked down. Flag this for the next phase.
If a correct seam exists:
- Turn the minimised repro, or independently established expected behavior, into a failing test at that seam.
- Watch it fail.
- Apply the fix.
- Watch it pass.
- Re-run the original scenario when available; otherwise report which checks passed and what remains unverified.
Phase 6 — Cleanup + post-mortem
Required before declaring done:
- Original repro passes when available; otherwise the missing reproduction and remaining runtime uncertainty are stated
- Regression test passes (or absence of seam is documented)
- All
[DEBUG-...]instrumentation removed (grepthe prefix) - Throwaway prototypes deleted (or moved to a clearly-marked debug location)
- The supported cause and verification limits are stated in the final report and any requested commit or PR
Then ask: what would have prevented this bug? If the answer involves architectural change such as a missing test seam, tangled callers, or hidden coupling, use engineering-rigor and codebase-design with the evidence from the fix. Make the recommendation after the fix, when the cause is known.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |