Skip to content

feat(datasets): the switchover — every tenant surface moves under its dataset (PR6) - #415

Merged
athvin merged 1 commit into
mainfrom
bm/datasets-p6-switchover
Nov 2, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/datasets-p6-switchover

Conversation

@athvin

@athvin athvin commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

PR6 of the datasets program (PR1 #380, PR2 #381, PR3 #383, PR4 #392, PR5 #396): the switchover. Old org-scoped lake routes are REMOVED (the sanctioned clean break); er-openapi-check breaking advisories are EXPECTED on this PR.

The dataset stops being a stamped column and becomes the address. Backend: 56
lake and control-plane handlers widen to Path((org, ds)) behind
dataset_or_404 + refuse_unless_active_dataset; the session trio, delivery
preconditions, golden/auto-merge opens and the dispatcher's model resolution
all read the DATASET env; 58 route literals and the utoipa doc paths move
under /v1/orgs/{org}/datasets/{ds}/, with org routes keeping only identity,
keys, audit, webhooks and the tag vocabulary. Tag APPLICATION moves with the
lake (subjects are lake-local ids); the vocabulary stays org-wide.

Frontend: the BFF directory moves wholesale (34 dirs, 70+ route files) onto
requireDatasetAccess/datasetPath, pages move to (tenant)/[org]/[ds]/
with the settings surface split (config studio + models are the dataset's;
members, profile, webhooks, AI and audit stay the org's, one SettingsNav
splitting hrefs so it still reads as one surface). Dataset context flows
through useDatasetSlug() (URL param, default fallback) rather than prop
threading, and every dataset-scoped query key re-roots as
["org", org, "ds", ds, …] — the signature break is what enumerated the
sweep: 260 type errors burned down to zero, no call site left guessing. A
minimal switcher sits in the top bar; org-switch, login and impersonation land
on /{org}, which redirects to default/dashboard until the management
phase's real dispatcher.

The widget token gains a REQUIRED d claim: mint embeds the dataset, verify
refuses a payload without it, so a pre-dataset token dies at claim parsing
even though its HMAC still verifies — the unit test reproduces the module's
key derivation with a positive control so that refusal can never be mistaken
for a bad signature. erweb rows the BFF writes (saved views, segments, review
recommendations) now carry their dataset column instead of leaning on the
migration default.

Four bugs only this PR's gates could surface, all fixed here:

  • Publish repointed only the org. pg::publish_config_version moved
    orgs.active_config_version and never the dataset row, so every
    dataset-scoped read (dataset_active_config, delivery preconditions)
    answered "no published config" the moment the routes switched. It now takes
    the dataset id and moves both pointers.
  • The dispatcher's webhook detail_path pointed at a removed route. The
    entity-event aggregate now names /datasets/{ds}/runs/…/entity-events,
    resolved from the job's dataset.
  • A live older store could not boot. The baseline replay runs before the
    reconciler, and the dataset indexes it now carries reference columns the
    reconciler has not added yet — on any pre-dataset control plane (the dev
    stack's volume was one) ensure_schema died with column "dataset_id" does not exist, because IF NOT EXISTS skips an existing INDEX, not a missing
    COLUMN. The replay now defers undefined-column statements under a savepoint
    and replays them strictly after reconcile; pg_schema_replay.rs ages a
    store back to the pre-dataset shape and proves one boot heals the whole
    distance — the migration proof the plan asked for.
  • Provisioned orgs kept a forever-provisioning dataset. The converge
    copies the org's state at creation — provisioning — and nothing ever
    flipped the dataset when the provision job promoted the org, because until
    now nothing READ dataset state. The dispatcher's activate step now takes the
    default dataset along under the same expected-state guard, and
    pg_provision asserts it; the full-stack tier caught this as every fresh
    tenant rendering "Setting up…" forever.

Supporting changes: the pg test tier addresses the dataset routes (257 path
lines over 27 files); pg::ensure_org converges the default dataset the way
the create-org handlers do, while upsert_org_byo deliberately does not (the
sweep's own test needs an unconverged org) — below-HTTP fixtures use the new
pg::converge_default_datasets + pg::merge_dataset_envs; the migrate-tenants
sweep labels converged tenants org/dataset. Contracts regenerated in the §9
order (envelopes.json, er-mcp/tools.json, the reshaped mock with per-dataset
lake keying and GET /datasets[/{ds}] fixtures); openapi.json is schemas-only
by design, so the route move leaves it byte-identical. kill-servers.sh now
also sweeps 3200 — the e2e config adopts a reused server as-is, and a
nine-day-old next start once served an entire tier run. The e2e suspend spec
polls the engine's own view of the org before asserting the 409: asserting in
the UI-flip window once enqueued a real train on a tenant the operator had
just frozen. All 42 visual baselines
regenerated in the pinned container (the dataset label reaches every
rail-bearing screen); regeneration needs two consecutive identical captures,
so update-baselines.sh now runs with a scoped 30s expect budget — webkit's
full-page shots of the longest screens overran the default 5s there while the
ordinary single-capture compare fits it comfortably.

Known interim, closed by the clean-break phase's re-key: config / models /
schedules / labels PG lists are still org-scoped in SQL (the jobs list and
dispatcher model resolution are dataset-filtered). Two datasets of one org
share those lists until the natural keys flip.

Verification

  • make check green on the rebased commit (fmt, clippy, doc, entities-check, skills-check, 91 test binaries)
  • Gated pg tier (DEDUPE_E2E_DUCKLAKE=1 + ER_TEST_PG_DSN): 90 passed / 0 failed, including the new pg_schema_replay migration proof
  • make check-e2e legs: dedupe-cli + er-cli + er-entity-diff all green
  • Frontend: eslint 0, prettier clean, tsc 0, authz gate 94/94 handlers, vitest 722 passed, coverage 56.8% vs the 49% floor
  • Playwright functional tier: green across all three projects (557 tests)
  • Visual baselines: 42/42 regenerated in the pinned Linux container
  • Full-stack tier (make frontend-dev + seed + test:e2e:full): 24/24 against the real engine — train, full and incremental runs all through the per-dataset queue

🤖 Generated with Claude Code

… dataset (PR6)

The dataset stops being a stamped column and becomes the address. Backend: 56
lake and control-plane handlers widen to `Path((org, ds))` behind
`dataset_or_404` + `refuse_unless_active_dataset`; the session trio, delivery
preconditions, golden/auto-merge opens and the dispatcher's model resolution
all read the DATASET env; 58 route literals and the utoipa doc paths move
under `/v1/orgs/{org}/datasets/{ds}/`, with org routes keeping only identity,
keys, audit, webhooks and the tag vocabulary. Tag APPLICATION moves with the
lake (subjects are lake-local ids); the vocabulary stays org-wide.

Frontend: the BFF directory moves wholesale (34 dirs, 70+ route files) onto
`requireDatasetAccess`/`datasetPath`, pages move to `(tenant)/[org]/[ds]/`
with the settings surface split (config studio + models are the dataset's;
members, profile, webhooks, AI and audit stay the org's, one SettingsNav
splitting hrefs so it still reads as one surface). Dataset context flows
through `useDatasetSlug()` (URL param, `default` fallback) rather than prop
threading, and every dataset-scoped query key re-roots as
`["org", org, "ds", ds, …]` — the signature break is what enumerated the
sweep: 260 type errors burned down to zero, no call site left guessing. A
minimal switcher sits in the top bar; org-switch, login and impersonation land
on `/{org}`, which redirects to `default/dashboard` until the management
phase's real dispatcher.

The widget token gains a REQUIRED `d` claim: mint embeds the dataset, verify
refuses a payload without it, so a pre-dataset token dies at claim parsing
even though its HMAC still verifies — the unit test reproduces the module's
key derivation with a positive control so that refusal can never be mistaken
for a bad signature. erweb rows the BFF writes (saved views, segments, review
recommendations) now carry their dataset column instead of leaning on the
migration default.

Four bugs only this PR's gates could surface, all fixed here:

- **Publish repointed only the org.** `pg::publish_config_version` moved
  `orgs.active_config_version` and never the dataset row, so every
  dataset-scoped read (`dataset_active_config`, delivery preconditions)
  answered "no published config" the moment the routes switched. It now takes
  the dataset id and moves both pointers.
- **The dispatcher's webhook `detail_path` pointed at a removed route.** The
  entity-event aggregate now names `/datasets/{ds}/runs/…/entity-events`,
  resolved from the job's dataset.
- **A live older store could not boot.** The baseline replay runs before the
  reconciler, and the dataset indexes it now carries reference columns the
  reconciler has not added yet — on any pre-dataset control plane (the dev
  stack's volume was one) `ensure_schema` died with `column "dataset_id" does
  not exist`, because IF NOT EXISTS skips an existing INDEX, not a missing
  COLUMN. The replay now defers undefined-column statements under a savepoint
  and replays them strictly after reconcile; `pg_schema_replay.rs` ages a
  store back to the pre-dataset shape and proves one boot heals the whole
  distance — the migration proof the plan asked for.
- **Provisioned orgs kept a forever-provisioning dataset.** The converge
  copies the org's state at creation — `provisioning` — and nothing ever
  flipped the dataset when the provision job promoted the org, because until
  now nothing READ dataset state. The dispatcher's activate step now takes the
  default dataset along under the same expected-state guard, and
  `pg_provision` asserts it; the full-stack tier caught this as every fresh
  tenant rendering "Setting up…" forever.

Supporting changes: the pg test tier addresses the dataset routes (257 path
lines over 27 files); `pg::ensure_org` converges the default dataset the way
the create-org handlers do, while `upsert_org_byo` deliberately does not (the
sweep's own test needs an unconverged org) — below-HTTP fixtures use the new
`pg::converge_default_datasets` + `pg::merge_dataset_envs`; the migrate-tenants
sweep labels converged tenants `org/dataset`. Contracts regenerated in the §9
order (envelopes.json, er-mcp/tools.json, the reshaped mock with per-dataset
lake keying and `GET /datasets[/{ds}]` fixtures); openapi.json is schemas-only
by design, so the route move leaves it byte-identical. `kill-servers.sh` now
also sweeps 3200 — the e2e config adopts a reused server as-is, and a
nine-day-old `next start` once served an entire tier run. The e2e suspend spec
polls the engine's own view of the org before asserting the 409: asserting in
the UI-flip window once enqueued a real train on a tenant the operator had
just frozen. All 42 visual baselines
regenerated in the pinned container (the dataset label reaches every
rail-bearing screen); regeneration needs two consecutive identical captures,
so `update-baselines.sh` now runs with a scoped 30s expect budget — webkit's
full-page shots of the longest screens overran the default 5s there while the
ordinary single-capture compare fits it comfortably.

Known interim, closed by the clean-break phase's re-key: config / models /
schedules / labels PG lists are still org-scoped in SQL (the jobs list and
dispatcher model resolution are dataset-filtered). Two datasets of one org
share those lists until the natural keys flip.

Co-Authored-By: Claude Fable 5 <[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