fix(world-postgres): throw EntityConflictError on duplicate run_created#2983
Merged
VaguelySerious merged 1 commit intoJul 17, 2026
Merged
Conversation
`events.create` with a `run_created` event inserts the run with
`onConflictDoNothing()`, so a run that already exists resolves with
`{ run: undefined }` rather than signalling the conflict. `start()`
asserts on that field and throws "Missing 'run' in server response for
'run_created' event", even though the run is healthy and already
running.
This is the race `start()` documents: it fires `events.create` and
`world.queue()` in parallel, and when the worker dequeues first,
`run_started` on the not-yet-existent run takes the resilient start
path and creates the run itself. `start()` already treats
`EntityConflictError` as benign, but the Postgres world never gives it
one — world-local throws it, and world-vercel surfaces a 409 that maps
to it.
Throwing before the event insert also stops a duplicate `run_created`
landing in the event log.
Signed-off-by: Joey Hotz <joeyhotz1@gmail.com>
🦋 Changeset detectedLatest commit: 9e0319e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
@joeyhotz is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
Pinging @vercel/workflow |
VaguelySerious
approved these changes
Jul 17, 2026
github-actions Bot
added a commit
that referenced
this pull request
Jul 17, 2026
…ed (#2983) Signed-off-by: Joey Hotz <joeyhotz1@gmail.com>
Contributor
|
Backport PR opened against |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
events.createwith arun_createdevent inserts the run withonConflictDoNothing(), so when the run already exists the insert returns no row andcreateresolves with{ run: undefined }instead of signalling the conflict.start()asserts on that field and throwsMissing 'run' in server response for 'run_created' event— even though the run is healthy and already running.This is the race
start()documents: it firesevents.create(run_created)andworld.queue()in parallel, and when the worker dequeues first,run_startedon the not-yet-existent run takes the resilient start path and creates the run itself.start()already treatsEntityConflictErrorhere as benign ("we can safely return", expected in<=1%of cases) — but the Postgres world never gives it one.world-localthrows it for this same race andworld-vercelsurfaces a 409 that maps to it;world-postgresis the only world that resolves silently.Throwing before the event insert also stops a duplicate
run_createdlanding in the event log.Observed on a self-hosted Postgres deployment on 3 of 261 runs (~1%, matching the estimate above) of our highest-frequency workflow over 7 days: each affected run has two
run_createdevents and completed normally, while the trigger that started it returned a 500.How did you test your changes?
Two cases added to
packages/world-postgres/test/storage.test.ts(runs›create):rejects a duplicate run_created with EntityConflictError— the direct conflict.rejects run_created when resilient start already created the run— reproduces the production race (run_startedon a non-existent run → resilient start → laterun_created), asserting exactly onerun_createdremains in the event log.Both resolve instead of rejecting against the current insert, and pass with the fix.
pnpm --filter @workflow/world-postgres exec vitest run test/storage.test.ts(119 tests)pnpm --filter @workflow/world-postgres typecheckbiome check packages/world-postgres/src/storage.ts packages/world-postgres/test/storage.test.tsPR Checklist - Required to merge
pnpm changesetwas run to create a changelog for this PRgit commit --signoffon your commits)@vercel/workflowin a comment once the PR is ready, and the above checklist is complete