fix(hermes): preserve pinned setup configuration and verify runtime files

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-08 02:35:36 -05:00
1 parent 6443853823
commit 2b9156bcb6
8 files changed
+132 -9

No files matched your search

+25 -1
View File
@@ -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.
+1 -1
View File
@@ -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",
@@ -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";
}
@@ -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/);
}
});
@@ -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");
@@ -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}`);
@@ -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<void>) {
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");
});
});
@@ -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<void> {
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();
}