The AI keeps 'fixing' the same bug and making it worse
Same error after 5 AI attempts; the code keeps getting longer
In short: Each blind retry adds more code and more guesses. Stop patching and get a diagnosis first.
Why it happens
AI agents tend to change code when they're unsure, rather than gather evidence. After a few rounds, the original error is buried under workarounds. The fix is to reset to a known-good state and force a diagnose-before-edit step.
How to fix it
- Revert to the last working commit or checkpoint (git, or the tool's version history).
- Copy the exact error text, the file, and what you did right before it broke.
- Ask for a diagnosis only, with no code changes: likely causes, ranked, and how to confirm each.
- Confirm the cause with a log or a small test, then ask for the smallest fix.
- Commit after every working step so you always have a checkpoint.
Don't: Don't say 'it's still broken, fix it' again. Give new evidence each time.
Copy-paste fix prompt
I'm getting this error in my app: Same error after 5 AI attempts; the code keeps getting longer [Paste the full error, stack trace, and the file it points to here] Likely cause: Each blind retry adds more code and more guesses. Stop patching and get a diagnosis first. Task: Do not edit any files yet. Read the error and the relevant files, list the 3 most likely root causes ranked by probability, and for each tell me one quick check (a log line or command) that confirms or rules it out. Rules: - First explain the root cause in 2 sentences and list the files you'll change. - Make the smallest change that fixes it. Don't refactor unrelated code. - Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear. - Never print or hard-code secret keys. - Finish by telling me exactly how to verify the fix.
Common with: Cursor, Claude Code, Codex, Lovable, Bolt, Replit, v0. Last reviewed 2026-11-13.
Did this fix it?
(Placeholder: feedback isn't recorded yet.)