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
+2 -1
View File
@@ -150,12 +150,13 @@ const optionalClaims = ({ operatorManifest, ilspyOracle }) => [
];
/** Project completed managed assertions into the standard verifier report. */
export const createManagedCompletionReport = (input) => ({
export const createManagedCompletionReport = (input, verifierRun) => ({
schema_version: 1,
verifier: {
id: COMPLETION_PROVIDER.id,
version: COMPLETION_PROVIDER.version,
},
verifier_run: verifierRun,
environment: {
platform: process.platform,
architecture: process.arch,
+43
View File
@@ -0,0 +1,43 @@
export interface VerifierRunStart {
readonly schema_version: 1;
readonly run_id: string;
readonly verifier_pid: number;
readonly parent_pid: number;
}
export interface VerifierRunDescendant {
readonly pid: number;
readonly parent_pid: number;
readonly process_group_id: number;
}
export type VerifierProcessLineage =
| {
readonly status: "verified";
readonly schema_version: 1;
readonly observed_at: string;
readonly launcher_pid: number;
readonly launcher_parent_pid: number;
readonly process_group_id: number;
readonly descendants: readonly VerifierRunDescendant[];
}
| {
readonly status: "unavailable";
readonly observed_at: string;
readonly launcher_pid: number;
readonly launcher_parent_pid: number;
readonly process_group_id: number | null;
readonly reason: string;
};
export interface VerifierRun extends VerifierRunStart {
readonly process_lineage: VerifierProcessLineage;
}
/** Allocate one process-local identity and propagate it to child processes. */
export function createVerifierRun(): VerifierRunStart;
/** Complete a verifier report with token-verified point-in-time lineage. */
export function completeVerifierRun(
run: VerifierRunStart,
): Promise<VerifierRun>;
+206
View File
@@ -0,0 +1,206 @@
import { spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import { readFile, readdir } from "node:fs/promises";
let activeVerifierRun;
/** Allocate one verifier identity before work and propagate it to child processes. */
export const createVerifierRun = () => {
if (activeVerifierRun !== undefined) {
process.env.REA_PROCESS_RUN_ID = activeVerifierRun.run_id;
return activeVerifierRun;
}
activeVerifierRun = Object.freeze({
schema_version: 1,
run_id: randomUUID(),
verifier_pid: process.pid,
parent_pid: process.ppid,
});
process.env.REA_PROCESS_RUN_ID = activeVerifierRun.run_id;
return activeVerifierRun;
};
/**
* Complete a verifier report with a token-verified point-in-time lineage.
*
* An empty descendant list means none were live during this observation. It
* does not prove that the verifier never launched children earlier in the run.
*/
export const completeVerifierRun = async (run) => {
const observedAt = new Date().toISOString();
return {
...run,
process_lineage: await observeVerifierLineage(run, observedAt),
};
};
const observeVerifierLineage = async (run, observedAt) => {
if (process.platform === "win32")
return unavailableLineage(
run,
observedAt,
null,
"Windows verifier lineage ownership is unavailable without Job Objects",
);
try {
const { members, observerPid } = await processSnapshot();
const launcher = members.find(({ pid }) => pid === run.verifier_pid);
if (launcher === undefined)
return unavailableLineage(
run,
observedAt,
null,
"verifier launcher was absent from the process snapshot",
);
if (launcher.parentPid !== run.parent_pid)
return unavailableLineage(
run,
observedAt,
launcher.processGroupId,
"verifier launcher parent changed before lineage observation",
);
const descendants = descendantMembers(
members.filter(({ pid }) => pid !== observerPid),
run.verifier_pid,
);
for (const member of descendants) {
let memberRunId;
try {
memberRunId = await processRunId(member.pid);
} catch {
return unavailableLineage(
run,
observedAt,
launcher.processGroupId,
`descendant ${String(member.pid)} environment was unreadable`,
);
}
if (memberRunId !== run.run_id)
return unavailableLineage(
run,
observedAt,
launcher.processGroupId,
`descendant ${String(member.pid)} run token did not match`,
);
}
return {
status: "verified",
schema_version: 1,
observed_at: observedAt,
launcher_pid: run.verifier_pid,
launcher_parent_pid: run.parent_pid,
process_group_id: launcher.processGroupId,
descendants: descendants
.map(({ pid, parentPid, processGroupId }) => ({
pid,
parent_pid: parentPid,
process_group_id: processGroupId,
}))
.sort((left, right) => left.pid - right.pid),
};
} catch {
return unavailableLineage(
run,
observedAt,
null,
"operating-system process lineage could not be inspected",
);
}
};
const unavailableLineage = (run, observedAt, processGroupId, reason) => ({
status: "unavailable",
observed_at: observedAt,
launcher_pid: run.verifier_pid,
launcher_parent_pid: run.parent_pid,
process_group_id: processGroupId,
reason,
});
const processSnapshot = async () => {
if (process.platform === "linux") return linuxProcessSnapshot();
return posixProcessSnapshot();
};
const linuxProcessSnapshot = async () => {
const entries = await readdir("/proc", { withFileTypes: true });
const members = [];
for (const entry of entries) {
if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue;
try {
const stat = await readFile(`/proc/${entry.name}/stat`, "utf8");
const match = /^\d+ \(.*\) (\S) (\d+) (\d+) /u.exec(stat);
if (match === null || match[1] === "Z") continue;
members.push({
pid: Number(entry.name),
parentPid: Number(match[2]),
processGroupId: Number(match[3]),
});
} catch {
// Processes can exit while /proc is being sampled.
}
}
return { members, observerPid: null };
};
const posixProcessSnapshot = async () => {
const child = spawn("ps", ["-axo", "pid=,ppid=,pgid=,stat="], {
stdio: ["ignore", "pipe", "pipe"],
});
const stdout = [];
const stderr = [];
child.stdout.on("data", (chunk) => stdout.push(chunk));
child.stderr.on("data", (chunk) => stderr.push(chunk));
const code = await new Promise((resolve, reject) => {
child.once("error", reject);
child.once("close", resolve);
});
if (code !== 0)
throw new Error(`ps failed: ${Buffer.concat(stderr).toString("utf8")}`);
const members = Buffer.concat(stdout)
.toString("utf8")
.split("\n")
.map((line) => /\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/u.exec(line))
.filter((match) => match !== null && !match[4]?.startsWith("Z"))
.map((match) => ({
pid: Number(match[1]),
parentPid: Number(match[2]),
processGroupId: Number(match[3]),
}));
return { members, observerPid: child.pid ?? null };
};
const descendantMembers = (members, launcherPid) => {
const descendantPids = new Set([launcherPid]);
let previousSize = -1;
while (previousSize !== descendantPids.size) {
previousSize = descendantPids.size;
for (const member of members)
if (descendantPids.has(member.parentPid)) descendantPids.add(member.pid);
}
descendantPids.delete(launcherPid);
return members.filter(({ pid }) => descendantPids.has(pid));
};
const processRunId = async (pid) => {
if (process.platform === "linux") {
const environment = await readFile(`/proc/${String(pid)}/environ`, "utf8");
return environment
.split("\0")
.find((entry) => entry.startsWith("REA_PROCESS_RUN_ID="))
?.slice("REA_PROCESS_RUN_ID=".length);
}
const child = spawn("ps", ["eww", "-p", String(pid)], {
stdio: ["ignore", "pipe", "ignore"],
});
const stdout = [];
child.stdout.on("data", (chunk) => stdout.push(chunk));
const code = await new Promise((resolve, reject) => {
child.once("error", reject);
child.once("close", resolve);
});
if (code !== 0) throw new Error("process environment unavailable");
return /(?:^|\s)REA_PROCESS_RUN_ID=([^\s]*)/u.exec(
Buffer.concat(stdout).toString("utf8"),
)?.[1];
};
+3
View File
@@ -8,8 +8,10 @@ import { fileURLToPath } from "node:url";
import { createPackage } from "@electron/asar";
import { evaluateCodexEvents } from "../dist/evaluation/CodexAgentEval.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const verifierRun = createVerifierRun();
const evaluationRoot = await mkdtemp(join(tmpdir(), "rea-agent-eval-"));
const fixtureRoot = join(evaluationRoot, "targets");
const skillDestination = join(
@@ -152,6 +154,7 @@ try {
}
const summary = {
verifier_run: await completeVerifierRun(verifierRun),
schemaVersion: 1,
codex,
codexVersion,
+3 -1
View File
@@ -8,8 +8,10 @@ import {
sha256,
sourceDigest,
} from "./lib/conformance-fixtures.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const exec = promisify(execFile);
const verifierRun = createVerifierRun();
const manifestPath = await realpath(
resolve(process.argv[2] ?? "build/conformance/manifest.json"),
);
@@ -37,7 +39,7 @@ if (v1 === undefined || v2 === undefined)
if (v1.artifactSha256 === v2.artifactSha256)
throw new Error("Version-pair artifacts unexpectedly have equal hashes");
process.stdout.write(
`${JSON.stringify({ verified: manifest.fixtures.length, manifestPath, platform: manifest.platform })}\n`,
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), verified: manifest.fixtures.length, manifestPath, platform: manifest.platform })}\n`,
);
async function verifyFixture(fixture) {
+4
View File
@@ -11,7 +11,10 @@ import { join } from "node:path";
import { tmpdir } from "node:os";
import { promisify } from "node:util";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const execFileAsync = promisify(execFile);
const verifierRun = createVerifierRun();
const command = process.env.REA_VERIFY_SERVER_COMMAND;
if (process.platform !== "linux" || process.getuid?.() !== 0)
throw new Error("Linux setup verification requires a root Linux runner");
@@ -113,6 +116,7 @@ if (/\/opt\/hopper\/bin\/Hopper|\bXvfb\b|hopper-demo-x11\.py/u.test(processes))
console.log(
JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
status: "verified",
setup: true,
cli: true,
@@ -14,6 +14,9 @@ import { applicationVersionComparisonResultSchema } from "../dist/domain/javascr
import { applicationFeatureTraceResultSchema } from "../dist/domain/javascriptFeatureTraceSchemas.js";
import { javaScriptExportShapeComparisonResultSchema } from "../dist/domain/javascriptExportShapeComparisonSchemas.js";
import { createPermissionPolicy } from "../dist/domain/permissionPolicy.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const verifierRun = createVerifierRun();
const options = parseArgs({
options: {
@@ -94,6 +97,7 @@ const exportShapeResult =
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
comparison_id: comparisonResult.comparison_id,
evidence_id: comparison.value.evidence_id,
left: comparisonResult.left,
@@ -7,6 +7,9 @@ import { analyzeJavaScriptApplication } from "../dist/application/JavaScriptAppl
import { PermissionAuthority } from "../dist/application/PermissionAuthority.js";
import { reconcileJavaScriptRuntimeEvidence } from "../dist/application/JavaScriptRuntimeReconciliationService.js";
import { createPermissionPolicy } from "../dist/domain/permissionPolicy.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const verifierRun = createVerifierRun();
const options = parseArgs({
options: {
@@ -71,6 +74,7 @@ const result = reconciled.value.normalized_result;
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
reconciliation_id: result.reconciliation_id,
evidence_id: reconciled.value.evidence_id,
graph_id: result.graph.graph_id,
+19 -14
View File
@@ -30,7 +30,9 @@ import {
nativeBoundaryLimits,
} from "./lib/managed-conformance-config.mjs";
import { createManagedCompletionReport } from "./lib/managed-completion-report.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const verifierRun = createVerifierRun();
const workspace = await mkdtemp(join(tmpdir(), "rea-managed-conformance-"));
const {
fixture,
@@ -439,20 +441,23 @@ try {
const manifestSelfTest = await runManagedAppManifestSelfTest();
const operatorManifest = await runOptionalManagedAppManifest();
const ilspyOracle = await runOptionalIlspyOracle();
const completionReport = createManagedCompletionReport({
modern,
framework,
nativeFunctionTarget,
readyToRun,
obfuscated,
left,
right,
nativeOnly,
malformed,
manifestSelfTest,
operatorManifest,
ilspyOracle,
});
const completionReport = createManagedCompletionReport(
{
modern,
framework,
nativeFunctionTarget,
readyToRun,
obfuscated,
left,
right,
nativeOnly,
malformed,
manifestSelfTest,
operatorManifest,
ilspyOracle,
},
await completeVerifierRun(verifierRun),
);
process.stdout.write(
`${JSON.stringify({
+3 -1
View File
@@ -18,8 +18,10 @@ import { verifyPackagePlatform } from "./verify-package-platform.mjs";
import { verifyPackageSetup } from "./verify-package-setup.mjs";
import { verifyManaged } from "./verify-package-managed.mjs";
import { verifyUnknownProvider } from "./verify-package-unknown-provider.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const root = process.cwd();
const verifierRun = createVerifierRun();
const workspace = await mkdtemp(join(tmpdir(), "rea-package-"));
const evidenceRoot = join(workspace, "evidence");
const referenceRoot = join(workspace, "reference-source");
@@ -100,7 +102,7 @@ try {
investigationReplay,
});
process.stdout.write(
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, managedCli: true, managedReconstructionCli: true, managedNativeVerificationCli: true, managedRuntimePlanCli: true, managedApplicationGraphCli: true, evidenceCli: true, incurMcpCommand: PRODUCT_IDENTITY.mcpCommand, lifecycleScriptsRequired: false, doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 3 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, configSymlinkLifecycle: supportedSetupHost, skill: supportedSetupHost, skillReferences: supportedSetupHost, mcpTools: TOOL_CONTRACTS.length, mcpPrompts: prompts.names.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: true })}\n`,
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), cli: true, analysisCli: true, artifactCli: true, managedCli: true, managedReconstructionCli: true, managedNativeVerificationCli: true, managedRuntimePlanCli: true, managedApplicationGraphCli: true, evidenceCli: true, incurMcpCommand: PRODUCT_IDENTITY.mcpCommand, lifecycleScriptsRequired: false, doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 3 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, configSymlinkLifecycle: supportedSetupHost, skill: supportedSetupHost, skillReferences: supportedSetupHost, mcpTools: TOOL_CONTRACTS.length, mcpPrompts: prompts.names.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: true })}\n`,
);
} finally {
if (tarball) await rm(join(root, tarball), { force: true });
+3 -1
View File
@@ -5,7 +5,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { CATALOG_IDENTITY } from "../dist/catalogIdentity.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const verifierRun = createVerifierRun();
const version = process.argv[2];
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(version ?? ""))
throw new Error("Usage: node scripts/verify-published-package.mjs <version>");
@@ -75,5 +77,5 @@ try {
}
process.stdout.write(
`${JSON.stringify({ package: "rea-agents", version, mcpTools: publishedToolCount, canonicalMcpTools: CATALOG_IDENTITY.counts.mcp_tools })}\n`,
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), package: "rea-agents", version, mcpTools: publishedToolCount, canonicalMcpTools: CATALOG_IDENTITY.counts.mcp_tools })}\n`,
);
+3
View File
@@ -21,6 +21,7 @@ import {
import { startBrowserVerifierSite } from "./fixtures/browser-verifier-site.mjs";
import { startPageCdpProxy } from "./fixtures/page-cdp-proxy.mjs";
import { sourceMapSummary } from "./lib/browser-verifier-assertions.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const SECRET_VALUES = [
"network-secret-value",
@@ -29,6 +30,7 @@ const SECRET_VALUES = [
"websocket-secret-value",
"ax-private-label-value",
];
const verifierRun = createVerifierRun();
const executable = await browserExecutable();
const profile = await mkdtemp(join(tmpdir(), "rea-real-browser-"));
@@ -209,6 +211,7 @@ try {
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
browser: observed.value.browser.product,
endpoint,
target,
+6 -1
View File
@@ -25,6 +25,9 @@ import { GhidraHeadlessLauncher } from "../dist/ghidra/GhidraLauncher.js";
import { GHIDRA_PROVIDER_IDENTITY } from "../dist/ghidra/GhidraProvider.js";
import { GHIDRA_SESSION_CAPABILITIES as SESSION_CAPABILITIES } from "../dist/ghidra/GhidraSessionValues.js";
import { parseBinaryTarget } from "../dist/domain/binaryTarget.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const verifierRun = createVerifierRun();
if (process.platform !== "win32" || process.arch !== "x64")
throw new Error(
@@ -191,7 +194,9 @@ try {
}
if (report === undefined)
throw new Error("Windows Ghidra report was not produced");
process.stdout.write(`${JSON.stringify(report)}\n`);
process.stdout.write(
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), ...report })}\n`,
);
async function inventory(operation, parameters) {
const input = parseGhidraInventoryInput(operation, parameters);
+3
View File
@@ -33,8 +33,10 @@ import {
call,
verifyInventoryOperations,
} from "./verify-real-ghidra-inventory.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const exec = promisify(execFile);
const verifierRun = createVerifierRun();
const installDir = process.env.GHIDRA_INSTALL_DIR;
if (installDir === undefined || !isAbsolute(installDir))
throw new Error(
@@ -150,6 +152,7 @@ try {
customPath === undefined ? null : await verifyTarget(customPath, "custom");
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
ok: true,
provider: { id: "ghidra", version: SUPPORTED_GHIDRA_VERSION },
fixture_sources: [sourcePath, crossFormatSourcePath],
+3
View File
@@ -4,7 +4,10 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import { createVerifierRun } from "./lib/verifier-run.mjs";
const execFileAsync = promisify(execFile);
createVerifierRun();
if (process.platform !== "linux")
throw new Error("Linux real-Hopper verification must run on Linux");
+4 -1
View File
@@ -27,7 +27,9 @@ import {
requireWorkflowEvidenceProvider,
} from "./lib/mcp-verifier-results.mjs";
import { openAndVerifyLargeFixture } from "./lib/real-hopper-pagination.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const execFileAsync = promisify(execFile);
const verifierRun = createVerifierRun();
const timeout = 180_000;
const parseServerArgs = (encoded) => {
const parsed = JSON.parse(encoded);
@@ -482,9 +484,10 @@ if (
}
if (summary === undefined)
throw new Error("Real-Hopper verification did not produce a summary");
const completedVerifierRun = await completeVerifierRun(verifierRun);
await new Promise((resolve, reject) => {
process.stdout.write(
`${JSON.stringify({ ...summary, cleanShutdown: true }, null, 2)}\n`,
`${JSON.stringify({ verifier_run: completedVerifierRun, ...summary, cleanShutdown: true }, null, 2)}\n`,
(cause) => {
if (cause) reject(cause);
else resolve();
+6 -1
View File
@@ -8,6 +8,9 @@ import { runControlledReplay } from "../dist/application/JavaScriptReplayService
import { createPermissionPolicy } from "../dist/domain/permissionPolicy.js";
import { LinuxJavaScriptReplayRunner } from "../dist/replay/LinuxJavaScriptReplayRunner.js";
import { SystemJavaScriptReplayHost } from "../dist/replay/SystemJavaScriptReplayHost.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const verifierRun = createVerifierRun();
const suppliedInputPath = process.env.REA_REPLAY_INPUT_PATH;
const suppliedInput =
@@ -147,7 +150,7 @@ const planned = await runControlledReplay(dependencies, input);
if (!planned.ok) {
if (process.env.REA_REPLAY_ALLOW_UNAVAILABLE === "true") {
process.stdout.write(
`${JSON.stringify({ available: false, error_tag: planned.error._tag })}\n`,
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), available: false, error_tag: planned.error._tag })}\n`,
);
process.exit(0);
}
@@ -179,6 +182,7 @@ if (
if (suppliedInput !== undefined) {
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
available: true,
supplied_manifest: true,
plan_digest: plan.plan_digest,
@@ -320,6 +324,7 @@ if (memory.termination !== "oom" || memory.cleanup.state !== "complete")
);
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
available: true,
plan_digest: plan.plan_digest,
evidence_id: evidence.evidence_id,
+3
View File
@@ -10,8 +10,10 @@ import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
const exec = promisify(execFile);
const verifierRun = createVerifierRun();
const root = process.cwd();
const workspace = await mkdtemp(join(tmpdir(), "rea-windows-package-"));
const prefix = join(workspace, "prefix");
@@ -98,6 +100,7 @@ try {
process.stdout.write(
`${JSON.stringify({
verifier_run: await completeVerifierRun(verifierRun),
ok: true,
platform: process.platform,
package: packageResult.filename,