Skip to content

feat(datasets): the control plane stops sharing — reads and writes scope to the dataset (PR8a) - #460

Merged
athvin merged 1 commit into
mainfrom
bm/datasets-p8-rekey
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/datasets-p8-rekey

Conversation

@athvin

@athvin athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner

First half of PR8 in the datasets program (PR6 #415 moved the routes, PR7 #427 gave tenants the screens).

The bug this fixes is user-visible. Nineteen statements still filtered on org_id alone, so a tenant with a people and an accounts dataset opened either one and saw ONE combined config history, ONE model registry, ONE label set, ONE schedule list. The routes said "dataset"; the SQL said "org".

Config versions, the model registry (including which model is active), schedules, labels, tag applications, staged steward actions, S3 cursors and entity links now address the dataset that owns them.

Why the test came first

None of this is type-checked: every one of these parameters is a &str, so passing an org id where a dataset id is now wanted compiles perfectly and quietly returns the wrong rows. So the first thing written was pg_dataset_isolation — one org, two datasets, asserting each sees its own rows and not the sibling's. The absence half is the point; a statement that returns everything passes a presence-only check. It was observed failing against the old SQL before being trusted.

The pg tier then found every mis-threaded call site, which is what it is for: 23 of 94 red at the start, walked down to 0. Most were fixtures writing rows with no dataset and reading them back scoped, now stamping it the way production does via a shared common::default_dataset helper. Two were the raw INSERT INTO matching_models statements flagged back in PR4 as needing exactly this.

Three deliberate non-moves, checked rather than assumed

  • jobs / task instances keep org filters — org-level kinds (provision, the migrate sweep) carry a null dataset by design, and the claim's org-level conflict rule reads the org.
  • the tag vocabulary stays org-wide; PR6 moved only its application.
  • webhooks are org endpoints; dataset is a filter and provenance there, not identity.

Two seams

The convergence sweep reads a pre-dataset org's published config to learn the entity type for the dataset it is about to create — it has no dataset yet, by definition — so it gets an explicitly org-addressed read (by_org_version), documented as the only caller entitled to it. And org_active_config resolves the org's default dataset rather than taking one, holding the still-org-driven callers (S3 poller, source_priority) on today's behaviour until the clean break removes them.

What this does NOT do

The natural keys still say [org_id, …]. Flipping them needs dataset_id NOT NULL, which the reconciler treats as breaking and so must be set before it runs — while the default-dataset converge that would supply the backfill runs after it. That ordering deserves its own migration proof, so it is PR8b. Version numbering therefore stays org-wide here, and the isolation test asserts on which rows a dataset SEES rather than on what they are numbered.

Verification

  • make check exit 0 (fmt, clippy, doc, entities-check, skills-check, 92 green test binaries)
  • Gated pg tier (DEDUPE_E2E_DUCKLAKE=1 + ER_TEST_PG_DSN): 94 passed / 0 failed, including the new isolation test
  • er-entity verify: every statement plans and passes the E0xx rules; lint unchanged at 5 pre-existing V15 warnings

🤖 Generated with Claude Code

@athvin athvin closed this Nov 3, 2026
@athvin athvin reopened this Nov 3, 2026
@athvin
athvin force-pushed the bm/datasets-p8-rekey branch from 422172b to c96443a Compare November 3, 2026 14:28
…ope to the dataset (PR8a)

PR6 moved every route under its dataset and PR7 gave tenants the screens to
manage them, but the SQL underneath had not moved: nineteen statements still
filtered on `org_id` alone. So a tenant with a `people` and an `accounts`
dataset opened either one and saw ONE combined config history, ONE model
registry, ONE label set, ONE schedule list. The routes said "dataset"; the
statements said "org", and the routes were the ones telling the truth.

This moves the statements. Config versions, the model registry (including
which model is active), schedules, labels, tag applications, staged steward
actions, S3 cursors and entity links are now addressed by the dataset that
owns them.

Nothing here is type-checked by the compiler: every one of these parameters
is a `&str`, so passing an org id where a dataset id is now wanted compiles
perfectly and returns the wrong rows. That is why the first commit of this
work was the test. `pg_dataset_isolation` builds one org with two datasets
and asserts each sees its own rows AND NOT the sibling's — the absence half
matters, because a statement that returns everything passes a presence-only
check. It was observed failing against the old SQL before being trusted.

The pg tier then found every mis-threaded call site, which is what it is for:
23 of 94 tests red at the start, walked down to zero. Most were fixtures
writing rows with no dataset and reading them back scoped; those now stamp
the dataset the way production does, through a shared `common::default_dataset`
helper. Two were the raw `INSERT INTO matching_models` statements flagged
during PR4 as needing exactly this.

Three deliberate non-moves, each checked rather than assumed:

- **jobs and task instances** keep their org filters: org-level kinds
  (`provision`, the migrate sweep) carry a null dataset by design, and the
  claim's org-level conflict rule reads the org.
- **the tag vocabulary** stays org-wide; PR6 moved only its application.
- **webhooks** are org endpoints — dataset is a filter and a provenance
  field there, not an identity.

Two seams needed care. The convergence sweep reads a pre-dataset org's
published config to learn what entity type the dataset it is about to create
should carry — it has no dataset yet, by definition — so it gets an
explicitly org-addressed read of its own (`by_org_version`), documented as
the one caller that may use it. And `org_active_config` now resolves the
org's default dataset rather than taking one, keeping the still-org-driven
callers (the S3 poller, `source_priority`) on today's behaviour until the
clean break removes them.

What this PR does NOT do, deliberately: the natural keys still say
`[org_id, …]`. Flipping them needs `dataset_id` NOT NULL, which the
reconciler treats as breaking and so must be set before it runs — while the
default-dataset converge that would supply the backfill runs after it. That
ordering deserves its own migration proof, so version NUMBERING stays
org-wide here and the isolation test asserts on which rows a dataset SEES
rather than on what they are numbered.

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin
athvin force-pushed the bm/datasets-p8-rekey branch from c96443a to a0589e7 Compare November 5, 2026 00:35
@athvin
athvin merged commit 9401cd3 into main Nov 5, 2026
36 checks passed
@athvin
athvin deleted the bm/datasets-p8-rekey branch November 5, 2026 01:43
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