| name | diagnosing-bugs |
| description | Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow. |
Uses scratch working memory for hypothesis tracking.
Diagnosing Bugs
RULE: glossary + ADRs. Skip phase only with explicit reason. DO NOT hypothesise before deterministic loop.
1. Feedback loop
MUST build fast pass/fail loop. Try order:
- Failing test at bug-reaching seam.
- Curl/HTTP script via
Bash vs dev server.
- CLI fixture + stdout diff via
Bash.
- Headless browser: DOM/console/network assertions.
- Replay trace/request/payload/event log.
- Throwaway minimal subsystem harness.
- Property/fuzz loop.
git bisect run harness via Bash.
- Differential loop: old vs new/config A vs B.
- HITL bash script from
scripts/hitl-loop.template.sh.
Rules:
- MUST make loop faster/sharper/deterministic.
- Flake: run 100x, parallelise, stress, add sleeps, raise repro rate.
2. Reproduce
- Run loop.
- Match symptom to report.
- Confirm repeatability/flake rate.
- Capture exact error/output/timing.
- DO NOT continue until reproduced.
3. Hypotheses (with working memory)
Initialize session: .scratch/diagnoses/<YYYY-MM-DD>/zoo-diagnosing-bugs-<slug>/
Write <session-dir>/session.md with symptom, repro steps, error signatures.
Generate 3–5 ranked falsifiable hypotheses. Write each to <session-dir>/hypothesis-<N>.md:
- Statement:
If {cause}, then {probe} will {result}
- Rank and confidence
- Rationale
- Instrumentation plan: specific probe and expected outcome
- Status: pending / confirmed / rejected
- Results: (filled during phase 4)
Drop vague hypotheses. Show ranked list. User AFK → proceed top hypothesis.
4. Instrument (with tracking)
Before each probe, read all <session-dir>/hypothesis-*.md files to maintain context.
- Map one probe to one hypothesis.
- Change one variable at a time.
- Prefer debugger/REPL.
- Else add targeted logs only.
- Tag logs
[DEBUG-xxxx].
- DO NOT log everything.
- Perf: baseline/profiler/query plan before logs.
After each probe, update the corresponding hypothesis file with:
- Evidence observed
- Status update (confirmed / rejected)
- Next steps
Continue until root cause is confirmed or all hypotheses are rejected.
5. Fix + regression
OWNER: Implementer profile (requires source-code edits)
Delegate to implementer profile via Agent tool before this phase. Implementer executes:
- If correct seam exists, write regression test before fix.
- Correct seam = real call-site bug pattern.
- If seam shallow/missing, document architecture gap.
- Watch regression fail.
- Apply minimal fix.
- Watch regression pass.
- Rerun original loop.
Implementer does NOT return completion here — more phases remain. Continue to Phase 6.
6. Cleanup
OWNER: Implementer profile (requires source-code edits and git commit)
MUST finish:
Implementer returns results back to architect profile for Phase 7.
Context economy
Before broad reads, locate relevant files/symbols with Glob, Grep, or targeted Read.
Prefer targeted Read with line ranges or block reads once the relevant area is known.
Read full files only when structure, ordering, or surrounding context is required for correctness.
Do not re-read unchanged files; use prior findings unless the file changed.
For logs or large outputs, search for the failing marker/error first using Grep. Read only surrounding ranges needed to prove or disprove a hypothesis.
7. Save and synthesize
OWNER: Architect profile (writes to .scratch/)
Read all <session-dir>/hypothesis-*.md files.
Write <session-dir>/root-cause.md:
- Confirmed hypothesis with evidence trail
- Rejected hypotheses and why they failed
- Root cause explanation
- Fix applied (from phase 5-6)
- Preventive measures
Write <session-dir>/diagnosis.md with full log (hypotheses, instrumentation results, timeline).
COMPLETION PROTOCOL: Your final text message is your return value. Output this summary, then STOP — do not call any more tools.
<session-dir>/root-cause.md path
- root cause summary
- fix applied
- status
- recommended next command (typically
/zoo-verify then /zoo-review then /zoo-commit-and-document)