-
Notifications
You must be signed in to change notification settings - Fork 344
fix(world-postgres): make step creation atomic #3575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VaguelySerious
merged 1 commit into
vercel:main
from
shin4141:codex/v42-atomic-step-created-event
Aug 22, 2026
+188
−34
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@workflow/world-postgres': patch | ||
| --- | ||
|
|
||
| Commit step entities and their `step_created` events atomically. |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI Review: Note
Wrapping the fan-out write in an explicit transaction has a width-dependent cost. N concurrent
step_createdcalls on one run, isolated Postgres 15,pgpoolmax: 30, 3 independent runs of 15 rounds each per side, first round of each run discarded, n=42 per cell:Width 1 is unchanged, so this is not the BEGIN/COMMIT round trips. I read it as contention amplification, though I have not instrumented it to prove the mechanism:
INSERT … ON CONFLICT DO NOTHINGblocks on a conflicting uncommitted row, so the window in which a concurrent slot attempt stalls grows from a single autocommit statement toevent insert → COMMIT. Each stalled writer that returns zero rows re-entersinsertEventRow's retry loop (SLOT_INSERT_BASE_DELAY_MS, doubling pastSLOT_INSERT_IMMEDIATE_ATTEMPTS), so the chain lengthens faster than linearly in width.The existing suite cannot surface this: the harness pool is
max: 1, so every "concurrent" case instorage.test.tsserialises at the driver before it reaches Postgres.Worth deciding explicitly rather than by accident, since fan-out is the hottest
events.createpath in this world. If the cost is unwelcome, a single statement is atomic without an explicit transaction and keeps the blocking window at one statement:The trade-off is that the slot-retry loop then re-runs the step insert too, so distinguishing "row conflict" from "slot retry" needs a follow-up read.