跳到正文
DEV Community· Hey SI team·· 3 小時前AI 評分67

AI 修復陷入循環時,下一次提示詞前先停止重試並逐步排錯

Stuck in an AI fix loop? Do this before the next prompt.

AI 導讀

文章建議,同一項 AI 修復連續失敗兩次後先停止重試,回到最後可用版本或建立儲存點,並記下操作、預期結果、實際結果及完整錯誤訊息。先要求 AI 解釋可能原因和證據、指出最可能涉及的檔案,再一次只改一項並測試;錯誤訊息如含 API key 或密碼,應先以 [REDACTED] 取代。

正文

You know the feeling. Something breaks. You ask the AI to fix it. It says "Fixed!" It isn't. You paste the error again. It apologizes and says "Fixed!" again. Twenty minutes later the original bug is still there, two new ones have shown up, and you can't remember what the app looked like when it worked.

That's a fix loop. No stress: getting stuck in one is normal, and it happens to experienced developers too. It doesn't mean you're bad at this. It means the current approach has stopped working, and it's time to change the approach, not send the prompt a fifth time.

This post works the same whether you build in Cursor, Lovable, Bolt, Replit, or a plain AI chat.

Why fix loops happen

A few things usually go wrong at once:

  • The AI is guessing. If it can't see the real cause, it patches the symptom it can see. Each patch looks reasonable, so it keeps going.
  • The real problem lives somewhere else. The error shows up on one screen, but the cause might be bad data that was saved earlier, a setting, or a different file. The AI keeps editing the file where the error appeared.
  • The chat gets cluttered. Long conversations fill up with old attempts, half-reverted code, and wrong assumptions. The AI starts building on top of its own earlier mistakes.
  • Too many changes at once. When one "fix" touches five files, you can't tell which change helped and which one broke something new.
  • "Still broken" isn't much of a clue. Without the exact error and what you expected to happen, the AI has very little to work with.

Every one of these has a simple counter-move.

The routine: do this before the next prompt

1. Stop

Seriously. Don't send another "it's still broken." A good rule is two strikes, then reset: if the same fix fails twice, you've left fixing territory and entered loop territory. Take a breath. We'll figure it out.

2. Get back to solid ground

Find your last working version. Most tools have a way back: Cursor, Replit, Lovable and Bolt all offer some kind of checkpoint, restore, or version history (the name and location vary, so check your tool's docs). If you use git, your last commit is a save point too.

Rolling back isn't failure. It's often the fastest fix there is. If you're not sure you want to roll back yet, at least make a save point of where you are now, so you can't lose anything while you experiment.

3. Describe what's actually happening

Write down four things in plain words:

  • What you did (clicked, typed, ran)
  • What you expected
  • What happened instead
  • The full error message, copied exactly, plus where you saw it (browser page, browser console, terminal, the tool's preview)

"It's broken" becomes "When I click Save on the add-task form, I expected the task to appear in the list, but the page goes blank and the browser console says TypeError: Cannot read properties of undefined." That's a clue the AI can actually use.

Quick safety note: if the error contains an API key or password, swap it for [REDACTED] before pasting.

4. Ask the AI to explain before it fixes

This is the big one. Ask for the likely cause and the evidence for it without any code. When the AI has to explain its reasoning, it's more likely to notice a wrong assumption, and you get to check whether the explanation actually makes sense.

Here's a prompt for that:

Pause. Don't write or change any code in this reply.

The problem: [ONE SENTENCE, e.g. "new tasks don't show up after I click Save"]
What I did: [STEPS]
What I expected: [EXPECTED]
What happened instead: [WHAT YOU SAW]
Full error message: [PASTE ALL OF IT, WITH ANY KEYS REPLACED BY [REDACTED]]

Please:
1. Explain in plain English what you think is causing this, and why.
2. Tell me what evidence supports that, and what would prove it wrong.
3. If you're not sure, suggest ONE small check (like a log message) to find out, instead of guessing.
4. Tell me which file(s) the real cause is most likely in.
Then wait for me before fixing anything.

5. One change at a time

Once the cause makes sense, ask for the smallest possible fix to that one thing. Then test it yourself. Works? Make a save point right away. Doesn't work? Roll back that one change and tell the AI exactly what happened. One change, one test, one save point.

6. Start a fresh chat with a summary

If the conversation is long and tangled, start over with a clean chat. You don't lose what you learned, because you bring a short summary with you. Ask the old chat to write it first:

We're going to continue this in a fresh chat. Don't write any code.

Write a short handoff note (under 10 lines) I can paste into a new chat. Include:
- What the app is and what part we're working on
- The problem, in one sentence, with the exact error
- What we've already tried and why each attempt didn't work
- What's been ruled out
- The most likely cause we haven't tested yet
- The one next step to try

Paste that note into the new chat, add "Explain your plan before changing any code," and you're back on track with a clear head (yours and the AI's).

7. Try a simpler path

If one feature keeps fighting you, ask: "Is there a simpler way to do this?" Roll back, rebuild that one step more simply, and keep moving. Shipping a smaller version that works beats a fancy version that doesn't.

The short version

  1. Two failed fixes? Stop.
  2. Roll back or make a save point.
  3. Describe: what you did, what you expected, what happened, full error.
  4. Ask for the cause and evidence first, no code.
  5. Smallest fix, test, save point.
  6. Messy chat? Fresh chat with a handoff note.
  7. Still stuck? Find a simpler path.

Our cartoon mascot SI the Yes Bot has a motto for this moment: an error isn't a disaster, it's a clue. You've already got everything you need to read it. Ride the wave. SI's got you. 🌊

Want more prompts like these? Grab the free 5-prompt kit at https://heysi.dev.

來源:DEV Community · dev.to