Skip to content

feat(entities): a contract fixup must name the release it became safe after - #474

Merged
athvin merged 1 commit into
mainfrom
bm/bluegreen-p12-contract-guard
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/bluegreen-p12-contract-guard

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

fixups.rs is the escape hatch for "the operations the declarative reconciler deliberately never performs" — and the reconciler never performs them because they break an older reader. So a fixup is exactly where the expand/contract discipline either holds or quietly doesn't, and until now nothing checked.

The registry now forces a decision

Every fixup carries a Kind. The registry can't be appended to without classifying the entry, and Contract can't be written without naming the catalog hash of the release that stopped reading the thing:

variant meaning
Safe additive, or data-only
Contract { after } the contract half; gated on after
ContractUngated { why } destructive but predating the guard

The decision is pure, and that's deliberate

contract_allowed(after, history, current) needs no database, because the decision is the part worth testing:

  • after is in the ledger's history → allow. The store passed through the release that stopped reading the thing, so at some point only code that ignored it was serving.
  • The history holds nothing but the current catalog → allow. The store was born on this release; there's nothing older to protect, and refusing here would break every fresh install — which is how a guard like this usually goes wrong.
  • Otherwise → refuse. There is history, but not the history this fixup needs: the store jumped from something older straight to here.

What it proves is the store's history, not the absence of old pods. Keeping one version serving at a time is the deploy's job — which, with the colour dimension (#461), is what a cutover does. That limit is stated in the doc comment rather than implied.

Observed refusing, against a real Postgres

By registering a contract fixup naming a catalog the store had never seen:

er-server migrate: fixup 9999_demo_refusal removes something the release before
deadbeefcafe still reads, and this store has no record of deadbeefcafe —
deploy that release first

Three things that observation pins down:

  1. It refused before reaching the fixup's body. The demo entry had no body and would have panicked unreachable if the guard had let it through — so the ordering is proven, not assumed.
  2. The same demo on a fresh store was allowed, which is the branch that protects first installs.
  3. The registry test fired on the unreviewed entry, so appending without reviewing fails locally rather than in a cluster.

0003_per_dataset_locks is labelled honestly

Declared ContractUngated with its reason, not Safe. It does drop the superseded org-level locks and the retired tenant_schema_states UNIQUE — but it shipped with the dataset switchover and is already applied everywhere, so there's no release boundary left to gate on. A test asserts the reason is more than a token, because an empty one would make the variant indistinguishable from Safe.

Three smaller things

  • entities/schema_migration/read/history.sql is a declared statement, because every persistent query here is. Control-store reads must return: entity (the typed column list is lake-read-only in this phase), so it reads the rows and the distinct hashes are collected in Rust — once, outside the loop, since the advisory lock means the ledger cannot change under us.
  • schema::control_catalog_hash() is the Postgres sibling of the existing lake_catalog_hash().
  • Kind::Contract carries #[allow(dead_code)] with its reason, because it deliberately ships before its first user — a guard added alongside the first removal could not have gated it. #[expect] was tried first and does not work here: an expectation must be fulfilled in every compilation, and the variant is dead in the lib target while the unit tests construct it, so expect errors "unfulfilled" on the test target.

Verification

  • make check green — 9 fixups unit tests.
  • The live refusal and fresh-store observations above, against a real Postgres.
  • entities-index.md regenerated for the new declared statement (245 → 246).

Independent of the colour stack — Rust and entities/ only — so this bases on main and can merge in any order.

🤖 Generated with Claude Code

… after

`fixups.rs` is the escape hatch for "the operations the declarative reconciler
deliberately never performs" — and the reconciler never performs them because
they break an older reader. So a fixup is where the expand/contract discipline
either holds or quietly does not, and until now nothing checked.

Every fixup now carries a `Kind`, which means the registry cannot be appended
to without classifying the entry, and `Contract` cannot be written without
naming the catalog hash of the release that STOPPED READING the thing:

    Safe                       additive or data-only
    Contract { after }         the contract half; gated on `after`
    ContractUngated { why }    destructive but predating the guard

`contract_allowed(after, history, current)` is pure, and separated from the
query for that reason — the decision is the part worth testing and it needs no
database:

- `after` is in the ledger's history -> allow. The store passed through the
  release that stopped reading the thing, so at some point only code that
  ignored it was serving.
- the history holds nothing but the current catalog -> allow. The store was born
  on this release; there is nothing older to protect, and refusing here would
  break every fresh install, which is how a guard like this usually goes wrong.
- otherwise -> REFUSE. There is history, but not the history this fixup needs:
  the store jumped from something older straight to here.

What that proves is the store's HISTORY, not the absence of old pods. Keeping
one version serving at a time is the deploy's job — which, with the colour
dimension, is what a cutover does. Said plainly in the doc comment rather than
implied.

**Observed refusing, against a real Postgres**, by registering a contract fixup
naming a catalog the store had never seen:

    er-server migrate: fixup 9999_demo_refusal removes something the release
    before deadbeefcafe still reads, and this store has no record of
    deadbeefcafe — deploy that release first

It refused BEFORE reaching the fixup's body — the demo entry had no body and
would have panicked `unreachable` if the guard had let it through, so the
ordering is proven rather than assumed. The same demo on a FRESH store was
allowed, which is the branch that protects first installs. And the registry
test fired on the unreviewed entry, so appending without reviewing fails
locally rather than in a cluster.

`0003_per_dataset_locks` is declared `ContractUngated` with its reason, not
`Safe`. It does drop the superseded org-level locks, and labelling it honestly
is the point: it shipped with the dataset switchover and is already applied
everywhere, so there is no release boundary left to gate on. A test asserts the
reason is more than a token, because an empty one would make the variant
indistinguishable from `Safe`.

Three smaller things:

- `entities/schema_migration/read/history.sql` is a declared statement, because
  every persistent query here is. Control-store reads must `return: entity`
  (the typed column list is lake-only in this phase), so it reads the rows and
  the distinct hashes are collected in Rust — once, outside the loop, since the
  advisory lock means the ledger cannot change under us.
- `schema::control_catalog_hash()` is the Postgres sibling of the existing
  `lake_catalog_hash()`.
- `Kind::Contract` carries `#[allow(dead_code)]` with its reason, because it
  deliberately ships BEFORE its first user — a guard added alongside the first
  removal could not have gated it. `#[expect]` was tried first and does not
  work: an expectation must be fulfilled in EVERY compilation, and the variant
  is dead in the lib target while the unit tests construct it, so `expect`
  errors "unfulfilled" on the test target.

Verified: `make check` green, 9 `fixups` unit tests, plus the live refusal and
fresh-store observations above.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit c7bea82 into main Nov 5, 2026
35 checks passed
athvin added a commit that referenced this pull request Nov 5, 2026
…ent statement adds (#483)

`main` fails its own `skills-check`: the generated reference says 246 declared
statements and the tree has 247. Reproduced on `origin/main` directly, so it is
not a branch artifact.

Neither contributing PR could have caught it. #460 (datasets PR8a) and #474
(the contract guard's `schema_migration/read/history`) each added a declared
statement and each regenerated the count against a `main` that had 245 — so
both landed holding 246, and the sum is 247. `main` is `strict: false`, which
means a PR merges on a green it earned against a base that may since have
moved; this is exactly the combination failure the merge bus was built to
prove, and neither PR was in a batch.

One line, no behaviour. The drift check runs inside the REQUIRED
`fmt + clippy + docs` job, so every PR opened against `main` inherits the
failure until this lands.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants