| 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. |
| disable-model-invocation | true |
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 vs dev server.
- CLI fixture + stdout diff.
- Headless browser: DOM/console/network assertions.
- Replay trace/request/payload/event log.
- Throwaway minimal subsystem harness.
- Property/fuzz loop.
git bisect run harness.
- 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: code-tweaker (requires source-code edits)
Architect MUST switch_mode to code-tweaker before this phase. Tweaker 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.
Tweaker does NOT call attempt_completion here — more phases remain. Continue to Phase 6.
6. Cleanup
OWNER: code-tweaker (requires source-code edits and git commit)
MUST finish:
Tweaker MUST switch_mode back to system-architect for Phase 7.
Context economy
Before broad reads, locate relevant files/symbols with list_files, search_files, or codebase_search.
Prefer targeted read_file ranges or indentation/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. Read only surrounding ranges needed to prove or disprove a hypothesis.
7. Save and synthesize
OWNER: system-architect (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).
Call attempt_completion with:
<session-dir>/root-cause.md path
- root cause summary
- fix applied
- status
- recommended next command (typically
/zoo-verify then /zoo-code-review then /zoo-commit-and-document)