Skip to content

chore: squash the platform migrations into one baseline per capability before launch - #503

Merged
allisonmahmood merged 8 commits into
mainfrom
chore/squash-migrations-before-launch
Oct 3, 2026
Merged

allisonmahmood merged 8 commits into
mainfrom
chore/squash-migrations-before-launch

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Before launch (#416) no database we need to keep exists, yet the platform record carried 15 migrations, and several tests and code paths existed only to upgrade databases built by older steps (decision O1 from the test audit). This squashes each capability into one baseline that builds exactly today's schema, and deletes the upgrade-only code and tests with it.

  • One baseline per capability, ids 1–8 in foreign-key order: companies, auth, patches, company_database, runtime, integrations, limits, execution. The names drop _baseline, so an old ledger can never match the new history by name.
  • Faithfulness proof (run outside the repo, /tmp/lane-e-proof): databases built from main's record and from this record have identical pg_dump --schema-only, identical data apart from the ledger, and an identical catalog listing (columns, defaults, constraints, indexes, functions, triggers, grants). That holds for the platform database, a Postgres company inventory and a PGlite company directory.
  • The ledger guard (packages/sql): migrate now refuses a ledger whose history differs from the record's, up to the lower of the two highest ids. The Migrator only applies ids above the ledger's highest, so a pre-squash database would otherwise silently skip the baselines and every future migration with an id up to 15. Ids above the record's highest still pass, so an older build can start after a newer one migrated (the rollback in OPERATIONS.md). The dev runner now writes the refusal to dev.log.
  • Removed upgrade paths: Inventory.upgrade and its calls in both ensureReadys, the mutation-key lookup's missing-table retry (added in feat(runtime): make server mutations atomic and safe to retry #432 for databases created before mutation keys), and the upgrade-only tests: runtime and patches migrations.test.ts, the directory migration block, two inventory-upgrade tests, and an orphan-sweep case for retained inventories. Docs: DEVELOPMENT.md, packages/sql README and CONTEXT (new Baseline term), ADR-0003/0009/0012, product.md, API.md.

After this merges:

  • Every existing local dev instance, in every worktree, needs pnpm dev reset, which wipes its local data. An instance that isn't reset refuses to start and says why in dev.log.
  • The disposable tier 2 spike database needs recreating before its next deploy.
  • patchy dev data in patch repos made by a CLI older than feat(primitives): let patches look up and assign company members #449 needs patchy dev reset.

Upgrade tests start again with the first migration that has to keep retained state.

Made by Claude Opus 5.5 via Claude Code

allisonmahmood and others added 7 commits October 3, 2026 05:04
The Migrator only runs ids above the ledger's highest and never backfills,
so a database migrated by another history (one from before a squash, or a
branch's own steps) would silently skip steps. migrate now compares the
ledger with the record up to the lower of their highest ids, inside the
Migrator's locked transaction, and fails with a BadState MigrationError
that names the id, both steps, and `pnpm dev reset`. Ids above the
record's highest pass, so an earlier build can still start after a newer
one migrated.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… steps

Inventory.upgrade existed for company databases created by earlier
inventory shapes; none worth keeping exist before launch. initialize now
creates the whole inventory (uploads, file handle key, object-id lookup,
mutation keys) in its one idempotent pass, and ensureReady leaves ready
placements alone instead of opening a pool to run the checks.

The schema matches the old initialize-plus-upgrade output exactly on
PostgreSQL and PGlite. The upgrade-only tests go; the portable contract
keeps the reinitialization check for the file handle key, inventory and
rows, and the int8 resource revision read-back.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Production has not launched, and the fifteen platform steps carried
backfills and upgrade tests for databases that only exist in dev and the
disposable spike. Each capability now has one baseline, ids 1 to 8 in
foreign-key order (companies, auth, patches, company_database, runtime,
integrations, limits, execution). They produce exactly the schema the old
record did: pg_dump and a catalog listing of both match apart from the
ledger rows.

The new names differ from every old step's, so a pre-squash database
fails the ledger check at id 1 and its developer runs `pnpm dev reset`.
The upgrade-only tests for runtime, patches and the company directory go
with the steps; the record's id test stays. Docs say when upgrade tests
come back.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The supervisor runs detached with its output discarded, so when migrate
failed (now including a ledger from before the squash) `pnpm dev` said
"see dev.log" and dev.log said nothing. The supervisor now writes the
migration error there, including the `pnpm dev reset` advice.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The case dropped patchy.mutation_keys to model a company database from
before mutation keys and relied on ensureReady to recreate it. Inventory
upgrades are gone with the squash, so the sweep no longer calls
ensureReady first: its placements come from listReady and are ready.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
#432 added it for company databases created before mutation keys: a 42P01
on the key lookup ran ensureReady, whose inventory upgrade created the
table, then read again. The upgrade is gone with the squash. withCompany
only opens ready placements, and a placement turns ready only after
Inventory.initialize created mutation_keys, so the retry could only repeat
the same failing read. A missing table now answers SourceUnavailable
directly, as it did after the retry.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The squash removed the lifecycle migration, and with it any patch deleted
before it, so the note about legacy deleted ids describes nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:primitives Patch tables and files area:integrations Company connections and integration implementations size:xl Over 1,000 changed lines; review in multiple passes labels Oct 3, 2026
That cleanup was an inventory upgrade step and went with them in the squash.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, read-only): one minor finding, now fixed.

  • Spec: no findings. It compared all eight baselines and the company inventory DDL against the old chain statement by statement and found them faithful. It agreed with the proof artifacts, which differ only in ledger rows. The guard's edge cases (empty ledger, fresh database, ledger ahead, gaps), its transaction and lock ordering, the server/dev/vitest wiring, and the removed upgrade paths all checked out.
  • Standards, minor: ADR-0009 still described the retained adopted-upload cleanup, which was an upgrade step. Fixed in 0e2b724.

@allisonmahmood
allisonmahmood merged commit 55ff7df into main Oct 3, 2026
11 checks passed
@allisonmahmood
allisonmahmood deleted the chore/squash-migrations-before-launch branch October 3, 2026 03:17
allisonmahmood added a commit that referenced this pull request Oct 3, 2026
#504)

The test suite had grown expensive without growing more useful. A
whole-repo audit (seven area reviews plus an independent Codex pass and
a discussion round) found three patterns:

- **The CLI tests were two thirds of offline test time.** Most of that
went on tables of pure-function cases, each one spawning the bundled CLI
and often a real Vite build.
- **`cli-smoke` spent about 4 minutes testing its own harness** (Windows
command lookup in a script that refuses Windows, port retries, temp-dir
cleanup) before the real end-to-end run.
- **Tests that add nothing:** duplicates of stronger tests, tests of
Effect Schema rather than our code, tests pinning features that were
removed, exact-copy assertions, and padded matrices.

This removes or moves them, keeping every behaviour that only those
tests proved.

**What changed**
- **Ownership between layers.** Unit tests (stubbed instance) own CLI
mapping, formatting and exit codes. The packed e2e owns "the installed
artifact works against a real server", one representative path per
journey. Its discovery flow, `--json` ladder, no-key and login-resume
blocks are gone. It keeps the real foreign-share refusal and the login →
logout → key refused proof.
- **Pure checks run in-process.** HTML bundle inspection, page-import
syntax, description sync and the definitive publish refusals (now
`Api.isDefinitivePublishRefusal`, tabled over the whole ADR-0004 list)
run in-process. A few CLI rows stay to prove each check is wired into
the real publish and dev builds.
- **`cli-smoke`.** The three probe modes are replaced by one
`--cleanup-check`: an orphaned process group that ignores SIGTERM is
killed, its port closed and its temp root removed. It takes under a
second. Along the way, `cleanup()` no longer sits up to 15 s after PASS
(a race timer was never cleared).
- **Fleet controller-state cases run over in-memory tasks** whose
supervisors fence epochs. Real processes stay for fencing, adoption,
draining, metering, the fleet budget and one real watchdog kill. The
other breaker kills are synthetic reports through the real collection
path.
- **Browser.** The Firefox project and the manual-only `@print` test are
gone (Chromium desktop is the supported browser). The members tier 2
test runs on a 1 s reconcile tick. `subscriptions-recovery` deliberately
keeps 30 s, because its long interval is what proves writes arrive
through NOTIFY. The CSV codec table moved to `csv.test.ts`.
- **Removed outright:** feature-deletion tests and the dead `/d/*`
route, Effect Schema round trips, same-engine duplicates (including
offline copies of races `postgres-concurrency` owns), the
openability-seam tests, PGlite legs that check nothing PGlite-specific,
and Supervisor wall-clock upper bounds that fail under load.

**Effect (this machine, full offline suite with the gap-tests PR on
top):** 1,625 → 1,537 tests, 1,494 s → 1,033 s cumulative test time,
test-phase wall 173 s → 101 s. The longest file is 101 s instead of 140
s. Locally `packed-cli-e2e` goes from 162 s to 109 s, plus the ~4 min of
probes CI ran first. This PR alone is 110 files, +5,173 / −10,040.

Coverage gaps the audit found are filled in the stacked PR. The
migration squash is #503.

Made by Claude Opus 5.5 via Claude Code

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:integrations Company connections and integration implementations area:primitives Patch tables and files area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant