feat(data-os): P060-P068 durable ingestion plane — source classification gate, connector contract, common envelope, schema evolution, quality enforcement, queryable lineage, idempotent backfill
CI (SIAX Cloud) / integration (push) Successful in 42s
CI (SIAX Cloud) / quality (push) Successful in 1m17s
CI (SIAX Cloud) / security (push) Successful in 46s
Security Scan (SIAX Cloud) / security (push) Successful in 31s
CI (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / integration (pull_request) Successful in 36s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m4s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 27s

BEFORE_STATE (verified, with evidence):

* P060 PARTIAL/BROKEN. The registry persisted rights/provenance/health/
  freshness to Postgres, but carried no authorization, no schedule, no
  checkpoint, no schema and no owner distinct from created_by — and the
  activation DoD was inverted: postgres-source-repository.ts wrote
  `${input.status ?? "active"}`, so a source with no rights, no provenance
  and no authorization was ACTIVE the instant it was registered. No
  activation operation existed at all.
* P061 MISSING. services/api/sources/connectors.py had per-source fetch_*()
  functions only — no lifecycle, no cursor, no resume, no health, no
  conformance suite.
* P062 MISSING, already documented as such in
  services/api/tests/test_known_gaps.py:10-19 (no CDC pipeline anywhere;
  workers/pipeline.py has no persistence at all).
* P063 MISSING. schema_version existed as a free string; no comparison,
  no policy, no versioned source schema.
* P064 PARTIAL. Rules/runs/issues/scores existed, but a failing rule only
  opened an issue and the data flowed on. No quarantine anywhere.
* P065 DUPLICATE (confirmed). Two ER engines: src/er/entity-resolution-
  service.ts (canonical) and services/api/workers/resolve.py (simplified,
  still called by pipeline.py:110).
* P067 PARTIAL. Lineage was emitted to AUD0 but nothing here could ANSWER a
  lineage question — no store, no query, no route.
* P068 MISSING, documented in test_known_gaps.py:44-52 ("no delivery-store
  persistence layer exists to dedupe a backfill against").

BUILT (only what was PARTIAL/BROKEN/MISSING):

* P060 sql/007_ingestion_plane.sql adds authorization/schedule/schemas/
  checkpoints/ledger/quarantine/lineage tables, owner_id, and flips the
  opt_sources status DEFAULT to 'pending' so even a raw psql INSERT cannot
  produce an unclassified-but-active source. SourceRegistryService gains
  classifySource/activateSource/deactivateSource + authorization/schedule
  accessors; registration NEVER activates (asking for status:"active" goes
  through the gate, not around it); a service identity cannot authorize a
  source. Routes: activate (GET classification / POST activate),
  authorization, schedule.
* P061 src/connectors/connector.ts — all nine operations on one interface.
  src/connectors/conformance.ts — a runnable suite (15 checks, no "skip"
  verdict). HttpJsonConnector (real HTTP, opaque cursor) and
  JsonlFileConnector (real file, line offsets, CDC deletes) both pass it.
  The suite caught a real defect while being written: an API that drops
  next_cursor at the end left the connector unable to resume, which is why
  HttpJsonConnectorConfig has cursor_field.
* P062 src/types/ingestion.ts + src/ingestion/{envelope,ingestion-runner}.ts.
  One envelope for batch/stream/cdc; durable per-(source,partition)
  checkpoints; resume proven by killing a run inside the sink.
* P063 src/schema/{record-schema,compatibility,schema-registry}.ts. Two
  enforcement points, both upstream of any consumer write: a discovery gate
  before the first read, and per-record conformance before the page reaches
  the sink. A producer cannot widen its own policy retroactively.
* P064 src/quality/quality-policy.ts composes the EXISTING ExpectationEngine
  (not a second engine) and adds the missing consequence: block /
  quarantine / warn, with quarantine durable and recoverable. No policy is
  reported as "none_declared", never as a pass; an unexecutable expectation
  counts as a violation, never a silent pass.
* P067 src/lineage/{lineage-edge,lineage-store}.ts + GET /api/0pt/lineage.
  AUD0 stays the system of record; this is 0pt's own queryable projection.
* P068 opt_ingestion_ledger + IngestionRunner.backfill: bounded, idempotent
  on repeat, leaves the live checkpoint alone, still re-emits real changes.

A BUG THIS PASS WROTE AND CAUGHT: the first IngestionRepository draft
combined the idempotency check and its recording into one atomic call
BEFORE the sink. The crash/resume test then delivered 7 of 10 records — the
page in flight when the sink died was already marked delivered, so the
resumed run skipped it as a duplicate. Permanent, silent data loss. Fixed by
splitting peekDeliveries/commitDeliveries and committing both the ledger and
the checkpoint only after the sink resolves.

NOT DONE, stated rather than deferred quietly:

* P065 is NOT met. resolve.py is still a second simplified production
  engine. Closing it means rewriting it as an adapter over the canonical
  service, which cannot be verified from this repo today: services/api is
  not built by this repo's Dockerfile, api.0pt.app answers 404, and NO CI
  workflow runs its pytest suite. The duplication is now stated at both
  sites in code and the removal plan is in STATUS.md. The new ingestion
  plane performs no ER, so it adds no third engine.
* P066 (Iceberg) untouched — ST0RE is owned by another workflow. Contract
  read only.
* Delivery is AT-LEAST-ONCE, not exactly-once (no per-partition run lock).
* No CDC *source* exists; the contract is met, a CDC connector is not built.
* 0pt does not schedule itself — the schedule row is a declaration ACT0
  would read.

VERIFIED: pnpm typecheck clean; pnpm test 365 passed / 25 skipped (was
311/18); pnpm build clean with all four new routes in the route table; lint
unchanged at 12 pre-existing errors. Real Postgres 16
(tests/p0/ingestion-plane-postgres.realinfra.test.ts, 7 passed) plus a real
`docker restart` of that container with an identical read-back through the
production code path — that is P060's "a restart preserves all sources",
measured.

DEPLOYMENT REALITY (curl, 2026-09-04): 0pt.app/api/health returns 200 from
Vercel with db:not_configured; 0pt.app/api/0pt/sources returns 404;
api.0pt.app/health returns 404; cd.yml still guards on a placeholder Coolify
app id. None of the capability layer runs in production. Nothing here is
LIVE_VERIFIED and STATUS.md says so.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
Simon Axelsson
2026-09-04 17:03:14 +02:00
co-authored by Claude Opus 5
parent c5ebceff38
commit 9267576b7c
43 changed files with 5506 additions and 20 deletions
+42
View File
@@ -0,0 +1,42 @@
/**
* src/lineage/lineage-edge.ts
* ============================
* P067: the flattened, QUERYABLE form of an OpenLineage run event.
*
* LineageEmitter (src/lineage/lineage-emitter.ts) already emits spec-shaped
* run events to AUD0, and AUD0 remains the SYSTEM OF RECORD for them. But
* "emitted to AUD0" is not "answerable from 0pt": nothing in this repo could
* answer "which sources fed dataset ds_x?" without asking another product.
* These edges are 0pt's own projection — one row per (run, input, output)
* pair — written in the same call that emits, so the question is answerable
* locally and joins back to AUD0 by `run_id`.
*
* The projection is deliberately LOSSY (facets are not stored, only the
* canonical SIAX ref) — it is an index, not a second source of truth.
*/
export interface LineageEdge {
/** Deterministic sha256 of (run_id, input, output) — a re-emitted idempotent run does not duplicate edges. */
edge_id: string;
tenant_id: string;
run_id: string;
capability_id: string;
input_namespace: string;
input_name: string;
input_ref?: string;
output_namespace: string;
output_name: string;
output_ref?: string;
event_time: string;
correlation_id?: string;
}
/** Query one direction of the graph. Exactly one of the two selectors is required. */
export interface LineageQuery {
tenant_id: string;
/** Everything that fed this output (upstream). */
output_name?: string;
/** Everything this input produced (downstream). */
input_name?: string;
limit?: number;
}
+121
View File
@@ -0,0 +1,121 @@
/**
* src/lineage/lineage-store.ts
* =============================
* P067 DoD: "source -> output lineage is QUERYABLE."
*
* LineageEmitter already emits OpenLineage run events to AUD0 and that does
* not change — AUD0 stays the system of record. This class adds the missing
* half: it flattens the same run event into (input, output) edges, persists
* them, and answers both directions of the question.
*
* `RecordingLineageEmitter` is the composition point: it wraps the existing
* emitter so every existing caller (QualityService, DatasetVersionService,
* the ingestion runner) gets the local projection for free, without any of
* them learning about a second store. Emission to AUD0 keeps its existing
* never-throw contract; a projection write failure is likewise reported, not
* thrown, because lineage is evidence of work that already happened.
*/
import crypto from "crypto";
import type { IngestionRepository } from "../repositories/ingestion-repository";
import type { LineageEdge, LineageQuery } from "./lineage-edge";
import type { LineageEmitInput, LineageEmitResult, LineageEmitter } from "./lineage-emitter";
import type { OpenLineageRunEvent } from "./openlineage";
/** Deterministic edge id: the same run re-emitted produces the same edges. */
export function lineageEdgeId(runId: string, input: string, output: string): string {
return `led_${crypto.createHash("sha256").update(`${runId}|${input}|${output}`).digest("hex").slice(0, 32)}`;
}
function refOf(facets: Record<string, unknown> | undefined): string | undefined {
const facet = facets?.siaxResourceRef as { ref?: string } | undefined;
return typeof facet?.ref === "string" ? facet.ref : undefined;
}
/**
* Flatten one OpenLineage run event into edges. A run with N inputs and M
* outputs yields N*M edges; a run with no inputs or no outputs yields none
* (there is no edge to draw), which is why the runner always emits both.
*/
export function edgesFromRunEvent(
event: OpenLineageRunEvent,
tenantId: string,
correlationId?: string,
): LineageEdge[] {
const edges: LineageEdge[] = [];
for (const input of event.inputs ?? []) {
for (const output of event.outputs ?? []) {
edges.push({
edge_id: lineageEdgeId(event.run.runId, `${input.namespace}/${input.name}`, `${output.namespace}/${output.name}`),
tenant_id: tenantId,
run_id: event.run.runId,
capability_id: event.job.name,
input_namespace: input.namespace,
input_name: input.name,
input_ref: refOf(input.facets),
output_namespace: output.namespace,
output_name: output.name,
output_ref: refOf(output.facets),
event_time: event.eventTime,
correlation_id: correlationId,
});
}
}
return edges;
}
export class LineageStore {
constructor(private readonly repo: IngestionRepository) {}
async record(event: OpenLineageRunEvent, tenantId: string, correlationId?: string): Promise<number> {
const edges = edgesFromRunEvent(event, tenantId, correlationId);
if (edges.length > 0) await this.repo.appendLineageEdges(edges);
return edges.length;
}
/** Everything that fed `outputName`, newest first. */
async upstreamOf(tenantId: string, outputName: string, limit?: number): Promise<LineageEdge[]> {
return this.repo.queryLineage({ tenant_id: tenantId, output_name: outputName, limit });
}
/** Everything `inputName` produced, newest first. */
async downstreamOf(tenantId: string, inputName: string, limit?: number): Promise<LineageEdge[]> {
return this.repo.queryLineage({ tenant_id: tenantId, input_name: inputName, limit });
}
async query(query: LineageQuery): Promise<LineageEdge[]> {
return this.repo.queryLineage(query);
}
}
/**
* A LineageEmitter that also writes the local projection. Drop-in for the
* existing emitter: same `emit` signature, same never-throw contract.
*/
export class RecordingLineageEmitter {
constructor(
private readonly inner: LineageEmitter,
private readonly store: LineageStore,
) {}
buildRunEvent(input: LineageEmitInput): OpenLineageRunEvent {
return this.inner.buildRunEvent(input);
}
async emit(input: LineageEmitInput): Promise<LineageEmitResult & { projected: number }> {
const event = this.inner.buildRunEvent(input);
const result = await this.inner.emit(input);
let projected = 0;
try {
projected = await this.store.record(event, input.tenant_id, input.correlation_id);
} catch (err) {
return {
...result,
projected: 0,
warning: [result.warning, `lineage projection write failed: ${err instanceof Error ? err.message : String(err)}`]
.filter(Boolean)
.join("; "),
};
}
return { ...result, projected };
}
}