Three bugs that show up again and again in AI-built apps. For each one: what the founder sees, the root cause, a before/after fix, and an automated test that fails on the broken code and passes on the fix.
Same 7 automated tests run against both versions. Run on 02 Dec 2026 (Europe/Vienna), Node v24.22.1, local Postgres via PGlite 0.6.1 (Postgres compiled to WASM). No hosted services involved.
| Test | Before | After | Error on the broken code |
|---|---|---|---|
| Bug 1: user sees their own todos | FAIL | PASS | expected Alice's 2 todos, got 0 |
| Bug 1: user creates a todo and reads it back | FAIL | PASS | 42501: new row violates row-level security policy for table "todos" |
| Bug 1 guard: no other users' rows, no spoofed inserts, anon sees nothing | PASS | PASS | fix must not open the table |
| Bug 2a: filter matches the stored status value | FAIL | PASS | expected 2 active sample projects, got 0 |
| Bug 2b: dashboard loads after the session is restored | FAIL | PASS | expected 2 projects after login, got 0 |
| Bug 3a: StrictMode plus double click sends exactly 1 webhook request | FAIL | PASS | n8n received 4 requests |
| Bug 3b: a 504 after processing is retried without a duplicate | FAIL | PASS | webhook failed (no retry, no idempotency key) |
Test 2b fails on the broken code for two reasons at once (the wrong filter from 2a and the session timing).
new row violates row-level security policy (42501)." Everything works in the Supabase table editor, because the service role bypasses RLS.Root cause: the policies compare auth.uid() with the row's primary key id instead of the owner column user_id, for both USING (read) and WITH CHECK (insert).
create policy "Users can view their own todos"
on public.todos
for select to authenticated
using (auth.uid() = id);
create policy "Users can create todos"
on public.todos
for insert to authenticated
with check (auth.uid() = id);create policy "Users can view their own todos"
on public.todos
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "Users can create their own todos"
on public.todos
for insert to authenticated
with check ((select auth.uid()) = user_id);(select auth.uid()) lets Postgres evaluate the function once per statement instead of once per row. A guard test confirms the fix did not open the table: other users' rows stay invisible, spoofed inserts are rejected, and anonymous users see nothing.
Two typical root causes:
.eq('status', 'Active'), but the column stores active. eq is case-sensitive, so nothing matches.anon, RLS correctly returns [], and nothing refetches after sign-in.// 2a: "Active" never matches "active"
const { data } = await client
.from('projects')
.select('id,name,status')
.eq('status', 'Active');
// 2b: runs once on mount, before the
// session exists
useEffect(() => { load() }, [])// 2a: one typed source of truth that
// matches the DB check constraint
type ProjectStatus = 'active' | 'archived';
.eq('status', 'active' as ProjectStatus)
// 2b: wait for the session, reload when
// the auth state changes
useEffect(() => {
if (session) load()
}, [session?.user.id])In the repo the React hook is reproduced by a small lifecycle stand-in; the logic under test is the same: never query user data until a session exists, and reload on onAuthStateChange.
Root cause: the POST is sent from a useEffect(..., []) in a component that mounts after submit. React StrictMode (dev) mounts components twice, so the effect runs twice. The button also stays clickable, so a double click doubles it again: the test measured 4 requests for one double click. There is no idempotency key, so the receiver cannot tell duplicates apart.
// rendered after submit; effect runs
// twice in StrictMode
function SubmitSender({ values }) {
useEffect(() => {
fetch(WEBHOOK_URL, {
method: 'POST',
body: JSON.stringify(values),
})
}, [])
return null
}
// button never disabled, no retry,
// no idempotency key// send from the submit handler, once
async function onSubmit(values) {
if (submitting.current) return
submitting.current = true
key.current ??= crypto.randomUUID()
try {
for (let i = 1; ; i++) {
const res = await fetch(WEBHOOK_URL, {
method: 'POST',
headers: { 'Idempotency-Key': key.current },
body: JSON.stringify({
...values,
idempotency_key: key.current,
}),
})
if (res.ok) { key.current = null; return }
if (i >= 3 || res.status < 500) throw new Error('failed')
}
} finally { submitting.current = false }
}
// <button disabled={submitting}>n8n side (recommended in addition): right after the Webhook node, store the key with a unique constraint and stop if it already exists:
insert into webhook_events (idempotency_key, payload)
values ($1, $2)
on conflict (idempotency_key) do nothing
returning idempotency_key;
-- IF node: no row returned -> duplicate -> stopThis SQL runs on PGlite in the test suite via a mock receiver. It was not tested against a running n8n instance.
I do not need your passwords or your service-role key. A GitHub invite and a Supabase project invite (or a dedicated test user) are enough.