How to Fix Bugs When Building with AI
Most AI debugging goes wrong the same way: vague reports, patched symptoms, and a third attempt at the same fix. Here is a routine that breaks the loop.

Key takeaways
- Give the agent evidence, not theories: the exact steps, what you expected, what happened, and the error text or a screenshot.
- Sort the bug first. Visual, logic, data access and backend bugs each have a different best source of evidence.
- Two failed fixes for the same bug is the signal to stop patching, switch to Plan mode and ask for the root cause, or restore the last good version.
To fix a bug in an app you are building with AI, give the agent hard evidence (the steps to reproduce it, what you expected, what happened and the exact error), let it fix that one thing, then check the result yourself. If the same bug survives two attempts, stop asking for fixes and ask for the cause instead. That routine solves most bugs in one or two turns.
What follows is that routine in detail, plus where to find evidence for each kind of bug in Startbase, and the moments when going back is faster than going forward.
Step one: sort the bug before you report it
Bugs in AI-built apps fall into five families. Naming the family tells you where the evidence lives.
- Crash or blank screen. The app does not render, or shows a white page. Evidence: the error in the preview. In Startbase, an error count appears under the preview and opens the preview console, and a Fix it for me button sends the error details straight to the agent.
- Visual bug. Something renders, but wrong: overlapping text, a button off screen on phones, a missing image. Evidence: a screenshot, or a drawing on the preview marking the spot.
- Logic bug. The app runs but does the wrong thing: totals off by tax, a filter that ignores one category, a timer that skips. Evidence: specific inputs and outputs.
- Data access bug. Lists are empty for some users, saves silently fail, someone sees data they should not. Evidence: which user, which role, which record. These are often access rules (row level security) rather than screen code.
- Backend bug. Emails that never send, payments that never confirm, scheduled jobs that do nothing. Evidence: the logs in the Backend tab, which have their own Fix with AI button on a failing event.
Step two: write a bug report the agent can act on
The agent reads your code, but it was not watching when the bug happened. A good report recreates that moment. Four parts, every time: where, what you did, what you expected, what happened.
On /checkout, signed in as a regular customer on a phone-sized screen: I add two items, apply the code SPRING10, and press Pay. I expected the total to drop by 10 percent before payment. Instead the total stays the same and the code field shows “Applied” in green. No error appears in the console. Fix only the discount calculation; do not change the checkout layout.
Notice what that report avoids: a guess at the cause. “I think the state is not updating” sends the agent down your theory. Describing the behavior lets it read the code and find the real cause, which is often somewhere you would not look.
Step three: let the agent verify, then verify yourself
The Startbase agent tests its own fixes: it opens the app in a real browser, reads runtime errors and failed requests, can tap buttons and fill in forms, and runs type checks, lint and a production build before finishing. The turn receipt says whether checks passed and which files changed.
That catches a lot, but not everything. The agent tests the scenario it understood. You still repeat your original steps, exactly, in the preview. If you described a bug for signed-in customers on phones, check it signed in, on the phone view. Open View diff on the receipt when you want to see what changed line by line.
The two-strike rule: when to stop patching
The most expensive pattern in AI debugging is the loop: fix fails, ask again, a slightly different fix fails, ask again. Each attempt adds code, and some of it stays even when it did not help. After two failed attempts on the same bug, change approach.
- 01Switch to Plan mode. Plan mode is read-only: the agent can read files, logs and context but cannot edit anything. Ask: “What is the root cause of this bug? List what we already tried and why each attempt did not work.”
- 02Ask for a plain-English explanation. If you understand the cause, you can judge the fix. “Explain why the list is empty for team members but not for the owner.”
- 03Approve one targeted fix. When the plan makes sense, Build this plan runs it. Or switch back to Build and request the specific change.
- 04Or go back. If the fixes have piled up, restore the version from before the bug appeared. Restoring saves your current files as a version first, so nothing is lost. Then re-request the original feature with what you learned.
The docs page on versions, undo and revert shows each of these controls, and our guide to checkpoints explains how to use them as a habit, not an emergency exit.
Symptom fixes versus root-cause fixes
A crash because a value is empty can be “fixed” by checking for empty and showing nothing. The crash stops. The bug does not: the value should never have been empty. When a fix looks like a guard, ask the follow-up question.
“You added a check so the page no longer crashes when the profile is missing. Why is the profile missing for new users in the first place? Fix that instead, and keep the check as a fallback.”
Data access bugs are where this matters most. An empty list for team members might be fixed by loosening an access rule until everyone sees everything, which turns a bug into a security hole. Ask the agent to state the rule in plain words (“members see projects they belong to”) and confirm it matches what you want. Our article on whether AI-generated code is safe covers how to test access as an attacker would.
Three tricky cases and how to handle them
It works in the preview but not after publishing
Publishing builds a snapshot of the project at that moment. If you fixed something after publishing, the live site does not have the fix until you republish. Check that first. If it is still broken, describe both environments to the agent: what works in the preview and fails on the published address.
The bug only happens sometimes
Intermittent bugs need a pattern. Note when it happens: first load only, after sign-in, on slow connections, with more than a certain number of items. Give the agent every pattern you saw, and ask it to add logging around the suspect area so the next occurrence leaves evidence.
A feature silently does nothing
No error, no result: typical of emails, jobs and server functions. Open Backend, Logs, find the failing event and use its Fix with AI button, or paste the line into chat. Missing secrets are a common cause, and the agent can see which ones the function expects.
Fewer bugs next time
- Change one thing per message, so when something breaks you know which change did it.
- Name what must not change in every request near working code.
- Put lasting rules (roles, flows that must keep working) in project knowledge, which the agent reads on every turn.
- Bookmark versions that work well, so the last good state is one click away.
More request shapes for debugging are in 12 prompt patterns for building apps, and the docs collect ready-made recipes on the debugging prompts page.
Frequently asked questions
Why does the AI keep making the same mistake?
Usually because it is fixing a symptom and the cause is elsewhere, or because earlier failed attempts left code behind. After two failed fixes, ask for the root cause in Plan mode, or restore the version from before the bug and try again with a clearer request.
Should I fix bugs myself in the code editor?
You can. Edits in the Code tab apply immediately and the agent sees them on its next turn. For most people, a clear bug report to the agent is faster, but a one-word typo fix by hand is fine.
What if fixing one bug breaks something else?
Use Undo on that turn's receipt to roll back to before it, then repeat the request with a fence naming what must keep working. View diff shows exactly which files the fix touched.
Where do I find error messages in Startbase?
Errors in the running app show as a count under the preview that opens the preview console. Backend errors from functions, emails and jobs are in the Backend tab under Logs. Both have a button that hands the error to the agent.

