Skip to main content
Handbook/Debug/Page 58 · Loops

When Your Agent Goes in Circles

Share

Share this page

Pass it to someone who needs it.

Star on GitHub

Key takeaway: Break the retry loop

Your agent says it fixed the bug. You run it, the same error comes back. It says it sees the real problem now, changes the file, and hands you the same error again.

Twenty minutes later it is undoing the edit it made ten minutes ago. This chapter teaches you to catch that circling early and break it before it eats your whole session.

7.3.1Recognize a retry loop

A retry loop is when the agent keeps shipping variations of the same broken fix, each time sure it has it. The tell is repetition:

  • the same edit made, reverted, and reapplied
  • the same error message coming back unchanged
  • a confident "now it is fixed" that is not

Catch it by the second round, not the fifth. It usually reads like this:

You: still failing, same TypeError. Agent: I see the issue now. Fixed it. You: same TypeError. Agent: You're right, the real fix is here. Done. You: same TypeError. Agent: I see the issue now... <- you are in a loop
The retry loop: the same broken fix keeps circling back unchanged.

7.3.2Why the agent goes in circles

It is not being lazy. It lost the thread. The window is now full of its own failed attempts, so it keeps pattern-matching on those instead of the real cause. Those are the same dead ends you saw poison a drifting session in the chapter on managing what the agent sees.

The other cause is a wrong mental model. It is reasoning from one false assumption that nothing in the chat corrects, so every fix is internally sensible and still wrong.

7.3.3Break the loop

Stop it before the fourth attempt. Then do one of two things: hand it the fact it is missing, or force a fresh diagnosis before it touches a single line.

The missing fact is usually something only you can see. The real error in the browser console. The actual value of a variable. Or that the file it keeps editing is not the file that runs.

One such fact ends more loops than ten more retries.

Break a loop by feeding the missing fact, or resetting once it has already churned.

7.3.4Reset the context and retry

If it has already churned through three attempts, the window is carrying every one of them, and one more message rarely pulls it out. Start a fresh session, the way the context chapter describes, and open with the missing fact plus a clean ask.

This prompt forces a ranked diagnosis before any edit, which is what actually breaks the loop:

Ready prompt
Act as a senior engineer taking over a stuck debugging session. The previous attempts all failed. Ignore them. Do NOT edit anything yet. Read my rules file and the architecture map in it first, so you reason about where this code actually lives instead of guessing. Then state the top three things that could cause this, ranked by likelihood. For each, name the ONE observation that would confirm or rule it out, and tell me how to get it. Do not propose a fix until one cause is confirmed. If the cause turns out to be a choice my rules file or spec already made, say so rather than quietly changing it. If you cannot explain why the last fix failed, say so instead of guessing. If you need the full reasoning behind this step, read https://zalt.me/guides/vibe-coding/debug/agent-loops What it keeps failing to do:

Do this now: next time the same error returns twice, stop the agent, open a fresh session, and paste this prompt with the one fact only you can see.

Mahmoud Zalt

Mahmoud Zalt

Software engineer, 16+ yrs · built Sistava.com in 3 months, idea to production, using these methods

Resources
Star on GitHubContribute
Donate

Support my work

A small tip keeps the free work coming.

© 2026 Mahmoud Zalt. Free to read, not to republish.
Copyright & license