Pattern
debugging
workflow

Debug Loops

Systematic approaches to debugging with AI assistance without going in circles.

The Debug Loop Problem

Without structure, debugging with AI can become:

Error → AI fix → New error → AI fix → Different error → ...

This pattern wastes time and context.

The Systematic Approach

Step 1: Reproduce Reliably

Before asking AI for help:

markdown
## Reproduction Steps
1. Start the dev server
2. Navigate to /users
3. Click "Add User"
4. Submit form with email "[email protected]"
5. Error appears in console

If you can't reproduce it reliably, that's the first problem to solve.

Step 2: Isolate the Problem

Narrow down where the error occurs:

markdown
## Isolation
- Error is in: src/api/users.ts
- Function: createUser()
- Line: 45 (approximately)
- Triggered by: POST /api/users

Step 3: Gather Evidence

Debug Context

engineer

Structured debug information

I'm debugging an issue.

## Error
{{error_message}}

## Stack Trace
{{stack_trace}}

## What I've Tried
- [Previous attempt 1]
- [Previous attempt 2]

## Constraints
- Don't change the function signature
- Minimal changes preferred
- Explain what's happening
Variables:
{{error_message}}
{{stack_trace}}

Step 4: Hypothesize Before Fixing

Ask AI to explain before fixing:

markdown
Before suggesting a fix, answer:
1. What do you think is happening?
2. Why is this causing the error?
3. What evidence supports your hypothesis?

Step 5: Test the Fix

After each fix:

  1. Save the change
  2. Reproduce the issue
  3. Verify it's fixed
  4. Check for regressions

Breaking the Loop

When Fixes Create New Errors

Stop and reassess:

markdown
We've tried 3 fixes and each created a new error.

Let's step back:
1. What is the root cause?
2. Are we treating symptoms?
3. Should we try a different approach entirely?

When Going in Circles

markdown
We seem to be going in circles. Let's:
1. List all errors we've seen
2. Identify the common thread
3. Start fresh with a simpler approach

The Reset Point

Sometimes the best move is:

bash
git checkout -- .

Then start with a clearer understanding of the problem.

Debug Prompt Patterns

The Minimal Reproducer

Minimal Reproducer

engineer

Create the smallest code that shows the bug

Help me create a minimal reproducer for this bug.

## Current code (complex)
[paste code]

## The bug
[describe bug]

## Goal
Create the smallest possible code that demonstrates this bug.
We'll fix the minimal version, then apply to the real code.

The Trace Request

Execution Trace

vibecoding

Understand code flow

Add console.log statements to trace execution through this function.

## Function
[paste function]

## What I want to see
- Input values
- Decision points
- Output values

I'll remove the logs after debugging.

The Comparison Request

Working vs Broken

engineer

Compare working and broken versions

Here are two versions of similar code:

## Working version (different feature)
[paste working code]

## Broken version
[paste broken code]

## The difference
Working one handles X, broken one handles Y.
Y fails with [error].

What's different about how they handle things?

Common Debugging Mistakes

MistakeBetter Approach
Fixing without understandingAsk "why" first
Changing multiple thingsOne change at a time
Not testing after each fixAlways verify
Accumulating "fixes"Reset and try clean approach
Ignoring the stack traceRead it carefully

Time Boxing

Set limits on debugging sessions:

Time SpentAction
15 minCheck: Am I making progress?
30 minTry a different approach
1 hourTake a break, get fresh eyes
2 hoursEscalate or simplify

The Nuclear Option

When nothing works:

  1. Simplify drastically

    • Remove features until it works
    • Add them back one by one
  2. Find a working example

    • Official documentation
    • Similar open source project
    • Stack Overflow answer
  3. Start from scratch

    • Sometimes faster than fixing
    • Use working code as template

Verification

Your debug process is effective if:

  • Bugs get fixed in < 3 attempts
  • You understand why each fix works
  • New bugs aren't introduced
  • Similar bugs don't recur