- src/platform/: SiaxRequestContext + propagation headers + 12 canonical
error codes (documented mirror of cl0ud packages/contract), SiaxError,
resource refs (st0re:artifact:...), and the §3/§10 dependency-mode guard:
production runtime + unconfigured dependency/store => hard
DEPENDENCY_UNAVAILABLE at construction, never silent mock/in-memory.
- src/clients/: all four platform clients rewritten against the REAL wire
contracts verified on sibling main branches this session:
* cl0ud: POST /api/policy/evaluate ({data} envelope, allow+requiresApproval)
- the old /v1/cl0ud/policies/evaluate path never existed on CL0UD
* st0re: camelCase ArtifactInput on /v1/st0re/artifacts/register incl.
X-Tenant-Id/X-Actor-Id + X-Idempotency-Key - the old snake_case body
would have been a 400 against the live registry
* n0d: required_role + resource_requirements + body idempotency_key +
CloudEvents callback_url per n0d createJobSchema; adds getJob/getJobResult
* aud0: /v1/aud0/openlineage is AUD0's only lineage ingest -
/v1/aud0/lineage/events never existed; legacy shape converts to a
spec-shaped OpenLineage RunEvent (deterministic runId dedup)
- src/lineage/: OpenLineage subset types + LineageEmitter (never-throw,
§16 evidence semantics)
- shared SiaxHttp transport: timeouts, typed SiaxError mapping, context
propagation, no raw upstream bodies in errors
Co-Authored-By: Claude Fable 5 <[email protected]>
114 lines
4.0 KiB
TypeScript
114 lines
4.0 KiB
TypeScript
/**
|
|
* src/lineage/lineage-emitter.ts
|
|
* ===============================
|
|
* 0pt's OpenLineage emitter (Master-DoD §10 Lineage). One narrow API for
|
|
* capability services to record "this run read X and produced Y" against
|
|
* AUD0's real OpenLineage ingest (`POST /v1/aud0/openlineage` — see
|
|
* src/clients/aud0-client.ts for the wire).
|
|
*
|
|
* Design points:
|
|
* - Deterministic runIds (caller-supplied), so an idempotent retry of a
|
|
* capability re-emits the SAME event and AUD0 dedups it instead of
|
|
* recording a phantom second run.
|
|
* - Canonical SIAX resource refs (`st0re:artifact:...`, `0pt:dataset:...`)
|
|
* go in dataset facets so evidence chains can be joined across products
|
|
* (§16 "Evidence chains: Link source → transform → model → decision").
|
|
* - Emission is evidence of what already happened — a lineage POST failure
|
|
* is surfaced to the caller as a warning value, never an exception that
|
|
* rolls back the completed work. Callers that need hard evidence
|
|
* guarantees must use an outbox (tracked honestly in STATUS.md).
|
|
*/
|
|
import type { Aud0Client } from "../clients/aud0-client";
|
|
import {
|
|
OPT_OPENLINEAGE_PRODUCER,
|
|
type OpenLineageDatasetRef,
|
|
type OpenLineageEventType,
|
|
type OpenLineageRunEvent,
|
|
} from "./openlineage";
|
|
|
|
export interface LineageEmitInput {
|
|
tenant_id: string;
|
|
project_id?: string;
|
|
/** The 0pt capability that ran, e.g. "0pt.quality.run.v1". Becomes job.name. */
|
|
capability_id: string;
|
|
/** Deterministic run id (e.g. the run/version/export id being recorded). */
|
|
run_id: string;
|
|
event_type: OpenLineageEventType;
|
|
/** ISO timestamp; defaults to now. */
|
|
event_time?: string;
|
|
/** Canonical SIAX refs and/or plain names consumed by the run. */
|
|
inputs?: LineageDatasetInput[];
|
|
/** Canonical SIAX refs and/or plain names produced by the run. */
|
|
outputs?: LineageDatasetInput[];
|
|
correlation_id?: string;
|
|
/** Extra run facets (namespaced siax*). */
|
|
run_facets?: Record<string, unknown>;
|
|
}
|
|
|
|
export interface LineageDatasetInput {
|
|
/** Human/system dataset name, e.g. "dataset/ds_x" or "opensearch/opt-companies__g2". */
|
|
name: string;
|
|
/** Optional canonical SIAX resource ref for cross-product joining. */
|
|
ref?: string;
|
|
namespace?: string;
|
|
facets?: Record<string, unknown>;
|
|
}
|
|
|
|
export interface LineageEmitResult {
|
|
emitted: boolean;
|
|
run_id: string;
|
|
/** Present when emission failed (AUD0 unreachable etc.). */
|
|
warning?: string;
|
|
}
|
|
|
|
const APP_ID = "0pt";
|
|
|
|
function toDatasetRef(d: LineageDatasetInput): OpenLineageDatasetRef {
|
|
return {
|
|
namespace: d.namespace ?? APP_ID,
|
|
name: d.name,
|
|
facets: {
|
|
...(d.ref ? { siaxResourceRef: { ref: d.ref } } : {}),
|
|
...(d.facets ?? {}),
|
|
},
|
|
};
|
|
}
|
|
|
|
export class LineageEmitter {
|
|
constructor(private readonly aud0: Aud0Client) {}
|
|
|
|
buildRunEvent(input: LineageEmitInput): OpenLineageRunEvent {
|
|
return {
|
|
eventType: input.event_type,
|
|
eventTime: input.event_time ?? new Date().toISOString(),
|
|
producer: OPT_OPENLINEAGE_PRODUCER,
|
|
run: {
|
|
runId: input.run_id,
|
|
facets: {
|
|
...(input.correlation_id ? { siaxCorrelation: { correlation_id: input.correlation_id } } : {}),
|
|
...(input.project_id ? { siaxProject: { project_id: input.project_id } } : {}),
|
|
...(input.run_facets ?? {}),
|
|
},
|
|
},
|
|
job: { namespace: APP_ID, name: input.capability_id },
|
|
inputs: (input.inputs ?? []).map(toDatasetRef),
|
|
outputs: (input.outputs ?? []).map(toDatasetRef),
|
|
};
|
|
}
|
|
|
|
/** Emit one run event. Never throws — see module doc comment. */
|
|
async emit(input: LineageEmitInput): Promise<LineageEmitResult> {
|
|
const event = this.buildRunEvent(input);
|
|
try {
|
|
await this.aud0.ingestOpenLineageEvent(input.tenant_id, APP_ID, event);
|
|
return { emitted: true, run_id: input.run_id };
|
|
} catch (err) {
|
|
return {
|
|
emitted: false,
|
|
run_id: input.run_id,
|
|
warning: `openlineage emission failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
};
|
|
}
|
|
}
|
|
}
|