fix(world-postgres): create runs and initial events atomically - #4111
Conversation
🦋 Changeset detectedLatest commit: 561ffa1 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 |
|
@komly is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
@vercel/workflow Ready for review. This fixes #3656 with seven real-PostgreSQL regression cases (six fail on the upstream base), a patch changeset, and a verified, DCO-signed commit. |
| ## Features | ||
|
|
||
| - **Durable storage**: Stores workflow runs, events, steps, hooks, and webhooks in PostgreSQL | ||
| - **Atomic run creation**: A new run becomes visible together with its event slot marker and initial `run_created` event, including when a queued `run_started` creates the run. |
There was a problem hiding this comment.
Remove all the changes in this file
There was a problem hiding this comment.
(AI) Reverted in cef47e2. Since that removed the documented WORKFLOW_POSTGRES_URL path, I also rewrote run-creation.test.ts to follow the setup of the other world-postgres integration tests (Testcontainers plus pnpm db:push, in-describe win32 skip). Verified the rewritten file still fails 6/7 on main and passes 7/7 with the fix; the full world-postgres suite (219 tests) passes on the branch.
| '@workflow/world-postgres': patch | ||
| --- | ||
|
|
||
| Create a workflow run, its slot marker, and its first event in one transaction so concurrent execution and interrupted creation cannot observe partial runs. |
There was a problem hiding this comment.
| Create a workflow run, its slot marker, and its first event in one transaction so concurrent execution and interrupted creation cannot observe partial runs. | |
| Fix run creation and slot allocation not happening transactionally |
|
(AI) Pushed cef47e2 addressing the review comments (changeset wording, README reverted, test aligned with the other world-postgres integration tests). Full world-postgres suite passes on the branch (219 tests). Additional validation, not committed: a live creation storm (60 run ids, each hit by 3 concurrent One note, not blocking: run creation now costs BEGIN/COMMIT round trips around the three inserts (5 statements instead of 3 autocommits). Creation-only and the same shape as the existing step_started / step_created transactions. |
Signed-off-by: Dmitry Petrov <Komly@yandex.ru> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Peter Wielander <peter.wielander@vercel.com>
cef47e2 to
561ffa1
Compare
Signed-off-by: Dmitry Petrov <Komly@yandex.ru> Co-authored-by: Peter Wielander <peter.wielander@vercel.com> Signed-off-by: Dmitry Petrov <Komly@yandex.ru>
|
Backport PR opened against |
#4132) Co-authored-by: Dmitry Petrov <Komly@yandex.ru> Co-authored-by: Peter Wielander <peter.wielander@vercel.com>
Description
Fixes #3656.
Create the run row, its slot marker, and the initial
run_createdevent in one transaction at both creation sites. A concurrent writer can no longer observe a new run before its slot identity exists, and a failed initial-event insert rolls back the run and marker. Existing creator-conflict handling is preserved.How did you test your changes?
git diff --checkpassed.The new test file uses Testcontainers by default and accepts an explicit loopback
WORKFLOW_POSTGRES_URLfor local development. It creates and drops only its isolated database. No mocks are added.PR Checklist - Required to merge
pnpm changeset status --since=mainpasses.@vercel/workflowin a comment once the PR is ready, and the above checklist is complete.Diff size
Docs — 2 files ·
+14 / -0Describe the atomic creation guarantee, local test command, and patch release.
Implementation — 1 file ·
+81 / -58Keep both existing creation paths in a transaction through their first event; most of the diff is moving those inserts into the transaction.
Tests — 1 file ·
+169 / -0Use real PostgreSQL locks and constraint failures to verify visibility, rollback, and duplicate creation.