fix(server): heal skipped 045 and warn on migration slot collisions #9312
main fromrefs/pull/9312/head·opened View on GitHubFix #8896
Databases whose journal already occupied ID 45 (forks, nightlies, renumbered branches) silently skip 045_ProjectionProjectsAutoPull: effect's Migrator only runs IDs above the highest recorded one and never compares names. Every project query then fails with no such column: auto_pull and the backend crash-loops at startup without opening a window — the migrator half of #8896, reproduced again by nightly 0.0.39 after #9277.
This adds idempotent repair migration 047 (047_EnsureProjectionProjectsAutoPull) that adds the column only when absent, so it heals affected databases and is a no-op everywhere else. It also logs a loud non-fatal warning naming collided slots on every runMigrations — the production counterpart of the hard failure in scripts/migrate-dev-db.ts. Deliberately non-fatal: refusing to start would brick databases that are otherwise healed (e.g. by this repair migration).
Tests: new 047_EnsureProjectionProjectsAutoPull.test.ts encodes the collision (journal claims 45 under another name, column absent) plus the healthy no-op case; neighboring migration tests (027, 040–042, 046) still pass, typecheck and lint/fmt clean.
Built and verified with OpenCode + Muse Spark.
Note
Medium Risk Changes SQLite schema repair at startup and migration journal behavior; low blast radius (one column, idempotent) but affects every database boot and could mask other slot collisions via warnings only.
Overview
Addresses startup crash-loops when projection_projects.auto_pull is missing because migration 045 was never applied: Effect’s migrator treats any journal row at ID 45 as “done,” so a fork/nightly that claimed slot 45 under another name permanently skips the real ProjectionProjectsAutoPull migration (#8896).
Adds 047_EnsureProjectionProjectsAutoPull, an idempotent repair that adds auto_pull only when absent (no-op on healthy DBs). Registers it in the migration manifest and wires warnOnMigrationSlotCollisions into runMigrations so production logs a non-fatal warning listing slots where the journal name disagrees with this checkout—loud visibility without refusing startup, since repair migrations can still heal the schema.
New tests simulate the collision (fake journal row at 45, column missing) and confirm healing plus repeat-run safety, plus the healthy no-op path.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7464886e7021bc04d4493b76ecae1bb8f269d283. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).Note
Add migration 047 to heal skipped 045 and warn on slot collisions#
- Adds migration 047 to idempotently add the
auto_pullcolumn withNOT NULL DEFAULT 0toprojection_projectsif it is absent, repairing databases that skipped migration 045. - Introduces
warnOnMigrationSlotCollisionswhich compares journal entries ineffect_sql_migrationsagainst the current manifest and emits a non-fatal warning if slot names differ. - Behavioral Change:
runMigrationsnow logs a warning when existing migration journal rows use different names for the same numeric slot.
📊 Macroscope summarized 7464886. 2 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues#
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -116,3 +118,4 @@116118 [44, "ClearAutomaticProjectModelDefaults", Migration0044],117119 [45, "ProjectionProjectsAutoPull", Migration0045],118120 [46, "RepairAutomaticSettlementTimestamps", Migration0046],121+ [47, "EnsureProjectionProjectsAutoPull", Migration0047],
🟠 High
persistence/Migrations.ts:121Databases whose journal already has migration ID
47or a later foreign migration never executeMigration0047, leavingprojection_projects.auto_pullabsent and causing project queries to fail at startup. BecauseMigrator.makeskips every loader entry withcurrentId <= latestMigrationId, this repair must run outside the max-ID-gated migrator path (or otherwise explicitly handle collided journals).🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/persistence/Migrations.ts around line 121: Databases whose journal already has migration ID `47` or a later foreign migration never execute `Migration0047`, leaving `projection_projects.auto_pull` absent and causing project queries to fail at startup. Because `Migrator.make` skips every loader entry with `currentId <= latestMigrationId`, this repair must run outside the max-ID-gated migrator path (or otherwise explicitly handle collided journals). Approvability#
Verdict: Would Approve
Macroscope's review found this PR approvable — This is a bounded production schema-repair change with an idempotent additive migration, targeted collision warning, and dedicated tests. A remaining High-severity scenario leaves the repair ineffective for databases already recorded at migration 47 or later, so that gap must be addressed before the change can be safely accepted.
Not approved because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
Note: GPT-6 on behalf of shivam (@shivamhwp).
Please move the collision diagnostic ahead of pending migrations, while handling a fresh database with no journal. It currently runs only after
run()succeeds. With migrations 1–40 applied and foreign journal entries 41–49, current main's migration 050 fails on missinglinked_pull_request_json, so startup exits without the collision warning.The repair also needs a fresh migration ID when rebasing: main already assigns 047 to
ProjectionProjectIconand has migrations through 050. More broadly, a repair stored in the same numbered journal can itself be skipped if a foreign build has already claimed that ID or a higher one. Cover that case when deciding how to run the repair.Please describe this as partial coverage of #8896. Adding
auto_pulldoes not restore the missing auth/thread columns or address the unknown event types from the original report.juliusmarminge added labelsmacroscope-review
Note
Written by
claude-opus-5-5on behalf of MariaHi! We are cleaning up open PRs, and this one does not say which model or harness was used to create it. If this change is really important, we recommend rebuilding the PR with a newer model and noting the model and harness in the PR description.
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed