The failure mode
You had working code. Then a few prompts later, the AI "helped" and now:
This is one of the most demoralizing moments in AI-assisted development because it feels like progress turned into sabotage.
How this problem usually shows up
If you keep going in the same thread, it often gets worse.
Why it happens
This is usually a mix of:
The issue is rarely just "the model is dumb." The issue is that the workflow no longer has a reliable source of truth.
This is especially visible in Cursor, Windsurf, and Cline, where the tools are powerful enough to create big diffs quickly.
What builders get wrong
They try to fix the broken state from inside the broken state
That often creates a second-order mess.
They do not isolate the last known good version
If you cannot identify the last stable point, recovery becomes guesswork.
They ask for more broad cleanup
Once things are drifting, "clean this up" is gasoline.
What to do instead
1. Stop the thread
Do not keep prompting the same broken conversation if the model is already rewriting unrelated code.
Freeze it.
2. Find the last known good state
That may be:
If you do not have one, start making one after every stable milestone from now on.
3. Reduce the bug to one failing behavior
Not:
But:
That is the unit you can actually recover.
4. Open a fresh thread with hard boundaries
Good recovery prompt:
The last good behavior was: when a user signs up, a profile row is created and the dashboard loads. Current bug: signup succeeds but no profile row is inserted. Only inspect these files: app/signup/page.tsx, app/api/signup/route.ts, lib/db.ts. Do not change styling, billing, or other routes.
That is much safer than asking for "fix the app."
5. Review the diff before testing
The model is allowed to propose. It is not allowed to silently decide.
Read the files it touched.
Good-enough recovery flow
This is the practical loop that keeps debugging from turning into repo roulette.
Typical red flags
Those mean you should stop broad prompting and reset the frame.
Related guides
Builder takeaway
When AI starts rewriting working code, the goal is not to win the current thread.
The goal is to restore a trustworthy source of truth and make the next change smaller, clearer, and testable.
That is what turns a panic session back into engineering.