← Notes
3 min read

The AI keeps fixing the same bug: how to debug with AI tools

Why AI fixes go in circles, and a five-step way to find the real cause: reproduce, read, narrow down, change one thing, check.

Debugging with AIDeveloper basics

You paste the error. The AI says “Fixed!” Something else breaks. You paste that error, and the first bug comes back. An hour later you’re still going round in circles, and if your tool charges per fix, you’re paying for each lap.

You’re not alone. In the 2025 Stack Overflow Developer Survey, 66% of developers said their top frustration is AI answers that are “almost right, but not quite”, and 45.2% said debugging AI-generated code takes more time.

Here is why the loop happens, and a five-step way out.

Why the loop happens

The AI only sees what you paste. “It’s broken” plus an error message gives it a symptom, not a cause, so it guesses. Each guess changes code that may have been fine, which creates the next symptom. The AI isn’t failing at fixing. It’s being asked to fix something nobody has found yet.

Think of it like this

A doctor who only hears “it hurts” will prescribe something. A doctor who hears where it hurts, since when, and what makes it worse can find the cause. Your job in debugging is to bring the second kind of description.

The five-step way out

Debug, don't loop
  1. 1Reproduce it — find the exact steps that make the bug happen every time
  2. 2Read the real error — the browser console, the server logs, the status code. Not just what's on screen
  3. 3Narrow it down — what changed since it last worked? Undo half, test, and repeat
  4. 4Change one thing — one fix at a time, so you know which change did what
  5. 5Check it worked — repeat step 1. If the bug is gone and nothing else broke, save a version

How to ask the AI

The tools’ own guides now say the same thing.

  • Describe expected vs actual. Lovable’s troubleshooting guide tells users to stop resending the same prompt, and to describe what they see against what they expected.
  • Roll back instead of piling on fixes. The same guide suggests reverting to the last working version and using Plan mode before more changes. Lovable caps free “Try to fix” attempts at 10.
  • Give it a way to check itself. Claude Code’s best-practice guide says to give the tool a pass or fail check it can run, like a test or a build.
  • Know when to restart. The same guide says that after two failed corrections, clear the session and write a better prompt, because the conversation is now full of failed attempts.
You Login fails.
You Login fails in production only. Expected: dashboard. Actual: blank page. Console: 401 from /api/session. Worked yesterday before I added the profile page.
The same bug, described two ways. The second one gives the AI a cause to work with.

The rule that prevents the next loop

Simon Willison’s rule for AI-written code: don’t commit code you couldn’t explain to someone else. You don’t need to write it yourself. You do need to understand what each fix changed, or the next bug will be a mystery too.


Next in Debugging with AI: Blank screen, no error: reading logs and the browser console (coming soon).

Sources