feat(platform): canonical SIAX context/errors + real-contract clients, no prod mock fallback

- 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]>
This commit is contained in:
Simon Axelsson
2026-08-31 16:35:01 +02:00
co-authored by Claude Fable 5
parent 00a1b3997d
commit b7038d7675
14 changed files with 1240 additions and 202 deletions
+113
View File
@@ -0,0 +1,113 @@
/**
* 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)}`,
};
}
}
}
+50
View File
@@ -0,0 +1,50 @@
/**
* src/lineage/openlineage.ts
* ===========================
* Minimal, spec-shaped OpenLineage types for 0pt's lineage emission
* (Master-DoD §10 "Lineage: emit OpenLineage-events till AUD0:s
* ingest-kontrakt", §16 "OpenLineage: Run/Job/Dataset ingest").
*
* This is a deliberate SUBSET of the OpenLineage 1.x spec
* (https://openlineage.io/spec/2-0-2/OpenLineage.json): the fields AUD0's
* `/v1/aud0/openlineage` ingest reads (eventType, eventTime, run.runId,
* job.namespace/name, inputs[], outputs[], facets passed through opaquely).
* Facets are open `Record<string, unknown>` — AUD0 stores them verbatim as
* evidence; custom SIAX facets are namespaced `siax*`.
*/
export type OpenLineageEventType = "START" | "RUNNING" | "COMPLETE" | "ABORT" | "FAIL" | "OTHER";
export interface OpenLineageDatasetRef {
/** Dataset namespace, e.g. "0pt" or a source system identifier. */
namespace: string;
/** Dataset name, e.g. "dataset/ds_x" or "opensearch/opt-search-companies". */
name: string;
facets?: Record<string, unknown>;
}
export interface OpenLineageRunEvent {
eventType: OpenLineageEventType;
/** ISO-8601 timestamp of the state transition. */
eventTime: string;
/** Producer URI identifying the emitting code base. */
producer: string;
/** Spec schema URL — optional; AUD0 does not require it. */
schemaURL?: string;
run: {
/** Stable run id — 0pt uses deterministic ids so re-emission dedups. */
runId: string;
facets?: Record<string, unknown>;
};
job: {
/** Job namespace — 0pt emits its app id ("0pt"). */
namespace: string;
/** Job name — the 0pt capability id, e.g. "0pt.dataset.version.v1". */
name: string;
facets?: Record<string, unknown>;
};
inputs?: OpenLineageDatasetRef[];
outputs?: OpenLineageDatasetRef[];
}
export const OPT_OPENLINEAGE_PRODUCER = "https://git.siax.io/sax3l/0pt";