Engineering

Trace-First Debugging

Make the agent earn the fix before touching code.

Use when

A failure has logs, screenshots, stack traces, recent commits, or user reports, but the cause is not obvious yet.

Cadence

When an agent is tempted to patch a bug from a hunch

Verification

The bug is reproduced, the root cause is evidenced by traces or tests, and the fix includes a regression check.

Advanced spec

Structured loop spec

FieldValue
NameTrace-First Debugging
CategoryEngineering
TriggerWhen an agent is tempted to patch a bug from a hunch
ObjectiveMake the agent earn the fix before touching code.
Allowed inputsRelevant files, source notes, logs, tests, screenshots, metrics, or task state for this loop
Allowed actionsCollect the symptom, expected behavior, recent changes, logs, stack traces, screenshots, and environment details.; List plausible causes and the smallest diagnostic for each before modifying files.; Reproduce the bug or create a failing regression test/check that captures it.; Patch the smallest proven cause and remove temporary debug noise unless it should become structured logging.; Verify the original reproduction fails before and passes after, then run nearby tests.
VerificationThe bug is reproduced, the root cause is evidenced by traces or tests, and the fix includes a regression check.
Stop conditionStop when the verifier passes, the budget is exhausted, no progress is made, a blocker appears, or approval is required.
BudgetSet a time, turn, token, retry, file, or dollar cap before running the loop.
Approval boundaryHuman approval required before public, destructive, financial, legal, account, or production-impacting actions.
Safe outputPull request, patch, report, or evidence log
Works withClaude Code, OpenAI Codex, Cursor, Gemini CLI, any tool-using coding agent
Runbook

Steps

  1. Collect the symptom, expected behavior, recent changes, logs, stack traces, screenshots, and environment details.
  2. List plausible causes and the smallest diagnostic for each before modifying files.
  3. Reproduce the bug or create a failing regression test/check that captures it.
  4. Patch the smallest proven cause and remove temporary debug noise unless it should become structured logging.
  5. Verify the original reproduction fails before and passes after, then run nearby tests.
Copy prompt

Prompt

Run the Trace-First Debugging loop. Do not patch from vibes. Gather symptom, expected behavior, recent changes, logs, traces, screenshots, and environment. List likely causes with diagnostics before editing. Reproduce the bug or create a failing regression check, patch the smallest proven cause, remove temporary debug noise, and verify the original reproduction plus nearby tests.
Metadata

Tags

debugginglogsreproductionroot cause
Next loops

Related