migration-runner: extend advisory-lock guard to webhook-triggers, routines, workflow-deploy-source - #504
Merged
TheGreatAxios merged 3 commits intoAug 30, 2026
Conversation
5 tasks
…ploy-source migrations Two hub replicas calling these packages' migration runners at once each see no ledger row and race the check-then-insert loop, crashing the loser on a duplicate-key violation (CL-7241). These tests reproduce that race directly against the current implementation and currently fail, matching CL-7211/PR #480's own before/after pattern for the six packages already converted to the shared advisory-lock guard.
…workflow-deploy-source Converts these three packages' migration runners to call @corbits/migration-runner's applyPackageMigrations, exactly as CL-7211 converted the other six (bench, insights, preferences, inference-catalog, evals, access-policy). Closes the same check-then-act race: two hub replicas booting together no longer both see a migration as unapplied and crash the loser on a duplicate-key ledger insert. Schema and ledger table names, and every exported function's name and signature, are unchanged, so this is safe for databases with an already-populated ledger and requires no caller changes.
…-deploy-source under the shared runner shape @corbits/migration-runner's README now reflects all nine ledger tables using the shared advisory-lock guard (six from CL-7211, three from CL-7241), pairwise verified collision-free against a live PostgreSQL 17.11 hashtext(). docs/package-migrations.md's shape-1 package list already named webhook-triggers and routines even before this PR converted them; workflow-deploy-source was missing from that list entirely and is added now that it also uses the shared runner.
TheGreatAxios
force-pushed
the
cl-7241-migration-advisory-lock-rollout
branch
from
August 30, 2026 21:33
29fbd83 to
baf72d1
Compare
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.
Summary
Stacked on migration-runner: shared advisory-lock guard for package migrations #480 (
cl-7211-migration-advisory-lock), which introduced@corbits/migration-runner'sapplyPackageMigrationsand converted six packages to it, fixing a check-then-act race in their migration ledgers.Fixes CL-7241:
@corbits/webhook-triggers,@corbits/routines, and@corbits/workflow-deploy-sourcehad the identical racy shape — aSELECT-then-insert loop with no lock — outside CL-7211's scope. Converts all three to callapplyPackageMigrations, exactly as the six were converted (keep the migrations array + type export, drop the bootstrap/lock/quoteIdentifier boilerplate, thinapplyXMigrationswrapper). Every exported function's name and signature is unchanged, soscripts/db-setup.tsand other callers need no changes, and this is safe for databases with an already-populated ledger (no drops, no truncates, ledger schema unchanged).Adds a "two replicas booting concurrently" test to all three packages' own
test/migrations.test.ts(mirroringpackages/migration-runner/test/migration-runner.test.ts's own concurrency test), each verified to fail against the pre-conversion racy code and pass after conversion. Note: none of the six packages CL-7211 converted got a package-level concurrency test of their own — they rely solely on the sharedmigration-runnerpackage test covering the mechanics generically. Worth a look on migration-runner: shared advisory-lock guard for package migrations #480 since it's the same gap this PR was asked not to repeat; not fixed here since it's out of this PR's scope.Computed
hashtext()for the three new ledger table names against a live local PostgreSQL 17.11 and confirmed no collisions among these three or with the existing six (all nine values distinct). Updatedpackages/migration-runner/README.md's collision note from six to nine verified names, and named the PostgreSQL version tested against.Added
@corbits/workflow-deploy-sourcetodocs/package-migrations.md's "Self-contained, transactional" package list — it was auditing-scope for CL-7241 but missing from that list even though it already used the byte-for-byte identical shape;webhook-triggersandroutineswere already (pre-emptively / inaccurately, pre-conversion) listed there and are now accurate.Minor, non-blocking: converting
webhook-triggersandroutinesdrops theJSON.stringify(...)quoting their pre-existing migration-failure error messages used around the migration name (e.g.migration "0001_routine" failedbecomesmigration 0001_routine failed) —applyPackageMigrationsinterpolates the bare name.workflow-deploy-sourcewas already unquoted pre-conversion, so it's unaffected. Confirmed nothing outsidemigration-runner's own tests parses this string. Flagging since PR migration-runner: shared advisory-lock guard for package migrations #480's own conversions had the same effect on whichever of its six packages used the quoted form.hashtext values (PostgreSQL 17.11)
All nine distinct — no collisions.
Test plan
cd packages/webhook-triggers && bun run typecheck && bun test— clean (37 pass, including new concurrency test)cd packages/routines && bun run typecheck && bun test— clean (272 pass, including new concurrency test)cd packages/workflow-deploy-source && bun run typecheck && bun test— clean (13 pass, including new concurrency test)bunx prettier --checkon touched files — cleanbun run lint— clean (0 errors; pre-existing unrelated warnings)bun run check:structural— clean, includingcheck:licensesgh pr checks) — pendingCL-7241