Debugging AI Code Systematically
In Phase 1 you fixed a bug by reading the error. But some bugs do not announce themselves. The app just… does the wrong thing. No red text, no crash.
Those need a method, because guessing does not scale.
The method
1. Make it happen on purpose. Write down the exact steps that trigger it. "It's broken sometimes" is not something anyone can fix — not you, and not the AI. If you cannot reproduce it reliably, that is the first problem to solve.
2. Cut the search in half. The bug lives somewhere between "I clicked" and "wrong thing appeared". Find the halfway point and check whether the data is still correct there. Whichever half it went wrong in, repeat. A few rounds of this finds almost anything.
The simplest tool for this is printing values as the code runs, so you can see what is actually in there:
console.log("about to save:", taskText);
Unglamorous, and it is what professionals reach for first.
3. Check what you assumed. Nearly every stubborn bug is a wrong assumption. You assumed the list had items. You assumed the text was a number, when it was the word "5". You assumed the thing on screen existed when the code ran. Print it and find out.
4. Change one thing. Then run. If you change three things and it starts working, you have learned nothing, and one of those changes may have quietly broken something else.
The silent kind
The worst bugs make no noise at all — a save that does not save, a filter quietly returning nothing, an error caught and thrown away. Nothing looks wrong until much later, when the data is gone.
When something "does nothing", assume there is a message and you are not looking where it went: the browser console first, then the terminal window where your app is running.
What to do when you are truly stuck
- Explain it to someone. Out loud, to a person or a pet. Describing the problem in full sentences solves a genuinely surprising share of bugs before you finish.
- Go back to the last version that worked. If you have save points (the next stage), this is easy and takes seconds.
- Rebuild the piece. After two failed fixes, patching is usually the wrong move.
- Sleep on it. Not a joke. Fresh eyes beat another hour almost every time.
Go deeper
The specific failure patterns AI code repeats are cataloged in 8 Common Bugs in AI-Generated Code, and the no-noise kind in Silent Failures in AI Code.
Video deep dives for this stage
Official showcase
Community picks
No videos for this stage yet.