Skip to content

Apply the coordinator schema as goose migrations - #1328

Merged
Gajesh2007 merged 10 commits into
masterfrom
feat/store-goose-migrations
Oct 6, 2026
Merged

Gajesh2007 merged 10 commits into
masterfrom
feat/store-goose-migrations

Conversation

@davidtai

@davidtai davidtai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The coordinator currently replays its schema DDL on every startup. This change uses numbered Goose migrations, records successful versions in goose_db_version, and serializes pending upgrades with a PostgreSQL advisory lock. An unchanged database skips completed migrations on later starts.

Required schema changes now fail closed: the baseline no longer catches every SQL exception. A refused or timed-out statement leaves that version pending and prevents startup from accepting an incomplete schema. Four pre-create usage statements retain only their necessary undefined_table handling.

Linear: DBLM-552.

Before

flowchart TD
  A["NewPostgres"] --> B["migrate: replay schema statements on every boot"]
  B --> C["Run backfill guards and index helpers"]
  C --> D["Serve requests"]
  B --> E["Broad exception handler hides failed ALTER"]
  E --> F["Startup can continue with a missing column"]
  G["Second coordinator starts"] --> B
  classDef process fill:#dbeafe,stroke:#2563eb,color:#172554
  classDef risk fill:#fee2e2,stroke:#dc2626,color:#450a0a
  classDef outcome fill:#fef3c7,stroke:#d97706,color:#451a03
  class A,B,C,G process
  class E,F risk
  class D outcome
Loading

After

flowchart TD
  A["NewPostgres"] --> B["migrate / migrateOnce: Goose Provider.Up"]
  B --> C{"Pending versions?"}
  C -- "No" --> D["Serve requests"]
  C -- "Yes" --> E["Acquire advisory lock and recheck versions"]
  E --> F["Apply ordered SQL and Go migrations"]
  F -- "Success" --> G["Record completed version"]
  G --> D
  F -- "SQL lock timeout" --> H["Bounded retry; failed version stays pending"]
  H --> B
  F -- "Other error / retries exhausted" --> I["Return startup error"]
  classDef process fill:#dbeafe,stroke:#2563eb,color:#172554
  classDef success fill:#dcfce7,stroke:#16a34a,color:#052e16
  classDef failure fill:#fee2e2,stroke:#dc2626,color:#450a0a
  classDef retry fill:#fef3c7,stroke:#d97706,color:#451a03
  class A,B,C,E,F process
  class D,G success
  class H retry
  class I failure
Loading

Blue denotes control flow, green successful state, amber bounded retry, and red failure. The retry loop permits three total attempts; it does not repeat indefinitely.

Migration layout and compatibility

Version Responsibility
1 Historical schema baseline and existing one-time data-repair markers; unexpected SQL errors propagate
2 Retired-backfill guard
3 Provider restore indexes
4 Provider earnings job index
5 Provider earnings window index
6 Consumer charge settlements from current master
7 Legacy MDM cohort schema from current master
8 Small-model interest schema from current master
9 Concurrent Stripe refund-reference index from #1352

Review and regression coverage

Fresh reviewers examined the full implementation and repository structure. A separate fresh refactor pass corrected documentation structure and ownership; no broad runtime rewrite was warranted. A fresh final reviewer then examined the complete integrated diff.

  • A real PostgreSQL regression removes a required legacy column, holds a table lock, and verifies failed migration does not record version 1. It then releases the lock and verifies the next startup restores the column. The test failed against the original broad exception handlers and passes after the fix.
  • A frozen pre-Goose schema fixture is separate from the evolving target schema. Tests cover fresh databases, pre-Goose upgrades, and upgrades already recording versions 1–5, preserving existing marker/counter rows.
  • Concurrent-startup and lock-retry tests exercise actual PostgreSQL connections. Invalid Stripe refund indexes prevent version 9 from being marked complete.
  • Profile projection checks inspect the migrated catalog instead of requiring future columns to be added to the immutable baseline.
  • Documentation-impact tests cover SQL migration files and registered Go migration helpers.
  • The expand/contract guide now keeps old-column reads authoritative until legacy writers are retired and values reconciled. It preserves compatible dual writes and fallback versions through the later read switch and column removal.
  • Two pre-existing fixture failures surfaced in full CI and are repaired without runtime changes: the Qwen3.8 catalog fixture waits for the initial desired_models registration frame before setting verified state, and the enrollment CLI expectation includes the current eligibility notice while retaining its process-exit and no-network assertions. Fresh refactor and correctness reviews cover these follow-up changes.

Validation

All database validation used disposable local databases, never production.

  • make coordinator-test with local PostgreSQL 16: complete coordinator suite and runner guards passed (112.7 seconds for the suite).
  • make coordinator-build coordinator-build-linux: host and Linux/amd64 builds passed.
  • golangci-lint run ./coordinator/... using v2.1.6 and Go 1.25.7: zero issues.
  • Focused PostgreSQL 16 migration, index and profile tests: passed, including the before/after negative control and invalid-index gate.
  • PostgreSQL 17 migration/upgrade/concurrency/profile tests: passed (17.8 seconds); --migrate-only also passed during schema generation.
  • python3 scripts/test-docs-impact-check.py: 13 tests passed.
  • make docs-impact-check BASE=origin/master, make docs-check (337 files), and whole-PR git diff --check: passed.
  • go mod verify: all modules verified.
  • Catalog fixture follow-up: 200 race-enabled repetitions and the complete catalog contracts package passed. A deterministic probe demonstrated the original registration race before the fix.
  • Enrollment fixture follow-up: native Swift evaluation against the captured macOS 27 CI output passes with the corrected expectation and fails with the original. The final provider unit-test CI run also passes, including the full Swift CLI suite.

Final-head remote validation: CI and Integration Tests passed for b08a7b74ebc37d13dfdcf98f99442f3c6674eb72. Approval and gated benchmark status remain separate.

Operational considerations

The first production cutover executes pending schema work and still needs the documented backup, lock inspection, schema verification, and separately approved deployment. Goose does not make DDL or index construction cost-free. No production database, service, or deployment was changed during this review.

There are no down migrations. Application rollback must follow the documented schema-compatibility rules; pre-Goose fallback images can replay legacy DDL. New schema changes belong in new numbered migrations, with the target schema snapshot regenerated afterward.

Replace the boot-time DDL loop in PostgresStore.migrate with pressly/goose
v3. Version 1 is the 255 statements the loop ran, unchanged and in order,
outside a transaction. Versions 2 to 5 are the retired-backfill guard and
the three concurrent index builds, with their code unchanged. Goose records
each version in goose_db_version and holds a session advisory lock, so a
second coordinator applies nothing. The migration session sets
lock_timeout 3s and statement_timeout 10min, and migrate retries a lock
timeout up to three times.

Check in the pg_dump of the pre-goose schema as
coordinator/store/schema/schema.sql. Tests prove that goose builds that
schema on a fresh database, leaves a legacy database unchanged apart from
goose_db_version, applies once under two concurrent runners, and retries a
lock timeout.

goose v3.28.0 needs Go 1.26 and the coordinator image builds with Go 1.25,
so this pins v3.27.3 and raises the go directive to 1.25.7.

Refs DBLM-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head b08a7b74ebc3 against base cc1362378235.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
normal spending limit reached; remaining coverage deferred

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 87/325 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.4793 reported, $0.0000 reserved with unknown cost; 4 paid request(s), 5 reused batch(es), 60291 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

docs-check treats an inline-code repo path as a citation; the placeholder
file name failed Docs Lint.

Refs DBLM-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

A CREATE INDEX CONCURRENTLY in an SQL migration that fails (for example
on the 3 s lock_timeout) leaves an invalid index; with IF NOT EXISTS the
next attempt skips it and goose records the version. The how-to now
shows index builds as Go migrations through ensureConcurrentIndex, and
TestSQLMigrationsDoNotBuildIndexesConcurrently fails on an SQL file that
builds one.

Docs: destructive migrations must wait until no pre-goose fallback image
can start; migrations and the baseline repairs run once; the startup
diagram shows the unlocked pending check before the advisory lock; the
5 min lock wait and the fail-safe first deploy under long reads.

Refs DBLM-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docs/architecture/schema-lifecycle.md as the explanation of how the
schema changes: the startup path from NewPostgres through goose, the
migration kinds, the locks and timeouts, the retired-backfill guard,
invariants, failure modes and a code map. storage.md now links to it
instead of holding the migration mechanism.

Rewrite docs/developer/database-migrations.md around a decision table,
steps for each migration kind, expand and contract in two releases, and
the pre-goose fallback rule.

Add docs/operations/schema-migration.md: scope, Cloud SQL backup, long
query check, --migrate-only with its real log lines, verification
queries, troubleshooting, rollback rules and the first cut-over
checklist. coordinator-deploy.md links to it.

Refs DBLM-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blacksmith-sh

blacksmith-sh Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Found 5 test failures on Blacksmith runners:

Failures

Test View Logs
TestIntegration_AttestationHeaders View Logs
TestIntegration_ConcurrentRequests View Logs
TestIntegration_ReferralRewardDistribution View Logs
TestIntegration_SwiftProviderRealRoutingGates View Logs
TestProfile_SingleProviderNonStreaming View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Replace the copied row-scan loops in TestMigrationsLeaveLegacyDatabaseUnchanged
with queryLines, and rename assertSameSchema to assertSameLines because it
also compares row lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai added a commit that referenced this pull request Oct 4, 2026
Takes the base's index-validity refactor and #1328's queryLines and
assertSameLines migration test helpers. No conflicts; this branch adds
index versions 19 and 20 only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port the goose migration runner onto the #1324 layout.

- The runner moves to coordinator/store/postgres/migrations.go and
  replaces the boot-time statement slice there. The SQL baseline and the
  pg_dump move to coordinator/store/postgres/schema/. The baseline is
  unchanged: its 255 blocks equal, byte for byte, the statements that
  master's migrate executes on a fresh database (pgx trace of master and
  of the old merge base are identical).
- The DDL constants that only the old slice used are deleted, including
  the internal cachemigrations package, privacysql and
  profilesql/schema.go; tests read those statements from the baseline.
- The migration tests and their harness (baselineStatement,
  forgetMigrationVersions, replayMigrations, loadSchemaFile,
  schemaSnapshot, queryLines, assertSameLines) move to
  coordinator/tests/store/postgres/ and use NewPostgres through the
  fixture. TestConcurrentMigrationsApplyOnce now holds the goose advisory
  lock while two coordinators start, so it fails at once when the runner
  does not take the lock.
- The DAR-349 dedupe guard also scans the SQL migrations.
- Docs and the docs-impact rules use the new paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai added a commit that referenced this pull request Oct 5, 2026
Bring in master's coordinator layout through the ported #1328 head.
The sqlc layer moves next to the Postgres backend: sqlc.yaml, queries/
and the generated storedb package live in coordinator/store/postgres/,
and the api_keys adapter replaces coordinator/store/postgres/apikey.go.
storedb is regenerated with sqlc v1.31.1 and is byte-identical.
TestAPIKeyLifecycleOnEveryBackend moves to coordinator/tests/store/contracts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 6, 2026 12:02am UTC
d-inference-console-ui-dev Ready Ready Preview Oct 6, 2026 12:02am UTC
d-inference-landing Ready Ready Preview Oct 6, 2026 12:02am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 6, 2026 12:02am UTC

Request Review

@vercel

vercel Bot commented Oct 5, 2026

Copy link
Copy Markdown

Deployment failed for project darkbloom-status with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: darkbloom-status.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@jonathan308 jonathan308 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking findings at b08a7b7.

Read-only review covered the full diff and startup call paths, baseline/schema parity, version ordering/bootstrap, advisory locking, transaction boundaries, retries/idempotency, historical markers/backfills, concurrent-index validity, and rollback documentation, with three independent focused reviews. Existing exact-head CI and integration runs passed; the PostgreSQL 16 CI artifact confirms the migration/upgrade/concurrency/retry regressions passed. No builds, tests, migrations, or production queries were run during this review. PostgreSQL 17 validation is author-reported, not independently rerun.

Remaining evidence gaps: E2E Benchmarks is waiting; darkbloom-status preview failed for Vercel permissions; the advisory threat review is incomplete due to its spending limit. Lock-session loss during a separate Go-migration connection is not covered by the concurrency tests.

For the later ORM rollout, land and stabilize #1328 first and renumber stacked migrations after version 9. After soft-deleted duplicate identities are possible, require fallback application read/write compatibility as well as Goose boot compatibility; #1328's unfiltered identity reads alone are not a safe soft-delete fallback guarantee.

@Gajesh2007
Gajesh2007 merged commit dccc9ee into master Oct 6, 2026
34 of 36 checks passed
@Gajesh2007
Gajesh2007 deleted the feat/store-goose-migrations branch October 6, 2026 00:35
jonathan308 added a commit that referenced this pull request Oct 6, 2026
Master is at dccc9ee (#1328 goose migrations, #1352, #1351, #1355, #1344). No conflicts. The merge brings master's submodule pin libs/mlx-swift-lm e407e899 (a formatting-only commit on top of 1ee8675a).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai added a commit that referenced this pull request Oct 6, 2026
Brings in master through #1328 (goose migrations, store in
store/postgres/), #1344, #1351, #1352 and others.

Conflicts:
- ci.yml (Report coverage): master inlined the empty-profile,
  coordinator-row and statement-format checks (#1252). This PR moved
  the same checks into scripts/coordinator-statement-coverage.sh,
  which ci.yml and integration.yml both call. Keep the script call.
- docs/developer/test.md (coverage command): keep the script call.
- docs/developer/test.md (CI workflow map): keep master's ci.yml row
  (adds the provider coverage table) and this PR's integration.yml row
  (adds the e2e coverage row and artifact).

The #1284 store contract tests and coverage tests build and vet
against master's store layout with no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

4 active deployments
Preview – d-inference-console-ui-dev — b08a7b74 Deployed Oct 6, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — b08a7b74 Deployed Oct 6, 2026 by vercel[bot]
Preview – d-inference — b08a7b74 Deployed Oct 6, 2026 by vercel[bot]
Preview – d-inference-landing — b08a7b74 Deployed Oct 6, 2026 by vercel[bot]
benchmarks — b08a7b74 Deployed Oct 6, 2026 by Gajesh2007 via E2E Benchmarks #2303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants