Skip to content

Fix P2002 race in concurrent origin registration#927

Merged
onchainlu merged 1 commit into
mainfrom
fix-origin-upsert
May 25, 2026
Merged

Fix P2002 race in concurrent origin registration#927
onchainlu merged 1 commit into
mainfrom
fix-origin-upsert

Conversation

@onchainlu
Copy link
Copy Markdown
Contributor

@onchainlu onchainlu commented May 25, 2026

Summary

  • Pre-creates origin rows outside interactive transactions before concurrent resource registration
  • Fixes unique constraint violation (P2002) on resourceOrigin.upsert() when multiple resources from the same origin (e.g. stableschedule.dev) register concurrently
  • Top-level Prisma upserts use native INSERT ON CONFLICT, which is safe from the race that interactive transactions hit (SELECT → INSERT race)

Context

Reported via Discord: registering stableschedule.dev (8 resources, 1 origin) fails on 2 resources with Invalid prisma.resourceOrigin.upsert() invocation: Unique constraint failed on the fields: ('origin'). The same origin works fine on mppscan.

…tration

When multiple resources from the same origin register concurrently,
each transaction's resourceOrigin.upsert() can race — two see no row,
both try INSERT, second gets a unique constraint violation. Pre-creating
origin rows outside transactions uses native INSERT ON CONFLICT, which
is safe from this race.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402scan Ready Ready Preview, Comment May 25, 2026 9:33pm

Request Review

@onchainlu onchainlu merged commit f95c360 into main May 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant