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:
markdownBefore 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:
- Save the change
- Reproduce the issue
- Verify it's fixed
- Check for regressions
Breaking the Loop
When Fixes Create New Errors
Stop and reassess:
markdownWe'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
markdownWe 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:
bashgit 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
| Mistake | Better Approach |
|---|---|
| Fixing without understanding | Ask "why" first |
| Changing multiple things | One change at a time |
| Not testing after each fix | Always verify |
| Accumulating "fixes" | Reset and try clean approach |
| Ignoring the stack trace | Read it carefully |
Time Boxing
Set limits on debugging sessions:
| Time Spent | Action |
|---|---|
| 15 min | Check: Am I making progress? |
| 30 min | Try a different approach |
| 1 hour | Take a break, get fresh eyes |
| 2 hours | Escalate or simplify |
The Nuclear Option
When nothing works:
-
Simplify drastically
- Remove features until it works
- Add them back one by one
-
Find a working example
- Official documentation
- Similar open source project
- Stack Overflow answer
-
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