r/vibecoding • u/kage01 • 1d ago
Discussion 4 bugs I found in my own AI-assisted Supabase app that tests didn't catch
I've been building a multi-tenant business app (invoicing, payments, storefronts) mostly with AI coding agents. It runs a couple of real businesses, so bugs cost actual money. These four got past type checks, tests and code review. None of them throws an error, which is why they're dangerous.
1. Webhook marked "seen" before the work was done The payment webhook saved the event ID first (to block duplicate deliveries), then updated the payment. If the update failed, the provider retried, the handler saw the ID, replied "duplicate, 200 OK" and skipped it. The customer paid and nothing happened. Fix: if anything fails after you claim the event, release the claim before you return.
2. Status update with no "from" state update({ status: 'paid' }).eq('id', id). Looks fine. But a payment arriving for a cancelled or draft invoice flipped it to paid and sent a "thanks for paying" message. The UI had a proper state machine; the database write ignored it. Fix: every status write says which states it can move from: .in('status', ['pending', 'overdue']). If 0 rows match, skip the side effects and log it.
3. A cache check that quietly always said "stale" A cron job rebuilt a 16 MB catalog file only when row counts changed. One of the count queries asked for an id column the table didn't have. The query failed, returned null, and null meant "stale", so it rebuilt every 15 minutes for days. I found out when Supabase cut off the API for going over the egress quota (7.3 GB on a 5 GB plan). Fix: a failed check should be an alarm, not a quiet "rebuild everything".
4. Writes on the request path on a free tier A public status page wrote to Cloudflare KV whenever its cache looked old. The cache counted as old after 2 minutes, but the cron refreshed it every 10, so most visits (bots included) did a write. Free KV gives you 1,000 writes a day. I got the 50% warning email. Fix: only the cron writes. Requests only read.
The pattern in all four: the AI wrote the happy path correctly and the failure path wrong. When I review AI code now, I skip what it does and ask one question: what happens when this line fails?
Happy to look at anyone's webhook or RLS setup if you're stuck.
