feat(process): record provider and verifier run lineage

This commit is contained in:
morluto
2026-07-22 14:01:47 +00:00
parent f5b3e22e72
commit 513fa294a4
200 changed files with 2808 additions and 546 deletions
+16
View File
@@ -13,6 +13,7 @@ import type { EvidenceSubjectTarget } from "../domain/evidence.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import type { ProgressReporter } from "./ProgressReporter.js";
import type { ProviderRejectionCode } from "../contracts/providerSelection.js";
import type { ProcessLineageObservation } from "../process/ProcessOwnership.js";
export interface ExecutionOptions {
readonly signal?: AbortSignal;
@@ -74,14 +75,28 @@ export interface AnalysisOperationPort {
): Promise<Result<AnalysisExecution, AnalysisError>>;
}
/** Retained provider-process observation attributed to its producing provider. */
export interface ProviderRuntimeLineageSnapshot {
readonly provider: ProviderIdentity;
readonly observation: ProcessLineageObservation;
}
/** Provider session bound to exactly one parsed artifact. */
export interface AnalysisClient extends AnalysisOperationPort {
/** Retained token-verified process snapshots for dynamic providers this client started. */
runtimeLineageSnapshots?(): readonly ProviderRuntimeLineageSnapshot[];
close(): Promise<void>;
}
/** Per-client identity allocated before any provider side effect starts. */
export interface AnalysisClientContext {
readonly runId: string;
}
export type AnalysisClientFactory = (
target: BinaryTarget,
profile?: AnalysisProfileCommitment,
context?: AnalysisClientContext,
) => AnalysisClient;
export interface ProviderIdentity {
@@ -144,6 +159,7 @@ export interface AnalysisProvider {
createClient(
target: BinaryTarget,
profile?: AnalysisProfileCommitment,
context?: AnalysisClientContext,
): AnalysisClient;
}
+13 -2
View File
@@ -1,3 +1,5 @@
import { randomUUID } from "node:crypto";
import type { BinaryTarget } from "../domain/binaryTarget.js";
import {
analysisProfilesEqual,
@@ -58,6 +60,7 @@ export class BinarySession
readonly profile: AnalysisProfileCommitment | null;
readonly compatibility: Readonly<Record<string, JsonValue>>;
readonly route: SessionProviderRoute;
readonly runId: string;
}
| undefined;
#transition: Promise<void> = Promise.resolve();
@@ -184,7 +187,8 @@ export class BinarySession
const previous = this.#active;
this.#active = undefined;
await previous?.client.close();
const client = route.createClient(target);
const runId = randomUUID();
const client = route.createClient(target, { runId });
const started = await client.execute("health", {}, options);
if (!started.ok) {
await client.close();
@@ -202,6 +206,7 @@ export class BinarySession
profile,
compatibility: structuredClone(compatibility),
route,
runId,
};
this.#clearRuntimeAvailability();
if (profile === null) this.clearSnapshot();
@@ -240,6 +245,9 @@ export class BinarySession
route: this.#currentRoute(),
router: this.#providerRouter,
runtimeAvailability: this.#runtimeAvailability,
runId: this.#active?.runId,
runtimeLineageSnapshots:
this.#active?.client.runtimeLineageSnapshots?.() ?? [],
});
}
@@ -396,11 +404,13 @@ export class BinarySession
readonly profile: AnalysisProfileCommitment | null;
readonly compatibility: Readonly<Record<string, JsonValue>>;
readonly route: SessionProviderRoute;
readonly runId: string;
}
| undefined,
): Promise<void> {
if (previous === undefined) return;
const client = previous.route.createClient(previous.target);
const runId = randomUUID();
const client = previous.route.createClient(previous.target, { runId });
const started = await client.execute("health", {});
if (started.ok)
this.#active = {
@@ -409,6 +419,7 @@ export class BinarySession
profile: previous.profile,
compatibility: previous.compatibility,
route: previous.route,
runId,
};
else await client.close();
}
+56 -1
View File
@@ -1,6 +1,9 @@
import type { BinaryTarget } from "../domain/binaryTarget.js";
import type { JsonValue } from "../domain/jsonValue.js";
import type { CapabilityDescriptor } from "./AnalysisProvider.js";
import type {
CapabilityDescriptor,
ProviderRuntimeLineageSnapshot,
} from "./AnalysisProvider.js";
import type {
SessionProviderRoute,
SessionProviderRouter,
@@ -14,6 +17,8 @@ interface BinarySessionStatusInput {
string,
{ readonly available: boolean; readonly reason: string | null }
>;
readonly runId: string | undefined;
readonly runtimeLineageSnapshots: readonly ProviderRuntimeLineageSnapshot[];
}
/** Project internal provider routing state into the caller-visible session status. */
@@ -22,6 +27,8 @@ export const binarySessionStatus = ({
route,
router,
runtimeAvailability,
runId,
runtimeLineageSnapshots,
}: BinarySessionStatusInput): JsonValue => {
const configuredProvider = router.configuredIdentity();
const provider = providerSummary(configuredProvider);
@@ -59,6 +66,13 @@ export const binarySessionStatus = ({
capabilities,
analysis_provider_binding: analysisProviderBinding,
analysis_provider_candidates: analysisProviderCandidates,
analysis_run:
runId === undefined
? null
: {
run_id: runId,
process_lineage: processLineageStatus(runtimeLineageSnapshots),
},
};
return target === undefined
? { open: false, ...common }
@@ -83,6 +97,47 @@ const providerSummary = ({
readonly version: string | null;
}) => ({ id, name, version });
const processLineageStatus = (
snapshots: readonly ProviderRuntimeLineageSnapshot[],
) =>
snapshots.length === 0
? { status: "not_observed" }
: {
status: "snapshots",
snapshots: snapshots
.slice()
.sort((left, right) =>
left.provider.id.localeCompare(right.provider.id),
)
.map(({ provider, observation }) => ({
provider: providerSummary(provider),
observation:
observation.status === "unavailable"
? {
status: observation.status,
observed_at: observation.observedAt,
launcher_pid: observation.launcherPid,
process_group_id: observation.processGroupId,
reason: observation.reason,
}
: {
status: observation.status,
observed_at: observation.observedAt,
schema_version: observation.lineage.schemaVersion,
launcher_pid: observation.lineage.launcherPid,
launcher_parent_pid: observation.lineage.launcherParentPid,
process_group_id: observation.lineage.processGroupId,
descendants: observation.lineage.descendants.map(
({ pid, parentPid, processGroupId }) => ({
pid,
parent_pid: parentPid,
process_group_id: processGroupId,
}),
),
},
})),
};
const capabilityStatus = (
descriptor: Omit<CapabilityDescriptor, "available" | "reason"> & {
readonly available: boolean;
+9
View File
@@ -4,6 +4,7 @@ import type { BinaryTarget } from "../domain/binaryTarget.js";
import type { AnalysisProfileCommitment } from "../domain/analysisProfile.js";
import type {
AnalysisClient,
AnalysisClientContext,
AnalysisProfileResolutionOptions,
AnalysisProvider,
CapabilityDescriptor,
@@ -88,6 +89,7 @@ export class CompositeProvider implements AnalysisProvider {
createClient(
target: BinaryTarget,
profile?: AnalysisProfileCommitment,
context?: AnalysisClientContext,
): AnalysisClient {
const clients = new Map<AnalysisProvider, AnalysisClient>();
const clientFor = (provider: AnalysisProvider): AnalysisClient => {
@@ -96,6 +98,7 @@ export class CompositeProvider implements AnalysisProvider {
const created = provider.createClient(
target,
profile?.provider.id === provider.identity().id ? profile : undefined,
context,
);
clients.set(provider, created);
return created;
@@ -126,6 +129,12 @@ export class CompositeProvider implements AnalysisProvider {
)
: clientFor(provider).execute(operation, parameters, options);
},
runtimeLineageSnapshots: () =>
[...clients.values()]
.flatMap((client) => client.runtimeLineageSnapshots?.() ?? [])
.sort((left, right) =>
left.provider.id.localeCompare(right.provider.id),
),
close: async () => {
await Promise.allSettled(
[...clients.values()].map(async (client) => client.close()),
+15 -7
View File
@@ -15,6 +15,7 @@ import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
import { err, ok, type Result } from "../domain/result.js";
import type {
AnalysisClient,
AnalysisClientContext,
AnalysisClientFactory,
AnalysisProfileResolution,
AnalysisProfileResolutionOptions,
@@ -42,7 +43,10 @@ export interface SessionProviderRoute {
readonly compatibility: Readonly<Record<string, JsonValue>>;
readonly binding: AnalysisProviderBinding | null;
readonly selection: AnalysisProviderSelection | undefined;
createClient(target: BinaryTarget): AnalysisClient;
createClient(
target: BinaryTarget,
context: AnalysisClientContext,
): AnalysisClient;
}
interface LegacyProviderRuntime {
@@ -172,7 +176,8 @@ export class SessionProviderRouter {
compatibility: {},
binding: null,
selection: undefined,
createClient: (target) => createLegacyClient(runtime, target, undefined),
createClient: (target, context) =>
createLegacyClient(runtime, target, undefined, context),
};
}
@@ -225,11 +230,12 @@ export class SessionProviderRouter {
compatibility: normalized.value.compatibility,
binding: null,
selection: undefined,
createClient: (openedTarget) =>
createClient: (openedTarget, context) =>
createLegacyClient(
runtime,
openedTarget,
normalized.value.profile ?? undefined,
context,
),
});
}
@@ -280,8 +286,9 @@ const selectableRoute = (
compatibility: structuredClone(binding?.compatibility ?? {}),
binding,
selection,
createClient: (target) =>
provider?.createClient(target, binding?.profile) ?? emptyClient(identity),
createClient: (target, context) =>
provider?.createClient(target, binding?.profile, context) ??
emptyClient(identity),
};
};
@@ -289,10 +296,11 @@ const createLegacyClient = (
runtime: LegacyProviderRuntime,
target: BinaryTarget,
profile: AnalysisProfileCommitment | undefined,
context: AnalysisClientContext,
): AnalysisClient =>
typeof runtime.provider === "function"
? runtime.provider(target, profile)
: runtime.provider.createClient(target, profile);
? runtime.provider(target, profile, context)
: runtime.provider.createClient(target, profile, context);
const emptyClient = (identity: ProviderIdentity): AnalysisClient => ({
execute: (operation) =>