Easy PromptAI Prompt Library
Logic ReasoningTextAdvanced

Diagnose Debugging Workflow

A disciplined diagnosis loop for hard bugs and performance regressions: reproduce → minimise → hypothesise → instrument → fix → regression-test. Use when user says 'diagnose this' / 'debug this', reports a bug, says something is broken/throwing/failing, or describes a performance regression.

Prompt Content

Copy and paste directly into your model or internal evaluation tool.

When user says 'diagnose this' / 'debug this', reports a bug, describes something broken/throwing/failing, or points to a performance regression, follow this disciplined process.

Phase 1 — Build a feedback loop (The skill)

This is the skill. Everything else is mechanical. If you have a fast, deterministic, agent-runnable pass/fail signal for the bug, you will find the cause — bisection, hypothesis-testing, and instrumentation all just consume that signal. If you don't have one, no amount of staring at code will save you.

Spend disproportionate effort here. Be aggressive. Be creative. Refuse to give up.

Ways to construct one — try them in roughly this order

  1. Failing test at whatever seam reaches the bug — unit, integration, e2e
  2. Curl / HTTP script against a running dev server
  3. CLI invocation with fixture input, diffing stdout against known-good snapshot
  4. Headless browser script (Playwright / Puppeteer) — drives UI, asserts on DOM/console/network
  5. Replay a captured trace — save real network request/payload/event log to disk; replay through code path in isolation
  6. Throwaway harness — spin up minimal subset of system (one service, mocked deps) that exercises bug code path with single function call
  7. Property / fuzz loop — if bug is 'sometimes wrong output', run 1000 random inputs and look for failure mode
  8. Bisection harness — if bug appeared between two known states (commit, dataset, version), automate 'boot at state X, check, repeat' so you can git bisect run it
  9. Differential loop — run same input through old-version vs new-version (or two configs) and diff outputs
  10. HITL bash script — last resort. If human must click, drive them with scripts/hitl-loop.template.sh so loop is still structured. Captured output feeds back to you

Build the right feedback loop, and the bug is 90% fixed.

Iterate on the loop itself

Treat the loop as a product. Once you have a loop, ask:

  • Can I make it faster? (Cache setup, skip unrelated init, narrow test scope)
  • Can I make the signal sharper? (Assert on 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 loop is a debugging superpower.

Non-deterministic bugs

Goal is not clean repro but higher reproduction rate. Loop trigger 100x, parallelise, add stress, narrow timing windows, inject sleeps. 50%-flake bug is debuggable; 1% is not — keep raising until debuggable.

When you genuinely cannot build a loop

Stop and say so explicitly. List what you tried. Ask user for: (a) access to whatever environment reproduces it, (b) a captured artifact (HAR file, log dump, core dump, screen recording with timestamps), or (c) permission to add temporary production instrumentation. Do not proceed to hypothesise without a loop.

Do not proceed to Phase 2 until you have a loop you believe in.

Phase 2 — Reproduce

Run the loop. Watch the bug appear.

Confirm:

  • The loop produces the failure mode the user described — not a different failure that happens to be nearby. Wrong bug = wrong fix
  • Failure is reproducible across multiple runs (or, for non-deterministic bugs, reproducible at high enough rate to debug against)
  • You have captured exact symptom (error message, wrong output, slow timing) so later phases can verify fix actually addresses it

Do not proceed until you reproduce the bug.

Phase 3 — Hypothesise

Generate 3–5 ranked hypotheses before testing any of them. Single-hypothesis generation anchors on first plausible idea.

Each hypothesis must be falsifiable: state prediction it makes.

Format: 'If <X> is the cause, then <changing Y> will make bug disappear / <changing Z> will make it worse.'

If you cannot state prediction, hypothesis is a vibe — discard or sharpen it.

Show ranked list to user before testing. They often have domain knowledge that re-ranks instantly ('we just deployed 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 user is AFK.

Phase 4 — Instrument

Each probe must map to specific prediction from Phase 3. Change one variable at a time.

Tool preference:

  1. Debugger / REPL inspection if env supports it. One breakpoint beats ten logs
  2. Targeted logs at boundaries that distinguish hypotheses
  3. Never 'log everything and grep'

Tag every debug log with unique prefix, e.g. [DEBUG-a4f2]. Cleanup at end becomes single grep. Untagged logs survive; tagged logs die.

Perf branch — for performance regressions, logs are usually wrong. Instead: establish baseline measurement (timing harness, performance.now(), profiler, query plan), then bisect. Measure first, fix second.

Phase 5 — Fix + regression test

Write regression test before fix — but only if there is a correct seam for it.

Correct seam is one where test exercises real bug pattern as it occurs at call site. If only available seam is too shallow (single-caller test when bug needs multiple callers, unit test that can't replicate chain that triggered bug), regression test there gives false confidence.

If no correct seam exists, that itself is the finding. Note it. Codebase architecture is preventing bug from being locked down. Flag this for next phase.

If correct seam exists:

  1. Turn minimised repro into failing test at that seam
  2. Watch it fail
  3. Apply fix
  4. Watch it pass
  5. Re-run Phase 1 feedback loop against original (un-minimised) scenario

Phase 6 — Cleanup + post-mortem

Required before declaring done:

  • Original repro no longer reproduces (re-run Phase 1 loop)
  • Regression test passes (or absence of seam documented)
  • All [DEBUG-...] instrumentation removed (grep prefix)
  • Throwaway prototypes deleted (or moved to clearly-marked debug location)
  • Hypothesis that turned out correct stated in commit / PR message — so next debugger learns

Then ask: what would have prevented this bug? If answer involves architectural change (no good test seam, tangled callers, hidden coupling), hand off to /improve-codebase-architecture skill with specifics. Make recommendation after fix is in, not before — you have more information now than when you started.

Use Cases

User reports system crashrequires root cause investigation and fixAPI response slowdown detectedneed to locate performance bottleneckNew release breaks existing functionalityrequires rapid diagnosis and rollback or fix

Reference Output

```markdown # Diagnostic Report - [Issue Title] ## Phase 1: Feedback Loop - Method: curl script + snapshot comparison (CLI) - Duration: 2 seconds, 100% reproduction rate ## Phase 2: Reproduction Confirmation - User-described symptom: returns 500 error - Actual reproduction: Yes, consistently returns same error message ## Phase 3: Hypothesis List 1. Database connection pool exhaustion causing timeout 2. Third-party service rate limiting triggering retry storm 3. Cache miss causing instantaneous high load ## Phase 4: Instrumentation Verification - Added `[DEBUG-db-pool]` logging - Found connection wait time > 5s ## Phase 5: Fix and Testing - Fix: Increased connection pool size - New regression test: Simulate concurrent requests, verify pool doesn't overflow ## Phase 6: Cleanup and Retrospective - All DEBUG logs cleared - Recommendation: Discuss dynamic connection pool scaling in next architecture review ```

Scoring Rubric

Scoring Criteria: - Whether a repeatable, fast feedback loop was established (weight 30%) - Whether the original user-reported issue was accurately reproduced (weight 20%) - Whether hypotheses were specific, verifiable with clear predictions (weight 20%) - Whether instrumentation was precise, non-redundant, and properly tagged for cleanup (weight 15%) - Whether effective regression test was written or absence of test seam documented (weight 10%) - Whether cleanup completed and architectural improvement suggested (weight 5%)

User Rating

0 ratings
-

Your rating

Log in to rate

Comments

0

Log in to comment

Related Prompts

ImageWriting

Product Marketing - Monochrome Avant-Garde Fashion Portrait

A high-fashion, monochrome editorial prompt for a sharp portrait with dramatic lighting and futuristic accessories, mimicking a luxury brand campaign.

Nano Banana Proimage promptProduct Marketing
Nano Banana Pro image generation
ImageWriting

Social Media Post - Dreamy Woman in Wildflower Field

A cinematic, photorealistic prompt for a serene portrait of a woman in a field of daisies, emphasizing soft natural light and sharp focus on foreground details.

Nano Banana Proimage promptSocial Media Post
Nano Banana Pro image generation
ImageWriting

Social Media Post - Mediterranean Riviera Male Menswear

A comprehensive professional photography prompt for a sharp, high-contrast menswear editorial set against sun-drenched stone architecture.

Nano Banana Proimage promptSocial Media Post
Nano Banana Pro image generation