Writing

Prompt Purgatory: How to Stop Re-Prompting the Same Bug

By Scott Wilder · November 21, 2026 · 6 min read · All writing

Prompt purgatory is when you ask an AI coding agent to fix the same bug for the fifth time and every fix breaks something new. The way out is not a better prompt: stop after two failed tries, roll back to the last version that worked, and restart in a fresh session with a short written handoff. By the end you'll have a five-step exit and a card you can paste into every task.

Two failed fixes means you're already in the loop

You know the pattern. The agent proposes a fix. The bug stays, or moves somewhere else. You paste the error back. It apologizes and tries again. Three evenings later you're still on the same login button.

More prompting doesn't help because every retry in that chat starts from a context that already holds the last wrong diff, your corrections and the agent's explanations. The next attempt inherits all of that noise. O'Reilly calls it the rehash loop: the model has run out of useful context and keeps reshuffling what you already gave it. As a session fills with history, stale instructions and failed attempts, output quality drops. That's context rot, and it can start before the window is technically full.

So attempt five in the same chat is usually worse than attempt one. You're not one clever sentence away from the fix. You're digging.

If the thing eating your evenings is a manual chore that should already run itself, email me the one task you want automated and tell me where it keeps breaking.

Set the exit rule before the first prompt

Most setups have no rule that says "if this failed the same way three times, stop." An agent told to finish the task keeps trying, and you keep feeding it because you're mid-problem and tired. Neither of you will call it. So call it before the first prompt, while you still think clearly.

The rule I'd use. It's a habit, not a measured cutoff:

That's four tries total before a human looks at it. On a one-hour evening session, that's the difference between losing one night and losing a week.

The 5-step way out of prompt purgatory

1. Call it at two and stop typing

Count your attempts. Two passes at the same fix with the bug still there means you're in the loop. Don't paste more context into that chat. Extra context adds weight behind the approach that already failed.

2. Roll back to the last version that worked

Don't ask the agent to fix its own fix. Each local fix can break something elsewhere, so you end up stacking patches on a broken base. Restore the last good state instead: a git commit, a backup or a checkpoint.

In VS Code, if you can name the request where things went wrong, restoring that checkpoint returns the affected files and the chat history to that point. No restore point at all? Fix that before your next session: back up the project before an agent edits your files.

One trap. Some Cursor users report that interrupting the agent mid-work reverted everything it had done so far. Find out what your tool does on stop before you hit the button.

3. Write a state file, then open a fresh session

Before you close the stuck chat, write down three things: what is failing, what you've already tried, and what the real goal is. Then start a new session that reads only that file, not the old transcript.

Skip the "tried and failed" list and the fresh session walks you straight back into the same dead ends.

4. Ask for the smallest fix and a way to prove it

Shrink the request to one test, one error, one file. Then ask for a check you can run yourself: a test that passes, a step that reproduces the bug, a before and after. Don't take "done" at face value. Verify the output before you move on.

5. If the small version fails twice, step out of the chat

Two more misses on a small, clean request means the problem is structural or sits somewhere the agent can't see. Stop prompting. Read the error and the code yourself, try a different tool, or ask a person. Once it's solved, write the lesson down where the next session will see it, so you only pay for it once.

Which move fits where you're stuck

If this is true Do this Skip this
You can point to the exact request where it went wrong Restore that checkpoint (files and chat) Asking the agent to undo it by hand
The chat is full of corrections and you can't find the point New chat with the state file only Copying the old transcript across
The fix broke something that used to work Roll back first, then ask again "Fix the thing you just broke"
The agent keeps rewriting code that wasn't broken Name the one file in scope and what must not change Letting it refactor while it debugs
A small, fresh request failed twice Read the code yourself or ask a person Rewording the same prompt again

That fourth row is its own trap, sometimes called the rewrite loop: the agent keeps "improving" working code and adds new breakage each time.

The prompt purgatory exit card (copy this)

Paste this at the top of every task before the first prompt. It fits under the one page task spec if you already use one.

EXIT RULE
- Same fix fails twice: stop, roll back, start a new session.
- Fresh small session fails twice: stop prompting. Read the code or ask someone.

STATE FILE (fill in before closing a stuck chat)
Goal (what "working" looks like):
What must not change:
In scope (one file or function):
What is failing (paste the exact error or test):
Tried and failed:
1.
2.
Last known good version (commit, checkpoint or backup):

FRESH SESSION PROMPT
Read only the state file above.
This specific test is failing: [paste test].
This is the error: [paste error].
The relevant code is [file] lines [X to Y].
Fix only this. Do not touch anything under "What must not change".
Then tell me exactly how to check the fix.

The prompt shape in the last block follows a narrow prompt pattern for stuck sessions. The point is to give the agent less, not more.

Mistakes that keep you in purgatory longer

Tick any you did this week. Each one is a reason the bug is still there.

Your next ten minutes

Open the task you're stuck on right now and count the failed tries. If it's two or more, close that chat. Fill in the state file above, roll back to your last good version, and run one fresh session with the fresh session prompt. Then paste the exit rule into your task spec so the next bug meets the rule before the first prompt.

Name the task that should already run itself

Prompt purgatory usually starts with a job you'd rather never do by hand again. If you've got one of those, email me with the one task you want automated.

Questions

What is prompt purgatory?

It's the loop where you keep asking an AI coding agent to fix the same bug, each fix breaks something else, and days or weeks go by with the problem still there. Other names for it are the rehash loop, the doom loop and the fix loop.

How many times should I correct an AI agent before starting over?

Two. If two corrections on the same issue still miss, close the chat, roll back to the last working version and start a fresh session with a short state file. That's a rule of thumb, not a measured cutoff.

Does starting a new chat lose my files?

No. In VS Code a new chat leaves the old chat history behind but keeps your saved files, custom instructions and memory. Your code stays as it is on disk, which is why you roll back first if the last fixes broke it.

Why does my AI agent keep breaking things when it fixes a bug?

It sees the error in front of it and proposes a local fix, without seeing everything that depends on that code. Each retry in the same chat also carries the earlier wrong attempts forward, so the next fix is built on more noise.

Is it my prompt or the tool?

Usually neither on its own. A cluttered session is the common cause, so test with a fresh session and a narrow prompt first. If a small, clean request fails twice, the problem is likely in the code structure, and that's when you read it yourself or ask a person.

What is context rot?

It's the drop in an AI agent's output quality as a session fills with history, stale instructions, tool output and failed attempts. It can start before the context window is technically full, which is why short, single-task sessions help.