𝗛𝗼𝘄 𝘁𝗼 𝗗𝗲𝗯𝘂𝗴 𝗔𝗜 𝗖𝗼𝗱𝗲: 𝟯 𝗙𝗮𝗶𝗹𝘂𝗿𝗲 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀

I built an inventory module with Cursor. The demo looked clean. The client approved it. Then it created duplicate records on every save.

The AI wrote the upsert call. It did not save the record UUID to state. Every save treated the form as a new record.

AI code breaks in three ways.

Wrong Placement AI puts logic in the parent component. It belongs in a helper file. This happens when the conversation context gets too large. Fix: Tell the AI the exact file path in your prompt.

The Happy Path The code works the first time. It fails on the second try. AI assumes clean data and a single interaction. Fix: Run every flow twice before you accept the code.

Stale State AI sets a flag to block a process. It forgets to reset the flag. The second attempt reads the old value. Fix: Look for useState and useRef. Find the missing resets.

Use this checklist for every AI module:

This takes 15 minutes. It saves hours of work.

Source: https://dev.to/sumit2401/how-to-debug-ai-generated-code-3-production-failure-patterns-52g3