Skip to content

feat(datasets): every control-plane row knows its dataset — nullable columns, stamping, backfill (PR4) - #392

Merged
athvin merged 3 commits into
mainfrom
bm/datasets-p4-dataset-id
Nov 2, 2026
Merged

athvin merged 3 commits into
mainfrom
bm/datasets-p4-dataset-id

Conversation

@athvin

@athvin athvin commented Nov 2, 2026

Copy link
Copy Markdown
Owner

PR 4 of the datasets program (after #380/#381/#383; rebased over #384's trace-context hop, which restructured the same enqueue plumbing). Inert to behavior: every new column is nullable, every unique constraint is unchanged (per-dataset re-keying is PR5/PR8), and a NULL dataset_id means exactly what the pre-dataset world meant.

What

  • Thirteen entities gain dataset_id (FK → datasets.id, nullable) with a V17-compliant dataset-leading index each: config_version, matching_model, job, task_instance, schedule, s3_ingest_cursor, pair_label, tenant_schema_state, entity_link, tagging, staged_steward_action, webhook (NULL = subscribed to all datasets), webhook_delivery. audit_log gains a nullable dataset NAME column instead — it has no org_id to sit beside (its tenant column is the org name), and the ledger outlives both.
  • Every INSERT path stamps it. Handlers resolve the org's default dataset once (stamp_dataset — best-effort by design: the column is nullable, the backfill heals NULLs, and failing a request over a stamp the schema does not require would invert priorities). Dispatcher paths carry job.dataset_id; schedule_tick copies the schedule's; the task-instance retry/clear INSERT … SELECTs carry the predecessor's for free. Org-level stamps are None on purpose: the provision job, api-key and org-lifecycle audits.
  • Fixup 0002_backfill_dataset_ids — the ledgered fixup framework's first passenger: eleven declared UPDATE statements (E009 made each declare reads: [dataset]) stamp every pre-dataset row with its org's default dataset, semantics-once.
  • Org creation converges inline (ensure_default_dataset_by_name after the org upsert and in provisioning), so nothing an org's first minutes write goes unstamped waiting for the next boot's sweep.

What the gates drove (worth recording)

  • 20 E003s: every entity-returning SELECT list.
  • 8 by-name row-decode misses the analyser does not catch: mode: partial reads (matching_model/read/active*, job/read/lock, task_instance/read/{live_claimed_pods,retry_lineage,stale_heartbeats}, webhook/read/for_delivery) decode row.get("dataset_id") by name — found by the pg suite, not E0xx.
  • 43 RETURNING lists; the OpenAPI snapshot + schema.d.ts regen (seven registered schemas grew a field); er-entity-diff's live_job fixture.

Tests

pg_dataset_sweep gains the backfill proof (a NULL job heals to its org's default dataset id; the fixup is ledgered semantics-once). Full pg suite green locally (48/48) after the #384 rebase, make check green, pnpm check green.

🤖 Generated with Claude Code

bmoore813 and others added 3 commits November 2, 2026 11:24
…columns, stamping, and the ledgered backfill (PR4)

Thirteen Postgres entities gain a nullable dataset_id (FK -> datasets.id) with
a V17-compliant dataset-leading index; audit_log gains a nullable dataset NAME
column instead, matching its org-name convention (it has no org_id to sit
beside, and the ledger outlives both). Every INSERT path stamps the column:
handlers resolve the org's default dataset once (stamp_dataset — best-effort
by design: the column is nullable, the backfill heals NULLs, and failing a
request over a stamp the schema does not require would invert priorities);
dispatcher paths carry job.dataset_id; schedule_tick copies the schedule's;
the task-instance retry/clear INSERT..SELECTs carry the predecessor's.

Fixup 0002_backfill_dataset_ids — the framework's first passenger — stamps
every pre-dataset row with its org's default dataset via eleven declared
UPDATE statements (E009 made each declare its read of datasets), ledgered
semantics-once. Org creation now converges the default dataset inline
(ensure_default_dataset_by_name), so nothing an org's first minutes write
goes unstamped waiting for the next boot.

The org-level exceptions stamp None on purpose: the provision job (it creates
the tenant itself), api-key audits, org lifecycle audits, and webhook rows
(NULL = subscribed to every dataset).

Mechanical consequences the gates drove: 20 E003s (entity-returning SELECT
lists), 8 by-name row-decode misses in mode-partial reads the analyser does
not column-check, 43 RETURNING lists, and the OpenAPI/schema.d.ts regen for
the seven registered schemas that grew a field. pg_dataset_sweep gains the
backfill proof (a NULL row heals to its org's default dataset id).

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin
athvin merged commit 007de0b into main Nov 2, 2026
27 checks passed
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