From 2b9156bcb6415e6ca79dcde2ebd40cd0ae0097d5 Mon Sep 17 00:00:00 2001 From: Dotta Date: Wed, 7 Oct 2026 20:36:33 -0500 Subject: [PATCH] fix(hermes): preserve pinned setup configuration and verify runtime files Co-Authored-By: Paperclip --- doc/plans/2026-10-06-hermes-native-runner.md | 26 ++++++++- packages/paperclip-runner/package.json | 2 +- .../scripts/hermes-provisioning-config.mjs | 18 +++++++ .../hermes-provisioning-config.test.mjs | 14 +++++ .../scripts/provision-hermes.mjs | 8 ++- .../scripts/setup-hermes-runtime.mjs | 8 ++- .../acpx/hermes-setup-integrity.test.ts | 53 +++++++++++++++++++ .../drivers/acpx/hermes-setup-integrity.ts | 12 +++++ 8 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 packages/paperclip-runner/scripts/hermes-provisioning-config.mjs create mode 100644 packages/paperclip-runner/scripts/hermes-provisioning-config.test.mjs create mode 100644 packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.test.ts create mode 100644 packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.ts diff --git a/doc/plans/2026-10-06-hermes-native-runner.md b/doc/plans/2026-10-06-hermes-native-runner.md index 54a354e9268..6603da40df4 100644 --- a/doc/plans/2026-10-06-hermes-native-runner.md +++ b/doc/plans/2026-10-06-hermes-native-runner.md @@ -770,7 +770,7 @@ share the pinned download/materialization operation. Python/ACP/ACPX pins and th native bridge bytes are unchanged. Provisioning scratch and uv downloads remain owned temporary files and are removed after settlement. -The new setup/layout/cache/CLI checks passed 20 tests. Runner and CLI TypeScript +The focused setup/layout/cache/CLI checks passed 20 tests. Runner and CLI TypeScript checks, the runner TypeScript build, generated protocol/profile checks and diff checks passed. An additional package/model selection invocation passed 25 tests and failed the standalone-boundary check with five violations. An independent @@ -788,3 +788,27 @@ ledger retains $23 reserved against the $25 cap, not $23 measured spending. Actual Daytona remains blocked on the previously reported token scopes. Successful managed subscriptions, actual Daytona and the full original live interaction/state/routine/distribution criteria remain required before promotion. + +The clean read-only npm-packed Runner artifact at `b9603a3a` contained both +compiled setup entrypoints and the Python materializer. Fresh Mac setup failed +before publishing any runtime: disabling all uv configuration also removed +Hermes's archive-authenticated resolver settings. Credential-free Linux CI +reported the same failure. The source archive and dependency lock passed their +digest checks; neither the lock nor runtime pins were changed. A separate offline +uv check with an explicit configuration derived only from the authenticated +upstream `[tool.uv]` section passed and left the lock unchanged. Provisioning now +uses that explicit configuration instead of discovering operator/system settings, +retains `--locked`, and checks the lock digest again after dependency installation. + +Fresh review of `b9603a3a` also correctly identified that setup validated the +inventory but did not read the installed runtime files. Setup now opens and closes +the same verified native snapshot used at admission before accepting existing +assets or publishing new ones. It never starts Hermes for this check. Regression +tests cover changed bridge bytes, a missing interpreter, and a substituted +entrypoint symlink while keeping the original manifest intact. All 14 focused +Runner Vitest tests and seven provisioner/build Node tests pass; Runner TypeScript +and the pinned-toolchain TypeScript build pass. The earlier failed packed setup +and Linux CI remain failures. Corrected +fresh installation, public server/CLI consumer execution and new-head CI/review +are still required; no release qualification or successful clean-consumer run is +claimed by these corrections. diff --git a/packages/paperclip-runner/package.json b/packages/paperclip-runner/package.json index cc112f4a8bf..2b1be164b03 100644 --- a/packages/paperclip-runner/package.json +++ b/packages/paperclip-runner/package.json @@ -75,7 +75,7 @@ "typecheck:browser": "tsc -p tsconfig.browser.json --noEmit", "test": "pnpm run test:typescript && pnpm run test:rust", "test:typescript": "pnpm run test:typescript:prep && vitest run", - "test:typescript:prep": "pnpm run ensure:eval-build-deps && pnpm run build:rust && node --test test/protocol-contract.test.mjs test/acpx-sidecar-contract.test.mjs test/acpx-codex-package-contract.test.mjs test/acpx-model-selection-package-contract.test.mjs test/acpx-rich-extensions-package-contract.test.mjs test/acpx-pi-receipt-package-contract.test.mjs test/acpx-response-delivery-package-contract.test.mjs scripts/candidate-provider-pack.test.mjs scripts/cursor-provisioner-layout.test.mjs scripts/hermes-provisioner-layout.test.mjs scripts/release-provider-pack.test.mjs scripts/aws-agentcore-provisioning.test.mjs scripts/build-verified-provider-entrypoints.test.mjs scripts/local-provider-smoke-environment.test.mjs scripts/materialize-opencode-binary.test.mjs", + "test:typescript:prep": "pnpm run ensure:eval-build-deps && pnpm run build:rust && node --test test/protocol-contract.test.mjs test/acpx-sidecar-contract.test.mjs test/acpx-codex-package-contract.test.mjs test/acpx-model-selection-package-contract.test.mjs test/acpx-rich-extensions-package-contract.test.mjs test/acpx-pi-receipt-package-contract.test.mjs test/acpx-response-delivery-package-contract.test.mjs scripts/candidate-provider-pack.test.mjs scripts/cursor-provisioner-layout.test.mjs scripts/hermes-provisioner-layout.test.mjs scripts/hermes-provisioning-config.test.mjs scripts/release-provider-pack.test.mjs scripts/aws-agentcore-provisioning.test.mjs scripts/build-verified-provider-entrypoints.test.mjs scripts/local-provider-smoke-environment.test.mjs scripts/materialize-opencode-binary.test.mjs", "test:typescript:vitest": "node ./scripts/run-pr-vitest-lane.mjs", "test:rust": "cargo test --release --manifest-path runner/Cargo.toml --locked --workspace", "test:codex": "cargo test --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --test codex_provider", diff --git a/packages/paperclip-runner/scripts/hermes-provisioning-config.mjs b/packages/paperclip-runner/scripts/hermes-provisioning-config.mjs new file mode 100644 index 00000000000..249ad141757 --- /dev/null +++ b/packages/paperclip-runner/scripts/hermes-provisioning-config.mjs @@ -0,0 +1,18 @@ +/** Project settings come only from the already archive-authenticated source. + * --config-file prevents uv from merging operator or system configuration. + * This extraction supports the pinned upstream table layout, not arbitrary TOML. + */ +export function hermesProvisioningConfig(pyproject) { + const lines = pyproject.split(/\r?\n/); + const roots = lines.flatMap((line, index) => line === "[tool.uv]" ? [index] : []); + if (roots.length !== 1) throw new Error("Hermes pinned source must contain one uv configuration table"); + const body = []; + for (const line of lines.slice(roots[0] + 1)) { + if (line.startsWith("[")) { + if (!line.startsWith("[tool.uv.")) break; + if (!/^\[tool\.uv\.[a-zA-Z][a-zA-Z0-9_.-]*\]$/.test(line)) throw new Error("Hermes pinned uv table layout is unsupported"); + body.push(line.replace("[tool.uv.", "[")); + } else body.push(line); + } + return body.join("\n") + "\n"; +} diff --git a/packages/paperclip-runner/scripts/hermes-provisioning-config.test.mjs b/packages/paperclip-runner/scripts/hermes-provisioning-config.test.mjs new file mode 100644 index 00000000000..740c17b8f77 --- /dev/null +++ b/packages/paperclip-runner/scripts/hermes-provisioning-config.test.mjs @@ -0,0 +1,14 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { hermesProvisioningConfig } from "./hermes-provisioning-config.mjs"; + +test("preserves pinned resolver context without selecting unrelated project tables", () => { + const settings = 'override-dependencies = ["cryptography>=50,<51"]\nexclude-newer = "14 days"\n\n[exclude-newer-package]\nanthropic = false\n'; + assert.equal(hermesProvisioningConfig('[project]\nname = "hermes-agent"\n[tool.uv]\n' + settings.replace("[exclude-newer-package]", "[tool.uv.exclude-newer-package]") + '[tool.setuptools]\npackages = ["ambient"]\n'), settings); +}); + +test("rejects missing, repeated or unsupported pinned uv table layouts", () => { + for (const source of ['[project]\nname = "hermes-agent"', '[tool.uv]\n[tool.uv]\n', '[tool.uv]\n[tool.uv."unsupported"]\n']) { + assert.throws(() => hermesProvisioningConfig(source), /pinned/); + } +}); diff --git a/packages/paperclip-runner/scripts/provision-hermes.mjs b/packages/paperclip-runner/scripts/provision-hermes.mjs index fa046677e3f..de948eadc97 100644 --- a/packages/paperclip-runner/scripts/provision-hermes.mjs +++ b/packages/paperclip-runner/scripts/provision-hermes.mjs @@ -4,6 +4,7 @@ import { access, lstat, mkdir, mkdtemp, readFile, realpath, rename, rm, writeFil import { dirname, isAbsolute, join, resolve } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { HERMES_CLOSURES } from "../src/drivers/acpx/hermes-distributions.ts"; +import { hermesProvisioningConfig } from "./hermes-provisioning-config.mjs"; const digest = bytes => createHash("sha256").update(bytes).digest("hex"); @@ -21,7 +22,7 @@ export async function materializePinnedHermesDistribution({ destination, provide const source = join(temporary, "source"); const prepared = join(temporary, "distribution"); const env = { PATH: process.env.PATH ?? "/usr/bin:/bin", LANG: "C.UTF-8", HOME: join(temporary, "home"), - UV_CACHE_DIR: join(temporary, "uv-cache"), UV_PYTHON_INSTALL_DIR: join(temporary, "uv-python"), UV_NO_CONFIG: "1" }; + UV_CACHE_DIR: join(temporary, "uv-cache"), UV_PYTHON_INSTALL_DIR: join(temporary, "uv-python") }; try { await mkdir(source, { mode: 0o700 }); await mkdir(env.HOME, { mode: 0o700 }); @@ -37,8 +38,11 @@ export async function materializePinnedHermesDistribution({ destination, provide await writeFile(archive, bytes, { mode: 0o600, flag: "wx" }); execFileSync("tar", ["-xzf", archive, "--strip-components=1", "-C", source], { env, timeout: 30000 }); if (digest(await readFile(join(source, "uv.lock"))) !== version.lockSha256) throw new Error("Hermes dependency lock digest mismatch"); - execFileSync("uv", ["sync", "--locked", "--no-dev", "--no-install-project", "--python", version.python, + const configFile = join(temporary, "uv.toml"); + await writeFile(configFile, hermesProvisioningConfig(await readFile(join(source, "pyproject.toml"), "utf8")), { mode: 0o600, flag: "wx" }); + execFileSync("uv", ["sync", "--locked", "--config-file", configFile, "--no-dev", "--no-install-project", "--python", version.python, "--extra", "acp", "--extra", "mcp", "--extra", "anthropic", "--extra", "bedrock", "--extra", "google"], { cwd: source, env, stdio: "inherit", timeout: 300000 }); + if (digest(await readFile(join(source, "uv.lock"))) !== version.lockSha256) throw new Error("Hermes dependency lock changed during installation"); execFileSync(join(source, ".venv/bin/python"), [materializer, source, prepared, provider], { env, stdio: "inherit", timeout: 120000 }); const manifest = JSON.parse(await readFile(join(prepared, "manifest.json"), "utf8")); if (digest(JSON.stringify(manifest.entries)) !== expectedClosureSha256) throw new Error("Hermes provisioned closure does not match its reviewed pin"); diff --git a/packages/paperclip-runner/scripts/setup-hermes-runtime.mjs b/packages/paperclip-runner/scripts/setup-hermes-runtime.mjs index 5ecfe57096f..a2dc56ec979 100644 --- a/packages/paperclip-runner/scripts/setup-hermes-runtime.mjs +++ b/packages/paperclip-runner/scripts/setup-hermes-runtime.mjs @@ -2,7 +2,7 @@ import { lstat, readFile } from "node:fs/promises"; import { join } from "node:path"; import { HERMES_CLOSURES } from "../src/drivers/acpx/hermes-distributions.ts"; -import { verifyNativeAcpxInstallation } from "../src/drivers/acpx/installation-integrity.ts"; +import { verifyHermesRuntimeFiles } from "../src/drivers/acpx/hermes-setup-integrity.ts"; import { hermesProvisionerDestination, hermesProvisionerLayout } from "./hermes-provisioner-layout.mjs"; import { materializePinnedHermesDistribution } from "./provision-hermes.mjs"; @@ -14,14 +14,12 @@ export async function provisionHermesRuntime() { const closureSha256 = HERMES_CLOSURES[platform]; if (!closureSha256) throw new Error(`Hermes has no reviewed distribution for ${platform}`); const destination = hermesProvisionerDestination(import.meta.url, closureSha256, process.platform, process.arch); - const verify = (distributionRoot, expectedClosureSha256) => verifyNativeAcpxInstallation({ distributionRoot, expectedClosureSha256, - manifestPath: join(distributionRoot, "manifest.json"), executable: "python/bin/python3.12", pythonEntrypoint: "entry.py", fixedArguments: [] }); const installed = await lstat(destination).catch(error => { if (error.code !== "ENOENT") throw error; return null; }); if (installed) { if (!installed.isDirectory() || installed.isSymbolicLink()) throw new Error("Hermes runtime assets must be a real directory"); - await verify(destination, closureSha256); + await verifyHermesRuntimeFiles(destination, closureSha256); } else { - await materializePinnedHermesDistribution({ destination, provider: layout.provider, materializer: layout.materializer, verify }); + await materializePinnedHermesDistribution({ destination, provider: layout.provider, materializer: layout.materializer, verify: verifyHermesRuntimeFiles }); } const version = JSON.parse(await readFile(join(layout.provider, "version.json"), "utf8")); console.log(`Verified Hermes ${version.release} (${platform}), Python ${version.python}`); diff --git a/packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.test.ts b/packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.test.ts new file mode 100644 index 00000000000..710ac93a6f7 --- /dev/null +++ b/packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.test.ts @@ -0,0 +1,53 @@ +import { createHash } from "node:crypto"; +import { chmod, lstat, mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { expect, it } from "vitest"; +import { verifyHermesRuntimeFiles } from "./hermes-setup-integrity.js"; + +async function distribution(run: (root: string, pin: string) => Promise) { + const root = await realpath(await mkdtemp(join(tmpdir(), "paperclip-hermes-setup-test-"))); + try { + await mkdir(join(root, "python/bin"), { recursive: true }); + const files = ["bridge.py", "entry.py", "python/bin/python3.12"]; + for (const path of files) { + await writeFile(join(root, path), path.endsWith("python3.12") ? '#!/bin/sh\ntouch "$PWD/unexpected-spawn"\n' : "# verified\n"); + await chmod(join(root, path), path.endsWith("python3.12") ? 0o700 : 0o600); + } + const entries = await Promise.all(files.map(async path => ({ + path, sha256: createHash("sha256").update(await readFile(join(root, path))).digest("hex"), + size: (await lstat(join(root, path))).size, executable: path.endsWith("python3.12"), + }))); + await writeFile(join(root, "manifest.json"), JSON.stringify({ entries })); + await run(root, createHash("sha256").update(JSON.stringify(entries)).digest("hex")); + } finally { await rm(root, { recursive: true, force: true }); } +} + +it("checks intact runtime files without executing the interpreter", async () => { + await distribution(async (root, pin) => { + await verifyHermesRuntimeFiles(root, pin); + await expect(lstat(join(root, "unexpected-spawn"))).rejects.toMatchObject({ code: "ENOENT" }); + }); +}); + +it("rejects modified runtime bytes even with an unchanged valid manifest", async () => { + await distribution(async (root, pin) => { + await writeFile(join(root, "bridge.py"), "# modified\n"); + await expect(verifyHermesRuntimeFiles(root, pin)).rejects.toThrow("file digest mismatch"); + }); +}); + +it("rejects a missing interpreter even with an unchanged valid manifest", async () => { + await distribution(async (root, pin) => { + await rm(join(root, "python/bin/python3.12")); + await expect(verifyHermesRuntimeFiles(root, pin)).rejects.toMatchObject({ code: "ENOENT" }); + }); +}); + +it("rejects a symbolic link substituted for the native entrypoint", async () => { + await distribution(async (root, pin) => { + await rm(join(root, "entry.py")); + await symlink("bridge.py", join(root, "entry.py")); + await expect(verifyHermesRuntimeFiles(root, pin)).rejects.toThrow("symbolic link"); + }); +}); diff --git a/packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.ts b/packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.ts new file mode 100644 index 00000000000..3898f7e9704 --- /dev/null +++ b/packages/paperclip-runner/src/drivers/acpx/hermes-setup-integrity.ts @@ -0,0 +1,12 @@ +import { join } from "node:path"; +import { verifyNativeAcpxInstallation } from "./installation-integrity.js"; + +/** Setup verifies the same execution bytes as admission without spawning Hermes. */ +export async function verifyHermesRuntimeFiles(distributionRoot: string, expectedClosureSha256: string): Promise { + const installation = await verifyNativeAcpxInstallation({ + distributionRoot, expectedClosureSha256, manifestPath: join(distributionRoot, "manifest.json"), + executable: "python/bin/python3.12", pythonEntrypoint: "entry.py", fixedArguments: [], + }); + const lease = await installation.openCommand(); + await lease.close(); +}