# Breaking bug-fix loops

> Stop repetitive 'fix it' loops from burning credits. Isolate the exact failing layer, choose Ask AI to fix versus Undo checkpoints, and recover fast.

- Canonical: https://exaspark.ai/docs/breaking-fix-loops/

## Why repetitive "fix it" prompts drain credits

Almost every AI app builder hits the same frustrating trap: a screen breaks, so you type `"still broken, fix it."` The patch misses, you type `"try again,"` and five turns later working layouts break while your credit balance drops.

Bug-fix loops are rarely random. Four predictable habits cause almost every spiral:

- **Vague symptom prompts.** Saying `"checkout is broken"` hides the route, user role, HTTP status, and error message, forcing speculative multi-file edits instead of one targeted fix.
- **Stacking patch debt.** After two failed guesses, leftover CSS overrides, duplicate hooks, and half-renamed columns actively collide with the third attempt.
- **Prompting code for config issues.** Rewriting components cannot fix a Preview user signing into Live, an unverified DNS record, or a missing Live Stripe key.
- **Bundling new features while debugging.** Asking to `"fix login AND redesign the header"` muddies verification so you cannot tell which edit broke what.

Escaping a loop takes clean diagnosis rather than repeating louder prompts. Most stubborn bugs resolve in one or two surgical turns once you isolate the failing layer.

## The Two-Strike Rule for stopping loops early

Follow one strict guardrail to protect both code quality and credits: **never run a third blind fix on top of two failed fixes.**

- **Strike 1 (Evidence-first fix).** Click **Ask AI to fix** on any Preview or Publish error banner, or send a crisp four-line bug report naming route, role, steps, and expected vs actual behavior.
- **Strike 2 (Inspect before editing).** If the exact failure remains, pause changes. Check browser DevTools Network status codes, console output, or **Cloud** rows to verify whether the issue is code or config.
- **Hard Stop (Undo to green).** If Strike 2 misses — or breaks another screen — stop patching immediately. Click **Undo** back to your last clean checkpoint and re-attempt the change in one smaller slice.

> **Note:** Every completed Agent turn creates an immutable checkpoint. **1-click Undo** removes tangled patch clutter instantly, whereas typing `"undo your last three tries"` spends credits and often leaves stray overrides behind.

## Choosing the right recovery tool

Reaching for the right tool turns a ten-turn spiral into a 60-second recovery.

| What you observe | Best recovery tool | Why it breaks the loop | Credit impact |
| --- | --- | --- | --- |
| **Red Preview, Publish, or Android error banner** | Click **Ask AI to fix** | Passes exact compiler stack trace or deploy log straight to the Agent | Usually 1 precise turn |
| **Same error fails twice or layout tangled** | Click **1-click Undo** | Restores the exact last verified green checkpoint with zero debt | Zero wasted patch turns |
| **Works in Preview, fails on Live URL** | Inspect **Cloud (Live)**, roles, or **Publish** | Fixes Preview vs Live isolation, Live secrets, or admin roles directly | Zero build turns needed |
| **Wrong logic with zero crash** | **Diagnose-first prompt** + 4-line report | Isolates exact API route or query mismatch before broad edits | Low; avoids blind rewrites |
| **Live production screen broken for buyers** | **Live rollback** in Publish history | Restores production in one click so you debug calmly in Preview | Zero live downtime panic |

Review [Checkpoints & Undo](https://exaspark.ai/docs/checkpoints-and-undo/) and [Working with the Agent](https://exaspark.ai/docs/working-with-the-agent/) to pair checkpoints with log-driven fixes.

## Isolating which of the four layers failed

Spend 30 seconds identifying *which layer* failed before writing a fix prompt. Loops explode when builders prompt for Layer 1 code rewrites while the true cause sits in Layer 3 or Layer 4.

### Layer 1: Build, syntax, or frontend runtime crash

Red banners, blank pages, or console exceptions right after an edit belong here. Click **Ask AI to fix** first; if two tries repeat the same error, click **Undo** and split the feature into two smaller prompts.

### Layer 2: Backend API, database query, or RBAC mismatch

Pages render fine, yet Save does nothing, data disappears on refresh, or an admin gets `403`. Grab the failing endpoint path and status (`400`, `401`, `403`, `500`) from the browser **Network** tab and inspect rows in **Cloud**.

### Layer 3: Environment isolation or workspace config

`"Works in Preview, broken on Live"`, empty Live tables, or invalid Live credentials stem from environment boundaries. **Preview** and **Live** never share databases, user accounts, storage buckets, or Stripe keys — no code rewrite copies Preview data into Live. See [Preview vs Live isolation](https://exaspark.ai/docs/preview-vs-live/).

### Layer 4: External provider settings

Stripe test cards rejected on Live, OAuth redirect errors after adding a custom domain, or unverified email DNS records live inside Stripe, your OAuth console, or your registrar rather than app code.

## Step-by-step protocol to escape an active loop

1. **Protect Live first** — If real visitors are affected, roll back Live in **Publish** history immediately so you can debug calmly in **Preview**.
2. **Clear patch debt via 1-click Undo** — Step back through checkpoints via **Undo** until Preview builds green and core paths work.
3. **Capture clean reproduction evidence** — Trigger the single failing action once and note URL route, signed-in role, HTTP status or banner text, and **Cloud** table state.
4. **Send a narrow diagnose-first prompt** — Ask the Agent to inspect only the failing route or component and explain the root cause before making sweeping edits.
5. **Apply one surgical fix and verify** — Re-run the exact reproduction steps in **Preview**, confirm state persists after reload, and move on cleanly.

## High-signal bug reports and diagnose-first prompts

Replace `"still broken"` with four concrete lines whenever there is no crash banner:

```text
High-Signal Bug Report
- Environment & route:  Preview -> /admin/bookings
- User & role:          Signed in as Admin (qa-admin@example.com)
- Exact steps & error:  Click "Approve" on row #12 -> POST /api/bookings/12 returns 403
- Expected vs actual:   Row should update to "approved" in Cloud; stays "pending"
```

### Prompt 1: Diagnose before making broad edits

> **Example prompt (App):** Do not rewrite unrelated styles or layouts. Investigate why POST /api/bookings/:id returns 403 for a signed-in Admin on /admin/bookings in Preview. Inspect the session helper, admin role middleware, and user role column in Cloud, explain the exact root cause, and apply only the minimal fix needed to authorize admins while keeping members blocked with 403.

### Prompt 2: Clean single-scope rebuild after Undo

> **Example prompt (App):** From this clean checkpoint, implement only booking cancellation on /account/bookings. Add POST /api/bookings/:id/cancel verifying the user owns the booking and starts_at is at least 12 hours ahead, update status to "canceled" in Cloud, and return 200. Do not edit other pages or checkout routes. Verify status remains canceled after page reload.

## Common loop traps and exact escapes

| Recurring loop trap | Why builders stay stuck | Exact escape move |
| --- | --- | --- |
| **CSS layout whack-a-mole** | Repeating `"nudge left / right"` layers conflicting rules | Use **click-to-edit** for local tweaks, or **Undo** and state desktop/mobile layout once |
| **Login redirect loop (401/403)** | Missing Live user, wrong callback domain, or role typo | Check **Cloud** role and active environment first; see [Debug auth & CORS](https://exaspark.ai/docs/debug-auth-and-cors/) |
| **Schema rename crash spiral** | Column renamed while forms or APIs read old name | Undo back, then run one atomic turn aligning schema, APIs, and UI together |
| **Checkout succeeds, plan stays locked** | Editing frontend thank-you page instead of webhook route | Inspect Stripe webhook logs and `user_id` metadata; see [Debug payments & email](https://exaspark.ai/docs/debug-payments-and-email/) |
| **Blank Preview after mega-prompt** | Too many screens and packages changed in one turn | Click **Undo** immediately and rebuild across 2–3 focused verified turns |

## Protecting credits while debugging

Every speculative `"try again"` turn drains credits from your Free daily/welcome pool or Starter/Pro monthly rollover balance without resolving root causes.

Pairing **Ask AI to fix**, **1-click Undo** under the Two-Strike Rule, **click-to-edit** for minor UI tweaks, and crisp four-line reports keeps debugging fast and predictable. See [Optimizing credit usage](https://exaspark.ai/docs/optimizing-credits/) for more habits.

## Next steps

- [Checkpoints & Undo](https://exaspark.ai/docs/checkpoints-and-undo/) — Master instant turn rollbacks and clean workspace recovery.
- [Debug blank screens & builds](https://exaspark.ai/docs/debug-blank-screens-builds/) — Isolate compile failures, missing imports, and runtime crashes fast.
- [Optimizing credit usage](https://exaspark.ai/docs/optimizing-credits/) — Keep every build and debugging turn focused and credit-efficient.

## From the blog

- [Common vibe coding mistakes](https://exaspark.ai/blog/vibe-coding-mistakes/) — Break habits that trigger fragile patches and wasted iterations.
- [What is an AI agent?](https://exaspark.ai/blog/what-is-an-ai-agent/) — Understand how evidence and logs sharpen agent problem-solving.
- [Why AI-built apps stall after launch](https://exaspark.ai/blog/why-ai-built-apps-stall-after-launch/) — Move smoothly from debugging prototypes to calm operations.
