All guidesDeep-dive articles
On this page

Supabase race condition study

31 Race-Condition Defects in 18 Supabase Apps From 120 Public Repos

By Ohad Krispin, founder of VibeRaven ยท LinkedIn

In short

In November 2026, VibeRaven loaded 120 pinned public Supabase repositories, ran 963 two-request checks in 78 of them, and found 31 race-condition defects in 18 apps. All 41 broken orders across 22 repositories reproduced on native PostgreSQL 18.6, and code review found that 14 of the 18 affected apps had a defect reachable through their own screens.

Updated 2026-11-21

November 2026 update. The study used a VibeRaven development build with automatic rule inference and schema completion. That build has yet to be published on npm.

Study funnel

Both runs used the same 120 repositories at the same pinned commits, with 80 in the working cohort and 40 held out. A check is a pair of SQL requests tested in multiple orders. One finding records a check with a broken order.

First and second runs across both cohorts
StageFirst runSecond run
Pinned repositories120120
Schemas loaded without a hand-written spec50120
Schemas that needed schema completionUnavailable71
Repositories with a candidate rule3497
Repositories with a completed check2778
Two-request checks completed256963
Checks enabled by gate dataUnavailable234
Broken orders (repositories)6 (5)41 (22)
Broken orders reproduced on native PostgreSQL641
Defects confirmed by code review (apps)6 (5)31 (18)
Apps with a defect reachable from a screen214
Scenarios that could not run481 of 740 (65%)1,553 of 2,558 (61%)

Other broken orders

The remaining 10 broken orders also reproduced on native PostgreSQL. Code review put them outside the defect count for two reasons.

  • Harmless or valid outcomes included a different valid generated value and a repeated toggle that left the intended state intact.
  • Some SQL differed from the function used in production, or the reconstruction could not apply a later function patch.

An invite can be accepted twice

Two people can both see a one-use invite as available before either acceptance is saved.

Fix by claiming the unused invite with one conditional update and recording the acceptance in the same transaction only when the update returns a row.

SQL
UPDATE demo_invites SET claimed_at = now()
WHERE id = $1 AND claimed_at IS NULL
RETURNING id;

A reward can be granted twice

Two grant requests can both see that the reward is missing and both create it.

Fix by enforcing a unique reward key and crediting the reward in the same transaction only when the insert returns a row.

SQL
INSERT INTO demo_rewards (grant_key) VALUES ($1)
ON CONFLICT (grant_key) DO NOTHING
RETURNING grant_key;

A bonus can be paid twice or a fee charged twice

Two requests for the same event can both pass the check for an existing payment or charge and both change the balance.

Fix by giving each event and entry type a unique ledger key and changing the balance in the same transaction only when the ledger insert succeeds.

SQL
INSERT INTO demo_ledger (event_key, kind, delta)
VALUES ($1, $2, $3)
ON CONFLICT (event_key, kind) DO NOTHING
RETURNING delta;

A balance can go below zero

Two debits can each pass a balance check using the same starting balance, then together spend more than the account has.

Fix by checking available funds in the debit itself and declining the request when the update returns no row.

SQL
UPDATE demo_balances SET amount = amount - $2
WHERE id = $1 AND $2 > 0 AND amount >= $2
RETURNING amount;

Parallel calls can bypass a rate limit

Two requests can both count recent activity before either records its own request, letting more requests through than the limit allows.

Fix by atomically incrementing an existing counter for the caller and time window only below the cap, and allowing the request only when the update returns a row.

SQL
UPDATE demo_limits SET used = used + 1
WHERE bucket_key = $1 AND used < cap
RETURNING used;

A counter can lose an update

Two requests can read the same count and each save that count plus one, so the total only rises once.

Fix by incrementing the stored counter in the same transaction as the event it counts.

SQL
UPDATE demo_counters SET total = total + 1
WHERE id = $1;

How we tested

We pinned each public repository to a commit. Loaded means the offline runner assembled enough of the schema from committed migrations and related source files to inspect it. Some loads used offline extension stubs. A loaded schema can still contain functions the runner cannot exercise.

Schema completion is a fallback for migrations that do not replay as written. It applies working statements, uses evidence such as later migrations, committed SQL and generated types to repair missing pieces, and records every repair and skip. Findings record which repairs they depend on.

The runner inferred candidate rules from SQL and seeded synthetic users and rows. Gate data supplies the test roles, memberships or row states required by the SQL. Under Read Committed, the runner compared overlapping orders with both one-at-a-time orders for the same pair of requests. A broken order left a committed state that matched neither baseline after ignoring volatile values such as timestamps and generated IDs.

We replayed every reported broken order in an isolated container running native PostgreSQL 18.6. We then reviewed the pinned SQL and traced its callers in app source to assess whether the outcome was a defect and whether a screen could reach it. The final review found zero false results among the 41 reported orders.

Two false alarms in an intermediate run came from schema completion. One rebuild missed a unique key and another created a table where committed SQL defined a view. Both were caught in SQL review and fixed before the final run.

What the study could not test

In the second run, 61% of generated scenarios (1,553 of 2,558) could not exercise both requests. The first request could be refused by the function or blocked by a row-level security policy, change no rows, depend on an unavailable object, or hit a unique key. Other scenarios errored separately, and some repositories reached the analysis time limit.

The study covers bounded SQL orders on synthetic data and offline schemas. Browser flows, races in application code and live row-level security policies were outside the run. Screen reachability comes from reading the source. These counts describe the tested corpus and cannot establish how common race defects are across Supabase apps.

Check your own app

VibeRaven 1.12.1 was tagged latest on npm when checked in November 2026. The published commands below use a bundled example or a spec you write. The example intentionally reports a broken order.

For your own local check, create viberaven.race.json with a rule, two SQL requests and an assertion that returns true when the rule holds. Review the setup and migrations, then run the spec from the project root. If it finds a broken order, use the printed replay command to confirm it and rerun the spec after your fix.

Terminal
npx -y viberaven@1.12.1 race --example

# In your app repository, with your reviewed spec
npx -y viberaven@1.12.1 race --spec viberaven.race.json

Sources