From 08667e0f72d4199e399e24de564d0717e6a69ede Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 15:21:26 -0700 Subject: [PATCH 01/23] fix(e2e): restore Hermes fallback forward ownership Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 9 +++++++-- test/e2e/support/hermes-gpu-startup-fallback.test.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index e1825051ed0..ff4a1e3177e 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -82,8 +82,10 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native * `--gpu` create before build or sandbox progress. The compatibility create - * and its GPU proof delegate to the real CLI. Every other invocation also - * transparently delegates its original argv. This + * and its GPU proof delegate to the real CLI. After the proof, the wrapper + * replaces itself with a link to the real CLI so later ForwardTcp ownership + * checks see the executable that owns each listener. Every other invocation + * also transparently delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -150,6 +152,9 @@ export function createHermesGpuFallbackWrapper( "", 'if [[ "$is_native_nvidia_smi_proof" == "1" && -d "$NATIVE_CREATE_REJECTED" ]]; then', ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}' >>"$FALLBACK_STATE_DIR/events.log"`, + ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', + ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', + ' mv -f "$REAL_OPENSHELL_LINK" "$0"', "fi", "", "# Transparent test-only delegation: argv is never written by this wrapper.", diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 17f1aec4c7d..6529a1d72e0 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -124,8 +124,8 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("rejects native create before progress and delegates one compatibility attempt (#10155)", () => { - const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { + it("retires fault injection before ForwardTcp restore after one compatibility attempt (#11239)", () => { + const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ "#!/usr/bin/env bash", "marker=delegated", @@ -189,6 +189,8 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { env, ); expect(compatibilityProof.status, compatibilityProof.stderr).toBe(0); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); const version = runWrapper(wrapper.wrapperPath, ["--version"], env); expect(version.status, version.stderr).toBe(0); @@ -204,7 +206,9 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { fs.readFileSync(path.join(path.dirname(wrapper.eventsPath), entry.name), "utf8"), ) .join("\n"); - expect(secretMarkers.every((secretMarker) => !wrapperArtifacts.includes(secretMarker))).toBe(true); + expect(secretMarkers.every((secretMarker) => !wrapperArtifacts.includes(secretMarker))).toBe( + true, + ); expect(wrapperArtifacts).not.toMatch(/(?:TOKEN|API_KEY|PASSWORD)=/u); // The fake delegate records a constant marker only; it never serializes argv. expect(fs.readFileSync(delegateMarkerLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ From 2ffc67d7f92319f7d255bb5845823bec64aa026c Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 15:50:33 -0700 Subject: [PATCH 02/23] fix(e2e): register Hermes fallback parity owner Signed-off-by: Aaron Erickson --- test/e2e/mock-parity.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index c787ae65d88..9ddce210add 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -120,7 +120,10 @@ }, { "live": "test/e2e/live/hermes-gpu-startup.test.ts", - "liveSources": ["test/e2e/live/hermes-gpu-startup-proof.ts"], + "liveSources": [ + "test/e2e/live/hermes-gpu-startup-fallback.ts", + "test/e2e/live/hermes-gpu-startup-proof.ts" + ], "fast": [ "test/e2e/support/hermes-gpu-startup-fallback.test.ts", "test/e2e/support/hermes-gpu-startup-integrity.test.ts", From 04d1207cef5bb3c75c8bf40acbbf9b1441746c7f Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 16:21:28 -0700 Subject: [PATCH 03/23] fix(e2e): fence Hermes fallback handoff Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 28 +++++++++++++--- test/e2e/live/hermes-gpu-startup.test.ts | 2 +- .../hermes-gpu-startup-fallback.test.ts | 32 ++++++++++++++++++- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index ff4a1e3177e..8aa3d858b6a 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -120,6 +120,7 @@ export function createHermesGpuFallbackWrapper( `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, `NATIVE_NVIDIA_SMI_PROOF=${quoteShellLiteral(HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF)}`, 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', + 'COMPATIBILITY_CREATE_COMPLETED="$FALLBACK_STATE_DIR/compatibility-create-completed"', "", "is_sandbox_create=0", "has_gpu_flag=0", @@ -142,6 +143,16 @@ export function createHermesGpuFallbackWrapper( " exit 2", " else", ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}' >>"$FALLBACK_STATE_DIR/events.log"`, + " set +e", + ' "$REAL_OPENSHELL" "$@"', + " compatibility_status=$?", + " set -e", + ' case "$compatibility_status" in', + " 0)", + ' mkdir "$COMPATIBILITY_CREATE_COMPLETED"', + " exit 0;;", + ' *) exit "$compatibility_status";;', + " esac", " fi", "fi", "", @@ -150,11 +161,20 @@ export function createHermesGpuFallbackWrapper( " is_native_nvidia_smi_proof=1", "fi", "", - 'if [[ "$is_native_nvidia_smi_proof" == "1" && -d "$NATIVE_CREATE_REJECTED" ]]; then', + 'if [[ "$is_native_nvidia_smi_proof" == "1" && -d "$NATIVE_CREATE_REJECTED" && -d "$COMPATIBILITY_CREATE_COMPLETED" ]]; then', ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}' >>"$FALLBACK_STATE_DIR/events.log"`, - ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', - ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', - ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + " set +e", + ' "$REAL_OPENSHELL" "$@"', + " proof_status=$?", + " set -e", + ' case "$proof_status" in', + " 0)", + ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', + ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', + ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + " exit 0;;", + ' *) exit "$proof_status";;', + " esac", "fi", "", "# Transparent test-only delegation: argv is never written by this wrapper.", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 4c53e3e2db6..cf93654b2aa 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, then delegate one compatibility create and GPU proof", + "reject the exact native --gpu create before progress, delegate the compatibility create and GPU proof, then replace the wrapper path with a link to the real OpenShell CLI", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 6529a1d72e0..e6364ef08dc 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -124,7 +124,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("retires fault injection before ForwardTcp restore after one compatibility attempt (#11239)", () => { + it("replaces the wrapper with the real OpenShell CLI after the fallback GPU proof (#11239)", () => { const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ "#!/usr/bin/env bash", @@ -219,6 +219,36 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); + it("keeps native fault injection when the exact proof precedes compatibility create (#11239)", () => { + const { wrapper } = createWrapperFixture("hermes-gpu-fallback-order-test-"); + const env = { ...process.env, ...wrapper.componentEnv }; + + const firstNativeCreate = runWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu"], + env, + ); + expect(firstNativeCreate.status).toBe(2); + + const prematureProof = runWrapper( + wrapper.wrapperPath, + ["sandbox", "exec", "-n", "alpha", "--", "sh", "-lc", HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF], + env, + ); + expect(prematureProof.status, prematureProof.stderr).toBe(0); + expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); + + const secondNativeCreate = runWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu"], + env, + ); + expect(secondNativeCreate.status).toBe(2); + expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ + HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, + ]); + }); + it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", From 7f565b684ca6f6c542d30d1d5acfb14fc1024ada Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 16:55:07 -0700 Subject: [PATCH 04/23] fix(e2e): retire fallback wrapper before forwarding Signed-off-by: Aaron Erickson --- ci/e2e-assertion-budget.json | 14 ++--- test/e2e/live/hermes-gpu-startup-fallback.ts | 52 +++++-------------- test/e2e/live/hermes-gpu-startup.test.ts | 3 +- .../hermes-gpu-startup-fallback.test.ts | 44 ++++++++++++++-- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index 385c46ff1d3..487832d9a6c 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -21,8 +21,8 @@ "namedAssertionHelpers": 601, "failCalls": 8, "throwGuards": 87, - "objectFieldAssertions": 245, - "assertionPoints": 2820, + "objectFieldAssertions": 244, + "assertionPoints": 2819, "generatedProbeBlocks": 124, "generatedProbeConditions": 332 }, @@ -33,10 +33,10 @@ "namedAssertionHelpers": 904, "failCalls": 38, "throwGuards": 631, - "objectFieldAssertions": 348, - "assertionPoints": 4306, - "generatedProbeBlocks": 279, - "generatedProbeConditions": 954 + "objectFieldAssertions": 347, + "assertionPoints": 4305, + "generatedProbeBlocks": 278, + "generatedProbeConditions": 953 }, "fileMetricOrder": [ "directExpectCalls", @@ -68,7 +68,7 @@ "test/e2e/live/gpu-e2e.test.ts": [40,45,73,91,3], "test/e2e/live/hermes-discord.test.ts": [10,25,17,64,14], "test/e2e/live/hermes-e2e.test.ts": [82,93,112,127,3], - "test/e2e/live/hermes-gpu-startup.test.ts": [19,29,63,108,13], + "test/e2e/live/hermes-gpu-startup.test.ts": [19,28,63,107,12], "test/e2e/live/hermes-inference-switch.test.ts": [61,67,72,92,2], "test/e2e/live/hermes-root-entrypoint-smoke.test.ts": [4,27,4,27,4], "test/e2e/live/hermes-sandbox-secret-boundary.test.ts": [20,27,20,27,4], diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 8aa3d858b6a..09a2d376693 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -10,7 +10,6 @@ import { REQUIRED_OPENSHELL_MCP_FEATURES } from "../../../src/lib/onboard/opensh export const HERMES_GPU_FALLBACK_EVENTS = { rejectNativeCreateBeforeProgress: "reject-native-create-before-progress", delegateCompatibilityCreate: "delegate-compatibility-create", - delegateNvidiaSmiProofAfterFallback: "delegate-nvidia-smi-proof-after-fallback", } as const; export const HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF = [ @@ -81,11 +80,10 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native - * `--gpu` create before build or sandbox progress. The compatibility create - * and its GPU proof delegate to the real CLI. After the proof, the wrapper - * replaces itself with a link to the real CLI so later ForwardTcp ownership - * checks see the executable that owns each listener. Every other invocation - * also transparently delegates its original argv. This + * `--gpu` create before build or sandbox progress. After the compatibility + * create succeeds, the wrapper replaces itself with a link to the real CLI so + * GPU proof and later ForwardTcp ownership checks see the executable that owns + * each listener. Every other invocation transparently delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -118,9 +116,7 @@ export function createHermesGpuFallbackWrapper( ...REQUIRED_OPENSHELL_MCP_FEATURES.map((marker) => `# capability: ${marker}`), `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, - `NATIVE_NVIDIA_SMI_PROOF=${quoteShellLiteral(HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF)}`, 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', - 'COMPATIBILITY_CREATE_COMPLETED="$FALLBACK_STATE_DIR/compatibility-create-completed"', "", "is_sandbox_create=0", "has_gpu_flag=0", @@ -143,40 +139,18 @@ export function createHermesGpuFallbackWrapper( " exit 2", " else", ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}' >>"$FALLBACK_STATE_DIR/events.log"`, - " set +e", - ' "$REAL_OPENSHELL" "$@"', - " compatibility_status=$?", - " set -e", - ' case "$compatibility_status" in', - " 0)", - ' mkdir "$COMPATIBILITY_CREATE_COMPLETED"', - " exit 0;;", - ' *) exit "$compatibility_status";;', - " esac", + ' if "$REAL_OPENSHELL" "$@"; then', + ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', + ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', + ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + " exit 0", + " else", + " compatibility_status=$?", + ' exit "$compatibility_status"', + " fi", " fi", "fi", "", - "is_native_nvidia_smi_proof=0", - 'if [[ "$#" -eq 8 && "${1:-}" == "sandbox" && "${2:-}" == "exec" && "${3:-}" == "-n" && -n "${4:-}" && "${5:-}" == "--" && "${6:-}" == "sh" && "${7:-}" == "-lc" && "${8:-}" == "$NATIVE_NVIDIA_SMI_PROOF" ]]; then', - " is_native_nvidia_smi_proof=1", - "fi", - "", - 'if [[ "$is_native_nvidia_smi_proof" == "1" && -d "$NATIVE_CREATE_REJECTED" && -d "$COMPATIBILITY_CREATE_COMPLETED" ]]; then', - ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}' >>"$FALLBACK_STATE_DIR/events.log"`, - " set +e", - ' "$REAL_OPENSHELL" "$@"', - " proof_status=$?", - " set -e", - ' case "$proof_status" in', - " 0)", - ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', - ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', - ' mv -f "$REAL_OPENSHELL_LINK" "$0"', - " exit 0;;", - ' *) exit "$proof_status";;', - " esac", - "fi", - "", "# Transparent test-only delegation: argv is never written by this wrapper.", 'exec "$REAL_OPENSHELL" "$@"', "", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index cf93654b2aa..2b025eb3415 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, delegate the compatibility create and GPU proof, then replace the wrapper path with a link to the real OpenShell CLI", + "reject the exact native --gpu create before progress, then replace the wrapper path with a link to the real OpenShell CLI after the compatibility create succeeds", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; @@ -487,7 +487,6 @@ test( expect(fallbackEvents).toEqual([ HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, - HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback, ]); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index e6364ef08dc..d254f816bea 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -124,7 +124,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("replaces the wrapper with the real OpenShell CLI after the fallback GPU proof (#11239)", () => { + it("replaces the wrapper with the real OpenShell CLI after compatibility create succeeds (#11239)", () => { const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ "#!/usr/bin/env bash", @@ -182,6 +182,15 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { env, ); expect(compatibility.status, compatibility.stderr).toBe(0); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); + + const repeatedCompatibility = runWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + env, + ); + expect(repeatedCompatibility.status, repeatedCompatibility.stderr).toBe(0); const compatibilityProof = runWrapper( wrapper.wrapperPath, @@ -189,15 +198,12 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { env, ); expect(compatibilityProof.status, compatibilityProof.stderr).toBe(0); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); const version = runWrapper(wrapper.wrapperPath, ["--version"], env); expect(version.status, version.stderr).toBe(0); expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, - HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback, ]); const wrapperArtifacts = fs .readdirSync(path.dirname(wrapper.eventsPath), { withFileTypes: true }) @@ -214,6 +220,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(fs.readFileSync(delegateMarkerLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ "delegated", "create-without-gpu", + "create-without-gpu", "delegated", "delegated", ]); @@ -249,6 +256,35 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); + it("keeps native fault injection when compatibility create fails (#11239)", () => { + const { wrapper } = createWrapperFixture("hermes-gpu-fallback-failed-create-test-", { + openshell: [ + "#!/usr/bin/env bash", + 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "create" ]]; then exit 23; fi', + "exit 0", + "", + ].join("\n"), + }); + const env = { ...process.env, ...wrapper.componentEnv }; + + expect( + runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) + .status, + ).toBe(2); + expect( + runWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + env, + ).status, + ).toBe(23); + expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); + expect( + runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) + .status, + ).toBe(2); + }); + it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", From ff135cad3c12b57678db1a752eadf768d2f05451 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 17:25:33 -0700 Subject: [PATCH 05/23] fix(e2e): hand off before compatibility create Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 21 ++++++++++++------- test/e2e/live/hermes-gpu-startup.test.ts | 2 +- .../hermes-gpu-startup-fallback.test.ts | 12 ++++++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 09a2d376693..f9a1b672012 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -80,10 +80,11 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native - * `--gpu` create before build or sandbox progress. After the compatibility - * create succeeds, the wrapper replaces itself with a link to the real CLI so - * GPU proof and later ForwardTcp ownership checks see the executable that owns - * each listener. Every other invocation transparently delegates its original argv. This + * `--gpu` create before build or sandbox progress. Before the compatibility + * create, the wrapper replaces its path with a link to the real CLI so the + * create and later ForwardTcp ownership checks see the executable that owns + * each listener. A failed create restores the wrapper. Every other invocation + * transparently delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -139,13 +140,17 @@ export function createHermesGpuFallbackWrapper( " exit 2", " else", ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}' >>"$FALLBACK_STATE_DIR/events.log"`, - ' if "$REAL_OPENSHELL" "$@"; then', - ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', - ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', - ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + ' WRAPPER_BACKUP="$FALLBACK_STATE_DIR/openshell-wrapper-backup.$$"', + ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', + ' cp -p "$0" "$WRAPPER_BACKUP"', + ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', + ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + ' if "$0" "$@"; then', + ' rm -f "$WRAPPER_BACKUP"', " exit 0", " else", " compatibility_status=$?", + ' mv -f "$WRAPPER_BACKUP" "$0"', ' exit "$compatibility_status"', " fi", " fi", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 2b025eb3415..b06c115ea6d 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, then replace the wrapper path with a link to the real OpenShell CLI after the compatibility create succeeds", + "reject the exact native --gpu create before progress, run the compatibility create through the real OpenShell CLI at the wrapper path, keep that link on success, and restore the wrapper on failure", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index d254f816bea..4d8dd9c9adb 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -124,7 +124,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("replaces the wrapper with the real OpenShell CLI after compatibility create succeeds (#11239)", () => { + it("keeps the real OpenShell CLI at the wrapper path after compatibility create succeeds (#11239)", () => { const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ "#!/usr/bin/env bash", @@ -136,14 +136,17 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { " done", "fi", `printf '%s\\n' "$marker" >>"$E2E_FAKE_DELEGATE_LOG"`, + `printf '%s\\n' "$0" >>"$E2E_FAKE_DELEGATE_EXECUTABLE_LOG"`, "", ].join("\n"), }); const delegateMarkerLog = path.join(root, "delegate-markers.log"); + const delegateExecutableLog = path.join(root, "delegate-executables.log"); const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_DELEGATE_LOG: delegateMarkerLog, + E2E_FAKE_DELEGATE_EXECUTABLE_LOG: delegateExecutableLog, }; const secretMarkers = [ "must-not-enter-wrapper-events", @@ -224,6 +227,13 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { "delegated", "delegated", ]); + expect(fs.readFileSync(delegateExecutableLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ + realOpenshell, + wrapper.wrapperPath, + wrapper.wrapperPath, + wrapper.wrapperPath, + wrapper.wrapperPath, + ]); }); it("keeps native fault injection when the exact proof precedes compatibility create (#11239)", () => { From 06b0a7a1bab8696925632b6cdbb3baf505edd3da Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 18:57:21 -0700 Subject: [PATCH 06/23] fix(deps): update js-yaml security floor Signed-off-by: Aaron Erickson --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 08a05ee0a36..c8b0a7ecae5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@oclif/core": "^4.10.5", "ajv": "^8.17.0", "execa": "^9.6.1", - "js-yaml": "^4.1.1", + "js-yaml": "^4.3.2", "p-retry": "^4.6.2", "qrcode-terminal": "^0.12.0", "smol-toml": "1.7.0", @@ -7069,9 +7069,9 @@ "license": "MIT" }, "node_modules/js-yaml": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz", - "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz", + "integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 5922559ea83..55bf531582f 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "@oclif/core": "^4.10.5", "ajv": "^8.17.0", "execa": "^9.6.1", - "js-yaml": "^4.1.1", + "js-yaml": "^4.3.2", "p-retry": "^4.6.2", "qrcode-terminal": "^0.12.0", "smol-toml": "1.7.0", From 9cc86823e236de7ad609d6a1dc4d9a4543841b97 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 19:47:16 -0700 Subject: [PATCH 07/23] fix(e2e): commit fallback handoff after create Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 45 +++-- test/e2e/live/hermes-gpu-startup.test.ts | 2 +- .../hermes-gpu-startup-fallback.test.ts | 181 +++++++++++++++++- 3 files changed, 209 insertions(+), 19 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index f9a1b672012..b1ee8b55084 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -80,11 +80,13 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native - * `--gpu` create before build or sandbox progress. Before the compatibility - * create, the wrapper replaces its path with a link to the real CLI so the - * create and later ForwardTcp ownership checks see the executable that owns - * each listener. A failed create restores the wrapper. Every other invocation - * transparently delegates its original argv. This + * `--gpu` create before build or sandbox progress. The compatibility create + * runs the real CLI with the wrapper path as argv[0], while the rejecting + * wrapper stays installed. After that create succeeds, the wrapper atomically + * replaces itself with a link to the real CLI so later ForwardTcp ownership + * checks resolve the configured path to the executable that owns each + * listener. A failed or interrupted create leaves the wrapper installed. + * Every other invocation transparently delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -140,19 +142,32 @@ export function createHermesGpuFallbackWrapper( " exit 2", " else", ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}' >>"$FALLBACK_STATE_DIR/events.log"`, - ' WRAPPER_BACKUP="$FALLBACK_STATE_DIR/openshell-wrapper-backup.$$"', + ' COMPATIBILITY_PID=""', + " forward_compatibility_signal() {", + ' local signal="$1"', + ' local status="$2"', + " trap - HUP INT TERM", + ' if [[ -n "$COMPATIBILITY_PID" ]] && kill -0 "$COMPATIBILITY_PID" 2>/dev/null; then', + ' kill "-$signal" "$COMPATIBILITY_PID" 2>/dev/null || true', + " fi", + ' wait "$COMPATIBILITY_PID" 2>/dev/null || true', + ' exit "$status"', + " }", + " trap 'forward_compatibility_signal HUP 129' HUP", + " trap 'forward_compatibility_signal INT 130' INT", + " trap 'forward_compatibility_signal TERM 143' TERM", + ' (exec -a "$0" "$REAL_OPENSHELL" "$@") &', + ' COMPATIBILITY_PID="$!"', + ' wait "$COMPATIBILITY_PID" || {', + ' compatibility_status="$?"', + " trap - HUP INT TERM", + ' exit "$compatibility_status"', + " }", + " trap - HUP INT TERM", ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', - ' cp -p "$0" "$WRAPPER_BACKUP"', ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', ' mv -f "$REAL_OPENSHELL_LINK" "$0"', - ' if "$0" "$@"; then', - ' rm -f "$WRAPPER_BACKUP"', - " exit 0", - " else", - " compatibility_status=$?", - ' mv -f "$WRAPPER_BACKUP" "$0"', - ' exit "$compatibility_status"', - " fi", + " exit 0", " fi", "fi", "", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index b06c115ea6d..6c4ae2d4d4c 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, run the compatibility create through the real OpenShell CLI at the wrapper path, keep that link on success, and restore the wrapper on failure", + "reject the exact native --gpu create before progress, keep the rejecting wrapper installed while the real OpenShell CLI runs with the wrapper argv[0], replace the wrapper with a real-CLI link only after success, and retain the wrapper on failure or interruption", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 4d8dd9c9adb..3f926c3565e 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -6,7 +6,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { buildDirectSandboxGpuProofCommands } from "../../../src/lib/onboard/initial-policy"; import { @@ -63,13 +63,24 @@ function runWrapperConcurrently( args: string[], env: NodeJS.ProcessEnv, ): Promise { + return waitForChild(spawnWrapper(wrapperPath, args, env)); +} + +function spawnWrapper(wrapperPath: string, args: string[], env: NodeJS.ProcessEnv) { + return spawn(wrapperPath, args, { env, stdio: "ignore" }); +} + +function waitForChild(child: ReturnType): Promise { return new Promise((resolve, reject) => { - const child = spawn(wrapperPath, args, { env, stdio: "ignore" }); child.once("error", reject); child.once("close", resolve); }); } +async function waitForFile(filePath: string): Promise { + await vi.waitUntil(() => fs.existsSync(filePath), { interval: 20, timeout: 5_000 }); +} + describe("Hermes GPU startup scenario selection", () => { it.each([ [undefined, false, { route: "native-success", scenario: "native" }], @@ -229,13 +240,47 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); expect(fs.readFileSync(delegateExecutableLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ realOpenshell, - wrapper.wrapperPath, + realOpenshell, wrapper.wrapperPath, wrapper.wrapperPath, wrapper.wrapperPath, ]); }); + it("passes the configured wrapper path as native executable argv[0] before committing the link (#11239)", () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-gpu-fallback-argv0-test-")); + roots.push(root); + const realDir = path.join(root, "real"); + fs.mkdirSync(realDir); + const realOpenshell = path.join(realDir, "openshell"); + fs.symlinkSync(process.execPath, realOpenshell); + writeExecutable(path.join(realDir, "openshell-gateway"), "#!/usr/bin/env bash\nexit 0\n"); + writeExecutable(path.join(realDir, "openshell-sandbox"), "#!/usr/bin/env bash\nexit 0\n"); + const wrapper = createHermesGpuFallbackWrapper(realOpenshell, { + rootDir: path.join(root, "wrapper"), + }); + const argvZeroLog = path.join(root, "argv-zero.log"); + fs.writeFileSync( + path.join(root, "sandbox"), + 'require("node:fs").writeFileSync(process.env.E2E_ARGV_ZERO_LOG, process.argv0);\n', + ); + + const compatibility = spawnSync( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + { + cwd: root, + encoding: "utf8", + env: { ...process.env, ...wrapper.componentEnv, E2E_ARGV_ZERO_LOG: argvZeroLog }, + }, + ); + + expect(compatibility.status, compatibility.stderr).toBe(0); + expect(fs.readFileSync(argvZeroLog, "utf8")).toBe(wrapper.wrapperPath); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); + }); + it("keeps native fault injection when the exact proof precedes compatibility create (#11239)", () => { const { wrapper } = createWrapperFixture("hermes-gpu-fallback-order-test-"); const env = { ...process.env, ...wrapper.componentEnv }; @@ -295,6 +340,136 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ).toBe(2); }); + it("rejects a native create while compatibility handoff is still pending (#11239)", async () => { + const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-pending-test-", { + openshell: [ + "#!/usr/bin/env bash", + 'for arg in "$@"; do', + ' if [[ "$arg" == "--gpu" ]]; then', + ` printf '%s\\n' native-bypass >>"$E2E_FAKE_DELEGATE_LOG"`, + " exit 97", + " fi", + "done", + `printf '%s\\n' compatibility >>"$E2E_FAKE_DELEGATE_LOG"`, + ': >"$E2E_FAKE_READY"', + 'while [[ ! -f "$E2E_FAKE_RELEASE" ]]; do sleep 0.02; done', + "exit 0", + "", + ].join("\n"), + }); + const ready = path.join(root, "compatibility-ready"); + const release = path.join(root, "compatibility-release"); + const delegateLog = path.join(root, "delegate.log"); + const env = { + ...process.env, + ...wrapper.componentEnv, + E2E_FAKE_DELEGATE_LOG: delegateLog, + E2E_FAKE_READY: ready, + E2E_FAKE_RELEASE: release, + }; + const compatibility = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + env, + ); + const compatibilityStatus = waitForChild(compatibility); + await waitForFile(ready); + + expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); + expect( + runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) + .status, + ).toBe(2); + expect(fs.readFileSync(delegateLog, "utf8").trim()).toBe("compatibility"); + + fs.writeFileSync(release, ""); + expect(await compatibilityStatus).toBe(0); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + }); + + it("retains the successful handoff when an overlapping compatibility create fails (#11239)", async () => { + const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-overlap-test-", { + openshell: [ + "#!/usr/bin/env bash", + "mode=failure", + 'for arg in "$@"; do [[ "$arg" == "--fixture-success" ]] && mode=success; done', + 'if [[ "$mode" == "success" ]]; then', + ' ready="$E2E_SUCCESS_READY"', + ' release="$E2E_SUCCESS_RELEASE"', + "else", + ' ready="$E2E_FAILURE_READY"', + ' release="$E2E_FAILURE_RELEASE"', + "fi", + ': >"$ready"', + 'while [[ ! -f "$release" ]]; do sleep 0.02; done', + '[[ "$mode" == "success" ]] && exit 0', + "exit 23", + "", + ].join("\n"), + }); + const successReady = path.join(root, "success-ready"); + const successRelease = path.join(root, "success-release"); + const failureReady = path.join(root, "failure-ready"); + const failureRelease = path.join(root, "failure-release"); + const env = { + ...process.env, + ...wrapper.componentEnv, + E2E_FAILURE_READY: failureReady, + E2E_FAILURE_RELEASE: failureRelease, + E2E_SUCCESS_READY: successReady, + E2E_SUCCESS_RELEASE: successRelease, + }; + const successful = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all", "--fixture-success"], + env, + ); + const successfulStatus = waitForChild(successful); + const failing = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + env, + ); + const failingStatus = waitForChild(failing); + await Promise.all([waitForFile(successReady), waitForFile(failureReady)]); + + fs.writeFileSync(successRelease, ""); + expect(await successfulStatus).toBe(0); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + fs.writeFileSync(failureRelease, ""); + expect(await failingStatus).toBe(23); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + }); + + it("leaves native fault injection installed when compatibility create is interrupted (#11239)", async () => { + const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-interrupt-test-", { + openshell: [ + "#!/usr/bin/env bash", + "trap 'exit 143' HUP INT TERM", + ': >"$E2E_FAKE_READY"', + "while :; do sleep 1; done", + "", + ].join("\n"), + }); + const ready = path.join(root, "compatibility-ready"); + const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready }; + const compatibility = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + env, + ); + const compatibilityStatus = waitForChild(compatibility); + await waitForFile(ready); + + expect(compatibility.kill("SIGTERM")).toBe(true); + expect(await compatibilityStatus).toBe(143); + expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); + expect( + runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) + .status, + ).toBe(2); + }); + it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", From fd691dea55d2170bb04d60c7c29fc221249c7335 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 20:01:19 -0700 Subject: [PATCH 08/23] chore(ci): retrigger PR checks Signed-off-by: Aaron Erickson From b64ff333e02d273590397f8df61d99e10cf50696 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 20:52:17 -0700 Subject: [PATCH 09/23] docs(e2e): clarify overlapping handoff Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 6 ++++-- test/e2e/live/hermes-gpu-startup.test.ts | 2 +- .../hermes-gpu-startup-fallback.test.ts | 18 ++++++------------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index b1ee8b55084..4580b63fb4d 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -85,8 +85,10 @@ function quoteShellLiteral(value: string): string { * wrapper stays installed. After that create succeeds, the wrapper atomically * replaces itself with a link to the real CLI so later ForwardTcp ownership * checks resolve the configured path to the executable that owns each - * listener. A failed or interrupted create leaves the wrapper installed. - * Every other invocation transparently delegates its original argv. This + * listener. A failed or interrupted invocation never changes the wrapper path; + * an overlapping successful invocation may independently commit the terminal + * link and remains authoritative. Every other invocation transparently + * delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 6c4ae2d4d4c..ff5c7841c54 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, keep the rejecting wrapper installed while the real OpenShell CLI runs with the wrapper argv[0], replace the wrapper with a real-CLI link only after success, and retain the wrapper on failure or interruption", + "reject the exact native --gpu create before progress, keep the rejecting wrapper installed while the real OpenShell CLI runs with the wrapper argv[0], replace the wrapper with a real-CLI link only after success, and let failed or interrupted invocations leave the path unchanged while an overlapping success remains authoritative", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 3f926c3565e..5b179155942 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -58,14 +58,6 @@ function runWrapper(wrapperPath: string, args: string[], env: NodeJS.ProcessEnv) return spawnSync(wrapperPath, args, { encoding: "utf8", env }); } -function runWrapperConcurrently( - wrapperPath: string, - args: string[], - env: NodeJS.ProcessEnv, -): Promise { - return waitForChild(spawnWrapper(wrapperPath, args, env)); -} - function spawnWrapper(wrapperPath: string, args: string[], env: NodeJS.ProcessEnv) { return spawn(wrapperPath, args, { env, stdio: "ignore" }); } @@ -585,10 +577,12 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { const env = { ...process.env, ...wrapper.componentEnv }; const statuses = await Promise.all( Array.from({ length: 8 }, () => - runWrapperConcurrently( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu"], - env, + waitForChild( + spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu"], + env, + ), ), ), ); From 6090e7104d9c0bb0fe175ad04e45af6faa2fe237 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 21:35:32 -0700 Subject: [PATCH 10/23] fix(e2e): accept trusted manual image publication Signed-off-by: Aaron Erickson --- .../support/base-image-publication.test.ts | 58 +++++++++++++++++++ tools/e2e/base-image-publication.mts | 36 ++++++++++-- 2 files changed, 88 insertions(+), 6 deletions(-) diff --git a/test/e2e/support/base-image-publication.test.ts b/test/e2e/support/base-image-publication.test.ts index a023adc433a..0854755db8f 100644 --- a/test/e2e/support/base-image-publication.test.ts +++ b/test/e2e/support/base-image-publication.test.ts @@ -119,6 +119,7 @@ function selectedRun(overrides: Partial = {}): PublicationRun { return { id: RUN_ID, attempt: 1, + event: "push", workflowId: WORKFLOW_ID, headSha: RELEVANT_SHA, status: "completed", @@ -477,6 +478,32 @@ describe("base-image publication evidence", () => { }); }); + it("accepts an exact successful manual main publication for branch reuse", () => { + const selection = selectPublicationRun( + runsPayload([workflowRun({ event: "workflow_dispatch" })]), + history(), + WORKFLOW_ID, + { allowWorkflowDispatch: true, completedSuccessOnly: true }, + ); + + expect(selection).toMatchObject({ + state: "selected", + run: { + id: RUN_ID, + event: "workflow_dispatch", + headSha: RELEVANT_SHA, + conclusion: "success", + }, + }); + expect(() => + selectPublicationRun( + runsPayload([workflowRun({ event: "workflow_dispatch" })]), + history(), + WORKFLOW_ID, + ), + ).toThrow(/event must be push/u); + }); + it("accepts the renamed trusted workflow while selecting branch reuse", () => { const selection = selectPublicationRun( runsPayload([workflowRun({ name: "Images / Base Images" })]), @@ -833,6 +860,37 @@ describe("base-image publication evidence", () => { ).resolves.toEqual(selectedRun()); }); + it("uses a successful manual main publication for branch reuse", async () => { + const manualRun = workflowRun({ event: "workflow_dispatch" }); + const responses = [ + workflowMetadata(), + runsPayload([manualRun]), + { total_count: 3, jobs: successfulJobs() }, + manualRun, + ]; + const requests: string[] = []; + + await expect( + waitForBaseImagePublication({ + history: history(), + request: async (requestPath) => { + requests.push(requestPath); + return responses.shift(); + }, + requireWorkflowSuccess: true, + selectNearestSuccessfulRun: true, + waitMs: 100, + pollMs: 10, + }), + ).resolves.toEqual(selectedRun({ event: "workflow_dispatch" })); + expect(requests).toEqual([ + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}`, + ]); + }); + it("rejects failed managed-image publication before E2E consumers start", async () => { const failedRun = workflowRun({ conclusion: "failure" }); const responses = [ diff --git a/tools/e2e/base-image-publication.mts b/tools/e2e/base-image-publication.mts index d010fd6a718..bb57ba10e2b 100644 --- a/tools/e2e/base-image-publication.mts +++ b/tools/e2e/base-image-publication.mts @@ -108,6 +108,7 @@ export interface FirstParentHistory { export interface PublicationRun { id: number; attempt: number; + event: "push" | "workflow_dispatch"; workflowId: number; headSha: string; status: string; @@ -429,7 +430,12 @@ export function validateWorkflow(payload: unknown): number { return workflowId; } -function validateRun(value: unknown, index: number, expectedWorkflowId: number): PublicationRun { +function validateRun( + value: unknown, + index: number, + expectedWorkflowId: number, + allowWorkflowDispatch = false, +): PublicationRun { const run = asRecord(value); const id = positiveSafeInteger(run.id, `workflow run ${index} id`); const attempt = positiveSafeInteger(run.run_attempt, `workflow run ${index} attempt`); @@ -439,7 +445,12 @@ function validateRun(value: unknown, index: number, expectedWorkflowId: number): throw new Error(`workflow run ${index} workflow id does not match the base-image workflow`); } const headSha = sha(run.head_sha, `workflow run ${index} head SHA`); - exactString(run.event, "push", `workflow run ${index} event`); + const event = run.event; + if (event !== "push" && !(allowWorkflowDispatch && event === "workflow_dispatch")) { + throw new Error( + `workflow run ${index} event must be push${allowWorkflowDispatch ? " or workflow_dispatch" : ""}`, + ); + } exactString(run.head_branch, MAIN_BRANCH, `workflow run ${index} branch`); exactString(run.path, WORKFLOW_PATH, `workflow run ${index} path`); trustedWorkflowName(run.name, `workflow run ${index} name`); @@ -468,6 +479,7 @@ function validateRun(value: unknown, index: number, expectedWorkflowId: number): return { id, attempt, + event, workflowId: expectedWorkflowId, headSha, status, @@ -480,7 +492,10 @@ export function selectPublicationRun( payload: unknown, history: FirstParentHistory, workflowId: number, - options: { readonly completedSuccessOnly?: boolean } = {}, + options: { + readonly allowWorkflowDispatch?: boolean; + readonly completedSuccessOnly?: boolean; + } = {}, ): PublicationSelection { positiveSafeInteger(workflowId, "base-image workflow id"); const response = asRecord(payload); @@ -495,7 +510,7 @@ export function selectPublicationRun( const runs = response.workflow_runs.flatMap((value, index) => { const run = asRecord(value); return typeof run.head_sha === "string" && history.distanceBySha.has(run.head_sha) - ? [validateRun(run, index, workflowId)] + ? [validateRun(run, index, workflowId, options.allowWorkflowDispatch === true)] : []; }); if (new Set(runs.map((run) => run.id)).size !== runs.length) { @@ -596,10 +611,16 @@ export function validatePublisherJobs(payload: unknown, run: PublicationRun): "p } export function validateBoundRun(payload: unknown, expected: PublicationRun): PublicationRun { - const actual = validateRun(payload, 0, expected.workflowId); + const actual = validateRun( + payload, + 0, + expected.workflowId, + expected.event === "workflow_dispatch", + ); if ( actual.id !== expected.id || actual.attempt !== expected.attempt || + actual.event !== expected.event || actual.headSha !== expected.headSha ) { throw new Error( @@ -753,10 +774,13 @@ export async function waitForBaseImagePublication( const workflowId = validateWorkflow( await request(`/repos/${REPOSITORY}/actions/workflows/${WORKFLOW_FILE}`), ); - const runsPath = `/repos/${REPOSITORY}/actions/workflows/${WORKFLOW_FILE}/runs?branch=${MAIN_BRANCH}&event=push&per_page=100`; + const allowWorkflowDispatch = options.selectNearestSuccessfulRun === true; + const eventFilter = allowWorkflowDispatch ? "" : "&event=push"; + const runsPath = `/repos/${REPOSITORY}/actions/workflows/${WORKFLOW_FILE}/runs?branch=${MAIN_BRANCH}${eventFilter}&per_page=100`; while (true) { const runs = await collectPaginated(request, runsPath, "workflow_runs"); const selection = selectPublicationRun(runs, options.history, workflowId, { + allowWorkflowDispatch, completedSuccessOnly: options.selectNearestSuccessfulRun === true, }); if (selection.state === "selected") { From 8d5ac7c61aefa94f17d7a2f41ee67b9fdd0df157 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 21:54:49 -0700 Subject: [PATCH 11/23] fix(e2e): select real CLI after fallback Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 22 ++++--- test/e2e/live/hermes-gpu-startup.test.ts | 2 +- .../hermes-gpu-startup-fallback.test.ts | 60 +++++-------------- 3 files changed, 25 insertions(+), 59 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 4580b63fb4d..5dd04180665 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -81,14 +81,13 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native * `--gpu` create before build or sandbox progress. The compatibility create - * runs the real CLI with the wrapper path as argv[0], while the rejecting - * wrapper stays installed. After that create succeeds, the wrapper atomically - * replaces itself with a link to the real CLI so later ForwardTcp ownership - * checks resolve the configured path to the executable that owns each - * listener. A failed or interrupted invocation never changes the wrapper path; - * an overlapping successful invocation may independently commit the terminal - * link and remains authoritative. Every other invocation transparently - * delegates its original argv. This + * runs the real CLI while the rejecting wrapper stays installed. After that + * create succeeds, the wrapper removes itself so normal OpenShell resolution + * selects the real CLI path used by surviving ForwardTcp listeners. A failed + * or interrupted invocation never changes the wrapper path; an overlapping + * successful invocation may independently commit the removal and remains + * authoritative. Every other invocation transparently delegates its original + * argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -158,7 +157,7 @@ export function createHermesGpuFallbackWrapper( " trap 'forward_compatibility_signal HUP 129' HUP", " trap 'forward_compatibility_signal INT 130' INT", " trap 'forward_compatibility_signal TERM 143' TERM", - ' (exec -a "$0" "$REAL_OPENSHELL" "$@") &', + ' (exec "$REAL_OPENSHELL" "$@") &', ' COMPATIBILITY_PID="$!"', ' wait "$COMPATIBILITY_PID" || {', ' compatibility_status="$?"', @@ -166,9 +165,7 @@ export function createHermesGpuFallbackWrapper( ' exit "$compatibility_status"', " }", " trap - HUP INT TERM", - ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', - ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', - ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + ' rm -f "$0"', " exit 0", " fi", "fi", @@ -184,6 +181,7 @@ export function createHermesGpuFallbackWrapper( NEMOCLAW_OPENSHELL_BIN: wrapperPath, NEMOCLAW_OPENSHELL_GATEWAY_BIN: gatewayPath, NEMOCLAW_OPENSHELL_SANDBOX_BIN: sandboxPath, + PATH: `${componentDir}:${process.env.PATH ?? ""}`, }, eventsPath, rootDir, diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index ff5c7841c54..f813c857650 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, keep the rejecting wrapper installed while the real OpenShell CLI runs with the wrapper argv[0], replace the wrapper with a real-CLI link only after success, and let failed or interrupted invocations leave the path unchanged while an overlapping success remains authoritative", + "reject the exact native --gpu create before progress, keep the rejecting wrapper installed during compatibility create, remove it only after success so OpenShell resolves to the real ForwardTcp owner path, and let failed or interrupted invocations leave the path unchanged while an overlapping success remains authoritative", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 5b179155942..d54ef62a0fe 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -9,6 +9,7 @@ import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import { buildDirectSandboxGpuProofCommands } from "../../../src/lib/onboard/initial-policy"; +import { resolveOpenshell } from "../../../src/lib/adapters/openshell/resolve"; import { hasRequiredOpenshellMessagingFeatures, REQUIRED_OPENSHELL_SANDBOX_MCP_FEATURE, @@ -127,7 +128,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("keeps the real OpenShell CLI at the wrapper path after compatibility create succeeds (#11239)", () => { + it("selects the real OpenShell CLI after compatibility create succeeds (#11239)", () => { const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ "#!/usr/bin/env bash", @@ -188,24 +189,25 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { env, ); expect(compatibility.status, compatibility.stderr).toBe(0); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); + expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); + const selectedOpenshell = resolveOpenshell({ env }) ?? "missing-openshell"; + expect(selectedOpenshell).toBe(realOpenshell); const repeatedCompatibility = runWrapper( - wrapper.wrapperPath, + selectedOpenshell, ["sandbox", "create", "--from", "image", "--gpu-device", "all"], env, ); expect(repeatedCompatibility.status, repeatedCompatibility.stderr).toBe(0); const compatibilityProof = runWrapper( - wrapper.wrapperPath, + selectedOpenshell, ["sandbox", "exec", "-n", "alpha", "--", "sh", "-lc", HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF], env, ); expect(compatibilityProof.status, compatibilityProof.stderr).toBe(0); - const version = runWrapper(wrapper.wrapperPath, ["--version"], env); + const version = runWrapper(selectedOpenshell, ["--version"], env); expect(version.status, version.stderr).toBe(0); expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, @@ -233,46 +235,12 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(fs.readFileSync(delegateExecutableLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ realOpenshell, realOpenshell, - wrapper.wrapperPath, - wrapper.wrapperPath, - wrapper.wrapperPath, + realOpenshell, + realOpenshell, + realOpenshell, ]); }); - it("passes the configured wrapper path as native executable argv[0] before committing the link (#11239)", () => { - const root = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-gpu-fallback-argv0-test-")); - roots.push(root); - const realDir = path.join(root, "real"); - fs.mkdirSync(realDir); - const realOpenshell = path.join(realDir, "openshell"); - fs.symlinkSync(process.execPath, realOpenshell); - writeExecutable(path.join(realDir, "openshell-gateway"), "#!/usr/bin/env bash\nexit 0\n"); - writeExecutable(path.join(realDir, "openshell-sandbox"), "#!/usr/bin/env bash\nexit 0\n"); - const wrapper = createHermesGpuFallbackWrapper(realOpenshell, { - rootDir: path.join(root, "wrapper"), - }); - const argvZeroLog = path.join(root, "argv-zero.log"); - fs.writeFileSync( - path.join(root, "sandbox"), - 'require("node:fs").writeFileSync(process.env.E2E_ARGV_ZERO_LOG, process.argv0);\n', - ); - - const compatibility = spawnSync( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], - { - cwd: root, - encoding: "utf8", - env: { ...process.env, ...wrapper.componentEnv, E2E_ARGV_ZERO_LOG: argvZeroLog }, - }, - ); - - expect(compatibility.status, compatibility.stderr).toBe(0); - expect(fs.readFileSync(argvZeroLog, "utf8")).toBe(wrapper.wrapperPath); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); - }); - it("keeps native fault injection when the exact proof precedes compatibility create (#11239)", () => { const { wrapper } = createWrapperFixture("hermes-gpu-fallback-order-test-"); const env = { ...process.env, ...wrapper.componentEnv }; @@ -376,7 +344,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { fs.writeFileSync(release, ""); expect(await compatibilityStatus).toBe(0); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); }); it("retains the successful handoff when an overlapping compatibility create fails (#11239)", async () => { @@ -427,10 +395,10 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { fs.writeFileSync(successRelease, ""); expect(await successfulStatus).toBe(0); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); fs.writeFileSync(failureRelease, ""); expect(await failingStatus).toBe(23); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); }); it("leaves native fault injection installed when compatibility create is interrupted (#11239)", async () => { From b5928ba3b127df9f9dfbec12c6364fb6ce8a77e6 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 22:24:10 -0700 Subject: [PATCH 12/23] fix(e2e): commit fallback handoff on ready Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 31 +++++++--- test/e2e/live/hermes-gpu-startup.test.ts | 2 +- .../hermes-gpu-startup-fallback.test.ts | 60 ++++++++++++++----- 3 files changed, 69 insertions(+), 24 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 5dd04180665..7e7db5efec6 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -81,13 +81,13 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native * `--gpu` create before build or sandbox progress. The compatibility create - * runs the real CLI while the rejecting wrapper stays installed. After that - * create succeeds, the wrapper removes itself so normal OpenShell resolution - * selects the real CLI path used by surviving ForwardTcp listeners. A failed - * or interrupted invocation never changes the wrapper path; an overlapping - * successful invocation may independently commit the removal and remains - * authoritative. Every other invocation transparently delegates its original - * argv. This + * runs the real CLI while the rejecting wrapper stays installed. A normal + * success, or NemoClaw's expected termination after the sandbox is independently + * proven Ready, atomically replaces the wrapper with a real-CLI link before + * host forwarding starts. A failed or pre-Ready interrupted invocation never + * changes the wrapper path; an overlapping successful invocation may + * independently commit the link and remains authoritative. Every other + * invocation transparently delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -121,6 +121,19 @@ export function createHermesGpuFallbackWrapper( `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', + 'SANDBOX_NAME="$(printf \'%s\\n\' "$@" | awk \'previous == "--name" { print; exit } { previous = $0 }\')"', + "", + "commit_compatibility_handoff() {", + ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', + ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', + ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + "}", + "", + "sandbox_is_ready() {", + ' test -n "$SANDBOX_NAME" &&', + ' "$REAL_OPENSHELL" sandbox get "$SANDBOX_NAME" 2>/dev/null |', + " grep -Eq '(^|[[:space:]])Ready([[:space:]]|$)'", + "}", "", "is_sandbox_create=0", "has_gpu_flag=0", @@ -152,6 +165,7 @@ export function createHermesGpuFallbackWrapper( ' kill "-$signal" "$COMPATIBILITY_PID" 2>/dev/null || true', " fi", ' wait "$COMPATIBILITY_PID" 2>/dev/null || true', + " sandbox_is_ready && commit_compatibility_handoff || true", ' exit "$status"', " }", " trap 'forward_compatibility_signal HUP 129' HUP", @@ -165,7 +179,7 @@ export function createHermesGpuFallbackWrapper( ' exit "$compatibility_status"', " }", " trap - HUP INT TERM", - ' rm -f "$0"', + " commit_compatibility_handoff", " exit 0", " fi", "fi", @@ -181,7 +195,6 @@ export function createHermesGpuFallbackWrapper( NEMOCLAW_OPENSHELL_BIN: wrapperPath, NEMOCLAW_OPENSHELL_GATEWAY_BIN: gatewayPath, NEMOCLAW_OPENSHELL_SANDBOX_BIN: sandboxPath, - PATH: `${componentDir}:${process.env.PATH ?? ""}`, }, eventsPath, rootDir, diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index f813c857650..a6c34372c8e 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -444,7 +444,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, keep the rejecting wrapper installed during compatibility create, remove it only after success so OpenShell resolves to the real ForwardTcp owner path, and let failed or interrupted invocations leave the path unchanged while an overlapping success remains authoritative", + "reject the exact native --gpu create before progress, keep the rejecting wrapper installed during compatibility create, commit the real-CLI link after normal success or an independently verified Ready termination, and retain the wrapper after failure or pre-Ready interruption unless an overlapping success already committed", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index d54ef62a0fe..47d74c3b096 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -9,7 +9,6 @@ import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import { buildDirectSandboxGpuProofCommands } from "../../../src/lib/onboard/initial-policy"; -import { resolveOpenshell } from "../../../src/lib/adapters/openshell/resolve"; import { hasRequiredOpenshellMessagingFeatures, REQUIRED_OPENSHELL_SANDBOX_MCP_FEATURE, @@ -128,7 +127,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("selects the real OpenShell CLI after compatibility create succeeds (#11239)", () => { + it("keeps the real OpenShell CLI at the wrapper path after compatibility create succeeds (#11239)", () => { const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ "#!/usr/bin/env bash", @@ -189,25 +188,24 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { env, ); expect(compatibility.status, compatibility.stderr).toBe(0); - expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); - const selectedOpenshell = resolveOpenshell({ env }) ?? "missing-openshell"; - expect(selectedOpenshell).toBe(realOpenshell); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); const repeatedCompatibility = runWrapper( - selectedOpenshell, + wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu-device", "all"], env, ); expect(repeatedCompatibility.status, repeatedCompatibility.stderr).toBe(0); const compatibilityProof = runWrapper( - selectedOpenshell, + wrapper.wrapperPath, ["sandbox", "exec", "-n", "alpha", "--", "sh", "-lc", HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF], env, ); expect(compatibilityProof.status, compatibilityProof.stderr).toBe(0); - const version = runWrapper(selectedOpenshell, ["--version"], env); + const version = runWrapper(wrapper.wrapperPath, ["--version"], env); expect(version.status, version.stderr).toBe(0); expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, @@ -235,9 +233,9 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(fs.readFileSync(delegateExecutableLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ realOpenshell, realOpenshell, - realOpenshell, - realOpenshell, - realOpenshell, + wrapper.wrapperPath, + wrapper.wrapperPath, + wrapper.wrapperPath, ]); }); @@ -344,7 +342,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { fs.writeFileSync(release, ""); expect(await compatibilityStatus).toBe(0); - expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); }); it("retains the successful handoff when an overlapping compatibility create fails (#11239)", async () => { @@ -395,16 +393,17 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { fs.writeFileSync(successRelease, ""); expect(await successfulStatus).toBe(0); - expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); fs.writeFileSync(failureRelease, ""); expect(await failingStatus).toBe(23); - expect(fs.existsSync(wrapper.wrapperPath)).toBe(false); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); }); it("leaves native fault injection installed when compatibility create is interrupted (#11239)", async () => { const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-interrupt-test-", { openshell: [ "#!/usr/bin/env bash", + 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then exit 1; fi', "trap 'exit 143' HUP INT TERM", ': >"$E2E_FAKE_READY"', "while :; do sleep 1; done", @@ -430,6 +429,39 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ).toBe(2); }); + it("commits the handoff when the create client is terminated after Ready (#11239)", async () => { + const { realOpenshell, root, wrapper } = createWrapperFixture( + "hermes-gpu-fallback-ready-termination-test-", + { + openshell: [ + "#!/usr/bin/env bash", + 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then', + " printf '%s\\n' 'Phase: Ready'", + " exit 0", + "fi", + "trap 'exit 143' HUP INT TERM", + ': >"$E2E_FAKE_READY"', + "while :; do sleep 1; done", + "", + ].join("\n"), + }, + ); + const ready = path.join(root, "compatibility-ready"); + const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready }; + const compatibility = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--name", "alpha", "--gpu-device", "all"], + env, + ); + const compatibilityStatus = waitForChild(compatibility); + await waitForFile(ready); + + expect(compatibility.kill("SIGTERM")).toBe(true); + expect(await compatibilityStatus).toBe(143); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); + expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); + }); + it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", From 934b0ef16c7861f3e4d892f48602a67dd18b6fbe Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 22:46:11 -0700 Subject: [PATCH 13/23] fix(e2e): bind handoff to sandbox identity Signed-off-by: Aaron Erickson --- ci/e2e-assertion-budget.json | 10 +++++----- test/e2e/live/hermes-gpu-startup-fallback.ts | 4 +++- test/e2e/live/hermes-gpu-startup.test.ts | 20 +++++++++++-------- .../hermes-gpu-startup-fallback.test.ts | 20 +++++++++++++++++-- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index f9f474bea50..0c1c5054de8 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -21,8 +21,8 @@ "namedAssertionHelpers": 601, "failCalls": 8, "throwGuards": 87, - "objectFieldAssertions": 244, - "assertionPoints": 2819, + "objectFieldAssertions": 243, + "assertionPoints": 2818, "generatedProbeBlocks": 124, "generatedProbeConditions": 332 }, @@ -33,8 +33,8 @@ "namedAssertionHelpers": 905, "failCalls": 38, "throwGuards": 633, - "objectFieldAssertions": 343, - "assertionPoints": 4304, + "objectFieldAssertions": 342, + "assertionPoints": 4303, "generatedProbeBlocks": 278, "generatedProbeConditions": 953 }, @@ -68,7 +68,7 @@ "test/e2e/live/gpu-e2e.test.ts": [40,45,73,91,3], "test/e2e/live/hermes-discord.test.ts": [10,25,17,64,14], "test/e2e/live/hermes-e2e.test.ts": [82,93,112,127,3], - "test/e2e/live/hermes-gpu-startup.test.ts": [19,28,63,107,12], + "test/e2e/live/hermes-gpu-startup.test.ts": [19,27,63,106,12], "test/e2e/live/hermes-inference-switch.test.ts": [61,67,72,92,2], "test/e2e/live/hermes-root-entrypoint-smoke.test.ts": [4,27,4,27,4], "test/e2e/live/hermes-sandbox-secret-boundary.test.ts": [20,27,20,27,4], diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 7e7db5efec6..94669c5ede4 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -11,6 +11,7 @@ export const HERMES_GPU_FALLBACK_EVENTS = { rejectNativeCreateBeforeProgress: "reject-native-create-before-progress", delegateCompatibilityCreate: "delegate-compatibility-create", } as const; +export const HERMES_GPU_FALLBACK_COMMIT_EVENT = "commit-compatibility-handoff"; export const HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF = [ "set -eu;", @@ -121,12 +122,13 @@ export function createHermesGpuFallbackWrapper( `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', - 'SANDBOX_NAME="$(printf \'%s\\n\' "$@" | awk \'previous == "--name" { print; exit } { previous = $0 }\')"', + 'SANDBOX_NAME="${NEMOCLAW_SANDBOX_NAME:-}"', "", "commit_compatibility_handoff() {", ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', ' mv -f "$REAL_OPENSHELL_LINK" "$0"', + ` printf '%s\\n' '${HERMES_GPU_FALLBACK_COMMIT_EVENT}' >>"$FALLBACK_STATE_DIR/events.log"`, "}", "", "sandbox_is_ready() {", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index a6c34372c8e..2d489602cf1 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -23,6 +23,7 @@ import type { RuntimeProviderPrerequisite } from "../fixtures/runtime-provider.t import { createHermesGpuFallbackWrapper, extractHermesGpuDiagnosticsDirectory, + HERMES_GPU_FALLBACK_COMMIT_EVENT, HERMES_GPU_FALLBACK_EVENTS, readHermesGpuFallbackEvents, resolveHermesGpuStartupScenario, @@ -474,6 +475,12 @@ test( await (install.exitCode !== 0 ? captureFailedGpuContainer(host, runtimeProvider, gpuDiagnosticsDir) : Promise.resolve()); + const fallbackEvents = fallbackWrapper + ? readHermesGpuFallbackEvents(fallbackWrapper.eventsPath) + : []; + await (fallbackWrapper + ? artifacts.writeJson("gpu-fallback-events.json", fallbackEvents) + : Promise.resolve()); expect(install.exitCode, resultText(install)).toBe(0); assertStockManagedImageReceipt({ environment: env, @@ -481,13 +488,10 @@ test( sandboxName: SANDBOX_NAME, }); - const verifyFallback = async (wrapper: ReturnType) => { - const fallbackEvents = readHermesGpuFallbackEvents(wrapper.eventsPath); - await artifacts.writeJson("gpu-fallback-events.json", fallbackEvents); - expect(fallbackEvents).toEqual([ - HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, - HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, - ]); + const verifyFallback = () => { + expect(fallbackEvents.join("\n")).toBe( + `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_COMMIT_EVENT}`, + ); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( HERMES_GPU_FALLBACK_DISCLOSURE_FRAGMENTS.every((fragment) => @@ -495,7 +499,7 @@ test( ), ).toBe(true); }; - await (fallbackWrapper ? verifyFallback(fallbackWrapper) : Promise.resolve()); + await (fallbackWrapper ? Promise.resolve(verifyFallback()) : Promise.resolve()); progress.phase("validate GPU startup and supervisor proof"); const status = await host.command("nemoclaw", [SANDBOX_NAME, "status"], { diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 47d74c3b096..15551296607 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -16,6 +16,7 @@ import { import { createHermesGpuFallbackWrapper, extractHermesGpuDiagnosticsDirectory, + HERMES_GPU_FALLBACK_COMMIT_EVENT, HERMES_GPU_FALLBACK_EVENTS, HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF, readHermesGpuFallbackEvents, @@ -210,6 +211,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, + HERMES_GPU_FALLBACK_COMMIT_EVENT, ]); const wrapperArtifacts = fs .readdirSync(path.dirname(wrapper.eventsPath), { withFileTypes: true }) @@ -411,7 +413,12 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ].join("\n"), }); const ready = path.join(root, "compatibility-ready"); - const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready }; + const env = { + ...process.env, + ...wrapper.componentEnv, + E2E_FAKE_READY: ready, + NEMOCLAW_SANDBOX_NAME: "alpha", + }; const compatibility = spawnWrapper( wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu-device", "all"], @@ -447,7 +454,12 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { }, ); const ready = path.join(root, "compatibility-ready"); - const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready }; + const env = { + ...process.env, + ...wrapper.componentEnv, + E2E_FAKE_READY: ready, + NEMOCLAW_SANDBOX_NAME: "alpha", + }; const compatibility = spawnWrapper( wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--name", "alpha", "--gpu-device", "all"], @@ -460,6 +472,10 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(await compatibilityStatus).toBe(143); expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); + expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ + HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, + HERMES_GPU_FALLBACK_COMMIT_EVENT, + ]); }); it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { From e30f9fdc1d201f1212b9425edd8ed3ac32276a3f Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 23:09:50 -0700 Subject: [PATCH 14/23] fix(e2e): read fallback sandbox from create args Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 2 +- .../e2e/support/hermes-gpu-startup-fallback.test.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 94669c5ede4..065e3a0f844 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -122,7 +122,7 @@ export function createHermesGpuFallbackWrapper( `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', - 'SANDBOX_NAME="${NEMOCLAW_SANDBOX_NAME:-}"', + `SANDBOX_NAME="$(printf '%s\\n' "$@" | awk 'previous == "--name" { print; exit } /^--name=/ { sub(/^--name=/, ""); print; exit } /^NEMOCLAW_SANDBOX_NAME=/ { sub(/^NEMOCLAW_SANDBOX_NAME=/, ""); print; exit } { previous = $0 }')"`, "", "commit_compatibility_handoff() {", ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 15551296607..62fe98ddcc3 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -417,7 +417,6 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready, - NEMOCLAW_SANDBOX_NAME: "alpha", }; const compatibility = spawnWrapper( wrapper.wrapperPath, @@ -458,11 +457,19 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready, - NEMOCLAW_SANDBOX_NAME: "alpha", }; const compatibility = spawnWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--name", "alpha", "--gpu-device", "all"], + [ + "sandbox", + "create", + "--from", + "image", + "--gpu-device", + "all", + "--", + "NEMOCLAW_SANDBOX_NAME=alpha", + ], env, ); const compatibilityStatus = waitForChild(compatibility); From a919adadb7458bb8b32c0ae38f1c80256345eee3 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Tue, 8 Sep 2026 23:45:12 -0700 Subject: [PATCH 15/23] fix(e2e): harden fallback evidence reuse Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 27 ++++++++-- test/e2e/live/hermes-gpu-startup.test.ts | 3 +- .../support/base-image-publication.test.ts | 50 ++++++++++++++++++- .../hermes-gpu-startup-fallback.test.ts | 33 ++++++++++-- tools/e2e/base-image-publication.mts | 24 +++++++-- 5 files changed, 121 insertions(+), 16 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 065e3a0f844..2cdf64342dd 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -10,8 +10,8 @@ import { REQUIRED_OPENSHELL_MCP_FEATURES } from "../../../src/lib/onboard/opensh export const HERMES_GPU_FALLBACK_EVENTS = { rejectNativeCreateBeforeProgress: "reject-native-create-before-progress", delegateCompatibilityCreate: "delegate-compatibility-create", + commitCompatibilityHandoff: "commit-compatibility-handoff", } as const; -export const HERMES_GPU_FALLBACK_COMMIT_EVENT = "commit-compatibility-handoff"; export const HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF = [ "set -eu;", @@ -121,6 +121,7 @@ export function createHermesGpuFallbackWrapper( ...REQUIRED_OPENSHELL_MCP_FEATURES.map((marker) => `# capability: ${marker}`), `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, + "READY_QUERY_TIMEOUT_SECONDS=2", 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', `SANDBOX_NAME="$(printf '%s\\n' "$@" | awk 'previous == "--name" { print; exit } /^--name=/ { sub(/^--name=/, ""); print; exit } /^NEMOCLAW_SANDBOX_NAME=/ { sub(/^NEMOCLAW_SANDBOX_NAME=/, ""); print; exit } { previous = $0 }')"`, "", @@ -128,13 +129,29 @@ export function createHermesGpuFallbackWrapper( ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', ' ln -s "$REAL_OPENSHELL" "$REAL_OPENSHELL_LINK"', ' mv -f "$REAL_OPENSHELL_LINK" "$0"', - ` printf '%s\\n' '${HERMES_GPU_FALLBACK_COMMIT_EVENT}' >>"$FALLBACK_STATE_DIR/events.log"`, + ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff}' >>"$FALLBACK_STATE_DIR/events.log"`, "}", "", "sandbox_is_ready() {", - ' test -n "$SANDBOX_NAME" &&', - ' "$REAL_OPENSHELL" sandbox get "$SANDBOX_NAME" 2>/dev/null |', - " grep -Eq '(^|[[:space:]])Ready([[:space:]]|$)'", + ' READY_QUERY_OUTPUT="$FALLBACK_STATE_DIR/sandbox-ready.$$"', + ' (exec "$REAL_OPENSHELL" sandbox get "$SANDBOX_NAME") >"$READY_QUERY_OUTPUT" 2>/dev/null &', + ' ready_query_pid="$!"', + " (", + ' sleep "$READY_QUERY_TIMEOUT_SECONDS"', + ' kill -TERM "$ready_query_pid" 2>/dev/null || true', + " sleep 0.2", + ' kill -KILL "$ready_query_pid" 2>/dev/null || true', + " ) &", + ' ready_watchdog_pid="$!"', + " ready_query_status=0", + ' wait "$ready_query_pid" || ready_query_status="$?"', + ' kill "$ready_watchdog_pid" 2>/dev/null || true', + ' wait "$ready_watchdog_pid" 2>/dev/null || true', + ' test "$ready_query_status" -eq 0 &&', + " grep -Eq '(^|[[:space:]])Ready([[:space:]]|$)' \"$READY_QUERY_OUTPUT\"", + ' ready_query_status="$?"', + ' rm -f "$READY_QUERY_OUTPUT"', + ' return "$ready_query_status"', "}", "", "is_sandbox_create=0", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 2d489602cf1..728c0f9e5ff 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -23,7 +23,6 @@ import type { RuntimeProviderPrerequisite } from "../fixtures/runtime-provider.t import { createHermesGpuFallbackWrapper, extractHermesGpuDiagnosticsDirectory, - HERMES_GPU_FALLBACK_COMMIT_EVENT, HERMES_GPU_FALLBACK_EVENTS, readHermesGpuFallbackEvents, resolveHermesGpuStartupScenario, @@ -490,7 +489,7 @@ test( const verifyFallback = () => { expect(fallbackEvents.join("\n")).toBe( - `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_COMMIT_EVENT}`, + `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff}`, ); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( diff --git a/test/e2e/support/base-image-publication.test.ts b/test/e2e/support/base-image-publication.test.ts index 0854755db8f..6de5dd41796 100644 --- a/test/e2e/support/base-image-publication.test.ts +++ b/test/e2e/support/base-image-publication.test.ts @@ -163,6 +163,16 @@ function successfulJobs(overrides: { runAttempt?: number } = {}): Record[] { + return [ + ...successfulJobs(), + publisherJob( + "Publish complete managed images / Promote complete multi-platform managed image cohort", + { id: 4 }, + ), + ]; +} + describe("base-image publication evidence", () => { it.each(["push", "workflow_dispatch"])("accepts %s publication preflight events", (eventName) => { expect(isBaseImagePublicationEvent(eventName)).toBe(true); @@ -504,6 +514,27 @@ describe("base-image publication evidence", () => { ).toThrow(/event must be push/u); }); + it("prefers a successful push over a successful manual publication at the same commit", () => { + const pushRunId = RUN_ID + 1; + const selection = selectPublicationRun( + runsPayload([ + workflowRun({ event: "workflow_dispatch" }), + workflowRun({ + id: pushRunId, + html_url: `${RUN_URL_ROOT}/${pushRunId}`, + }), + ]), + history(), + WORKFLOW_ID, + { allowWorkflowDispatch: true, completedSuccessOnly: true }, + ); + + expect(selection).toMatchObject({ + state: "selected", + run: { id: pushRunId, event: "push", headSha: RELEVANT_SHA }, + }); + }); + it("accepts the renamed trusted workflow while selecting branch reuse", () => { const selection = selectPublicationRun( runsPayload([workflowRun({ name: "Images / Base Images" })]), @@ -635,6 +666,23 @@ describe("base-image publication evidence", () => { ).toThrow(/provenance does not match/u); }); + it("requires exact managed-image promotion from a manual publication", () => { + const manualRun = selectedRun({ event: "workflow_dispatch" }); + + expect(() => + validatePublisherJobs( + { total_count: successfulJobs().length, jobs: successfulJobs() }, + manualRun, + ), + ).toThrow(/missing required Publish complete managed images/u); + expect( + validatePublisherJobs( + { total_count: successfulManualJobs().length, jobs: successfulManualJobs() }, + manualRun, + ), + ).toBe("ready"); + }); + it("accepts the renamed trusted publisher jobs", () => { const jobs = [ publisherJob("Manifests / OpenClaw", { id: 1 }), @@ -865,7 +913,7 @@ describe("base-image publication evidence", () => { const responses = [ workflowMetadata(), runsPayload([manualRun]), - { total_count: 3, jobs: successfulJobs() }, + { total_count: 4, jobs: successfulManualJobs() }, manualRun, ]; const requests: string[] = []; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 62fe98ddcc3..48c5f19180a 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -16,7 +16,6 @@ import { import { createHermesGpuFallbackWrapper, extractHermesGpuDiagnosticsDirectory, - HERMES_GPU_FALLBACK_COMMIT_EVENT, HERMES_GPU_FALLBACK_EVENTS, HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF, readHermesGpuFallbackEvents, @@ -211,7 +210,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, - HERMES_GPU_FALLBACK_COMMIT_EVENT, + HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff, ]); const wrapperArtifacts = fs .readdirSync(path.dirname(wrapper.eventsPath), { withFileTypes: true }) @@ -481,10 +480,38 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, - HERMES_GPU_FALLBACK_COMMIT_EVENT, + HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff, ]); }); + it("bounds a stuck Ready query and retains native fault injection (#11239)", async () => { + const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-ready-timeout-test-", { + openshell: [ + "#!/usr/bin/env bash", + 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then exec sleep 30; fi', + "trap 'exit 143' HUP INT TERM", + ': >"$E2E_FAKE_READY"', + "while :; do sleep 1; done", + "", + ].join("\n"), + }); + const ready = path.join(root, "compatibility-ready"); + const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready }; + const compatibility = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], + env, + ); + const compatibilityStatus = waitForChild(compatibility); + await waitForFile(ready); + const terminatedAt = Date.now(); + + expect(compatibility.kill("SIGTERM")).toBe(true); + expect(await compatibilityStatus).toBe(143); + expect(Date.now() - terminatedAt).toBeLessThan(4_000); + expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); + }); + it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", diff --git a/tools/e2e/base-image-publication.mts b/tools/e2e/base-image-publication.mts index bb57ba10e2b..4c90004b8ff 100644 --- a/tools/e2e/base-image-publication.mts +++ b/tools/e2e/base-image-publication.mts @@ -87,13 +87,19 @@ export const REQUIRED_PUBLISHER_JOBS = [ "Build and push Hermes base image", "Build and push Deep Agents Code base image", ] as const; -const PUBLISHER_JOB_ALIASES = new Map([ +const REQUIRED_MANUAL_MANAGED_IMAGE_JOB = + "Publish complete managed images / Promote complete multi-platform managed image cohort"; +type RequiredPublisherJob = + | (typeof REQUIRED_PUBLISHER_JOBS)[number] + | typeof REQUIRED_MANUAL_MANAGED_IMAGE_JOB; +const PUBLISHER_JOB_ALIASES = new Map([ ["Build and push OpenClaw base image", "Build and push OpenClaw base image"], ["Manifests / OpenClaw", "Build and push OpenClaw base image"], ["Build and push Hermes base image", "Build and push Hermes base image"], ["Manifests / Hermes", "Build and push Hermes base image"], ["Build and push Deep Agents Code base image", "Build and push Deep Agents Code base image"], ["Manifests / Deep Agents Code", "Build and push Deep Agents Code base image"], + [REQUIRED_MANUAL_MANAGED_IMAGE_JOB, REQUIRED_MANUAL_MANAGED_IMAGE_JOB], ]); type JsonRecord = Record; @@ -527,12 +533,16 @@ export function selectPublicationRun( const nearestDistance = Math.min(...selectable.map(({ distance }) => distance)); const nearest = selectable.filter(({ distance }) => distance === nearestDistance); - if (nearest.length !== 1) { + const preferredEvent = nearest.some(({ run }) => run.event === "push") + ? "push" + : "workflow_dispatch"; + const preferred = nearest.filter(({ run }) => run.event === preferredEvent); + if (preferred.length !== 1) { throw new Error( - `multiple trusted base-image workflow runs match ${nearest[0]?.run.headSha ?? history.relevantSha}`, + `multiple trusted ${preferredEvent} base-image workflow runs match ${preferred[0]?.run.headSha ?? history.relevantSha}: ${preferred.map(({ run }) => run.url).join(", ")}`, ); } - const run = nearest[0].run; + const run = preferred[0].run; return { state: "selected", run }; } @@ -581,7 +591,11 @@ export function validatePublisherJobs(payload: unknown, run: PublicationRun): "p } let pending = false; - for (const requiredName of REQUIRED_PUBLISHER_JOBS) { + const requiredJobs: readonly RequiredPublisherJob[] = + run.event === "workflow_dispatch" + ? [...REQUIRED_PUBLISHER_JOBS, REQUIRED_MANUAL_MANAGED_IMAGE_JOB] + : REQUIRED_PUBLISHER_JOBS; + for (const requiredName of requiredJobs) { const current = jobsByName.get(requiredName); if (!current) { if (run.status === "completed") { From b5eaa062ce2727ec6d3f6c1fa269726aa6669a11 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 00:14:19 -0700 Subject: [PATCH 16/23] docs(e2e): avoid unsupported forward ordering Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup-fallback.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 2cdf64342dd..209f685dfc8 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -84,11 +84,11 @@ function quoteShellLiteral(value: string): string { * `--gpu` create before build or sandbox progress. The compatibility create * runs the real CLI while the rejecting wrapper stays installed. A normal * success, or NemoClaw's expected termination after the sandbox is independently - * proven Ready, atomically replaces the wrapper with a real-CLI link before - * host forwarding starts. A failed or pre-Ready interrupted invocation never - * changes the wrapper path; an overlapping successful invocation may - * independently commit the link and remains authoritative. Every other - * invocation transparently delegates its original argv. This + * proven Ready, atomically replaces the wrapper with a real-CLI link. A failed + * or pre-Ready interrupted invocation never changes the wrapper path; an + * overlapping successful invocation may independently commit the link and + * remains authoritative. Every other invocation transparently delegates its + * original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must From 5a10dcf33ecc73f31717754186dd3481a4a00e7d Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 01:18:28 -0700 Subject: [PATCH 17/23] fix(e2e): prove bounded forward handoff Signed-off-by: Aaron Erickson --- .github/workflows/base-image.yaml | 4 +- test/e2e/live/hermes-gpu-startup-fallback.ts | 8 ++++ test/e2e/live/hermes-gpu-startup.test.ts | 26 +++++++++++-- .../hermes-gpu-startup-fallback.test.ts | 37 +++++++++++++++++++ tools/e2e/base-image-publication.mts | 2 +- 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/.github/workflows/base-image.yaml b/.github/workflows/base-image.yaml index da5371c1afb..2d09168c2c6 100644 --- a/.github/workflows/base-image.yaml +++ b/.github/workflows/base-image.yaml @@ -6,7 +6,9 @@ # Triggers: # - Push to main when a base- or managed-image input changes # - Manual dispatch for ad-hoc rebuilds -# E2E publication verification accepts push builds, not manual rebuilds. +# E2E publication verification normally accepts push builds. Trusted manual PR +# branch reuse may accept an exact manual main publication only when its complete +# managed-image promotion job succeeded. # # Base images contain the expensive, rarely-changing layers. Complete image # publication consumes exact base digests from the same trusted workflow run. diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 209f685dfc8..e8d01188f8d 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -121,6 +121,7 @@ export function createHermesGpuFallbackWrapper( ...REQUIRED_OPENSHELL_MCP_FEATURES.map((marker) => `# capability: ${marker}`), `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, + "COMPATIBILITY_SIGNAL_TIMEOUT_SECONDS=2", "READY_QUERY_TIMEOUT_SECONDS=2", 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', `SANDBOX_NAME="$(printf '%s\\n' "$@" | awk 'previous == "--name" { print; exit } /^--name=/ { sub(/^--name=/, ""); print; exit } /^NEMOCLAW_SANDBOX_NAME=/ { sub(/^NEMOCLAW_SANDBOX_NAME=/, ""); print; exit } { previous = $0 }')"`, @@ -183,7 +184,14 @@ export function createHermesGpuFallbackWrapper( ' if [[ -n "$COMPATIBILITY_PID" ]] && kill -0 "$COMPATIBILITY_PID" 2>/dev/null; then', ' kill "-$signal" "$COMPATIBILITY_PID" 2>/dev/null || true', " fi", + " (", + ' sleep "$COMPATIBILITY_SIGNAL_TIMEOUT_SECONDS"', + ' kill -KILL "$COMPATIBILITY_PID" 2>/dev/null || true', + " ) &", + ' compatibility_watchdog_pid="$!"', ' wait "$COMPATIBILITY_PID" 2>/dev/null || true', + ' kill "$compatibility_watchdog_pid" 2>/dev/null || true', + ' wait "$compatibility_watchdog_pid" 2>/dev/null || true', " sandbox_is_ready && commit_compatibility_handoff || true", ' exit "$status"', " }", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 728c0f9e5ff..501a4c1be92 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -4,6 +4,10 @@ import fs from "node:fs"; import path from "node:path"; +import { + createForwardServiceTarget, + isForwardServiceListenerOwner, +} from "../../../src/lib/adapters/openshell/forward-service"; import { execTimeout, testTimeout } from "../../helpers/timeouts.ts"; import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; import { assertStockManagedImageReceipt } from "../fixtures/managed-image-receipt.ts"; @@ -487,9 +491,23 @@ test( sandboxName: SANDBOX_NAME, }); - const verifyFallback = () => { - expect(fallbackEvents.join("\n")).toBe( - `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff}`, + const verifyFallback = (wrapper: ReturnType) => { + const forwardOwnership = [18_789, 8_642].map((port) => + isForwardServiceListenerOwner( + createForwardServiceTarget( + { + executable: wrapper.wrapperPath, + gatewayName: "nemoclaw", + localHost: "127.0.0.1", + sandboxName: SANDBOX_NAME, + workspace: "default", + }, + port, + ), + ), + ); + expect([...fallbackEvents, `forward-ownership:${forwardOwnership.join(",")}`].join("\n")).toBe( + `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff}\nforward-ownership:true,true`, ); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( @@ -498,7 +516,7 @@ test( ), ).toBe(true); }; - await (fallbackWrapper ? Promise.resolve(verifyFallback()) : Promise.resolve()); + await (fallbackWrapper ? Promise.resolve(verifyFallback(fallbackWrapper)) : Promise.resolve()); progress.phase("validate GPU startup and supervisor proof"); const status = await host.command("nemoclaw", [SANDBOX_NAME, "status"], { diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 48c5f19180a..4d6f8edcbe6 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -512,6 +512,43 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); }); + it("kills and reaps a compatibility child that ignores cancellation (#11239)", async () => { + const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-child-timeout-test-", { + openshell: [ + "#!/usr/bin/env bash", + 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then exit 1; fi', + "trap '' HUP INT TERM", + 'printf \'%s\\n\' "$$" >"$E2E_FAKE_CHILD_PID"', + ': >"$E2E_FAKE_READY"', + "exec sleep 30", + "", + ].join("\n"), + }); + const ready = path.join(root, "compatibility-ready"); + const childPidPath = path.join(root, "compatibility-child.pid"); + const env = { + ...process.env, + ...wrapper.componentEnv, + E2E_FAKE_CHILD_PID: childPidPath, + E2E_FAKE_READY: ready, + }; + const compatibility = spawnWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], + env, + ); + const compatibilityStatus = waitForChild(compatibility); + await waitForFile(ready); + const delegatedPid = Number(fs.readFileSync(childPidPath, "utf8").trim()); + const terminatedAt = Date.now(); + + expect(compatibility.kill("SIGTERM")).toBe(true); + expect(await compatibilityStatus).toBe(143); + expect(Date.now() - terminatedAt).toBeLessThan(4_000); + expect(() => process.kill(delegatedPid, 0)).toThrow(); + expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); + }); + it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", diff --git a/tools/e2e/base-image-publication.mts b/tools/e2e/base-image-publication.mts index 4c90004b8ff..24ccb285bb2 100644 --- a/tools/e2e/base-image-publication.mts +++ b/tools/e2e/base-image-publication.mts @@ -863,7 +863,7 @@ export async function waitForBaseImagePublication( notice( selection.state === "selected" ? `Required base image publishers are not complete for ${selection.run.headSha}; selected workflow run status ${selection.run.status}; ${selection.run.url}` - : `Waiting for a trusted base-image push run covering ${options.history.relevantSha}`, + : `Waiting for a trusted base-image publication run covering ${options.history.relevantSha}`, ); await sleep(Math.min(options.pollMs, Math.max(1, deadline - now()))); } From 5a861d27370f65057425558049130f85d54791b6 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 02:13:15 -0700 Subject: [PATCH 18/23] fix(e2e): scope fallback handoff Signed-off-by: Aaron Erickson --- ci/e2e-assertion-budget.json | 6 +- test/e2e/live/hermes-gpu-startup-fallback.ts | 88 +---- test/e2e/live/hermes-gpu-startup.test.ts | 10 +- .../hermes-gpu-startup-fallback.test.ts | 326 +++--------------- 4 files changed, 77 insertions(+), 353 deletions(-) diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index 4b2c31a797c..91897ab9ec0 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -35,8 +35,8 @@ "throwGuards": 633, "objectFieldAssertions": 342, "assertionPoints": 4303, - "generatedProbeBlocks": 278, - "generatedProbeConditions": 949 + "generatedProbeBlocks": 276, + "generatedProbeConditions": 947 }, "fileMetricOrder": [ "directExpectCalls", @@ -68,7 +68,7 @@ "test/e2e/live/gpu-e2e.test.ts": [40,45,73,91,3], "test/e2e/live/hermes-discord.test.ts": [10,25,17,64,14], "test/e2e/live/hermes-e2e.test.ts": [82,93,112,127,3], - "test/e2e/live/hermes-gpu-startup.test.ts": [19,27,63,106,12], + "test/e2e/live/hermes-gpu-startup.test.ts": [19,27,63,106,10], "test/e2e/live/hermes-inference-switch.test.ts": [61,67,72,92,2], "test/e2e/live/hermes-root-entrypoint-smoke.test.ts": [4,27,4,27,4], "test/e2e/live/hermes-sandbox-secret-boundary.test.ts": [20,27,20,27,4], diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index e8d01188f8d..55711a5f249 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -81,14 +81,11 @@ function quoteShellLiteral(value: string): string { /** * Create an E2E-only OpenShell CLI wrapper that rejects the exact native - * `--gpu` create before build or sandbox progress. The compatibility create - * runs the real CLI while the rejecting wrapper stays installed. A normal - * success, or NemoClaw's expected termination after the sandbox is independently - * proven Ready, atomically replaces the wrapper with a real-CLI link. A failed - * or pre-Ready interrupted invocation never changes the wrapper path; an - * overlapping successful invocation may independently commit the link and - * remains authoritative. Every other invocation transparently delegates its - * original argv. This + * `--gpu` create for one sandbox before build or sandbox progress. When that + * sandbox enters compatibility create, the wrapper atomically replaces itself + * with a real-CLI link before executing the create through the configured path. + * Creates for other sandboxes cannot retire the fault injection. Every other + * invocation transparently delegates its original argv. This * test-only wrapper never logs argv: its sole artifact is an event log made of * fixed labels, so sandbox-create environment arguments never enter artifacts. * This interception pattern is specific to the #6110 fallback proof and must @@ -97,7 +94,7 @@ function quoteShellLiteral(value: string): string { */ export function createHermesGpuFallbackWrapper( realOpenshellPath: string, - options: { rootDir?: string } = {}, + options: { rootDir?: string; sandboxName: string }, ): HermesGpuFallbackWrapper { requireAbsoluteExecutable(realOpenshellPath, "real OpenShell CLI"); const componentDir = path.dirname(realOpenshellPath); @@ -121,10 +118,8 @@ export function createHermesGpuFallbackWrapper( ...REQUIRED_OPENSHELL_MCP_FEATURES.map((marker) => `# capability: ${marker}`), `REAL_OPENSHELL=${quoteShellLiteral(realOpenshellPath)}`, `FALLBACK_STATE_DIR=${quoteShellLiteral(stateDir)}`, - "COMPATIBILITY_SIGNAL_TIMEOUT_SECONDS=2", - "READY_QUERY_TIMEOUT_SECONDS=2", + `TARGET_SANDBOX_NAME=${quoteShellLiteral(options.sandboxName)}`, 'NATIVE_CREATE_REJECTED="$FALLBACK_STATE_DIR/native-create-rejected"', - `SANDBOX_NAME="$(printf '%s\\n' "$@" | awk 'previous == "--name" { print; exit } /^--name=/ { sub(/^--name=/, ""); print; exit } /^NEMOCLAW_SANDBOX_NAME=/ { sub(/^NEMOCLAW_SANDBOX_NAME=/, ""); print; exit } { previous = $0 }')"`, "", "commit_compatibility_handoff() {", ' REAL_OPENSHELL_LINK="$FALLBACK_STATE_DIR/openshell-real.$$"', @@ -133,41 +128,24 @@ export function createHermesGpuFallbackWrapper( ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff}' >>"$FALLBACK_STATE_DIR/events.log"`, "}", "", - "sandbox_is_ready() {", - ' READY_QUERY_OUTPUT="$FALLBACK_STATE_DIR/sandbox-ready.$$"', - ' (exec "$REAL_OPENSHELL" sandbox get "$SANDBOX_NAME") >"$READY_QUERY_OUTPUT" 2>/dev/null &', - ' ready_query_pid="$!"', - " (", - ' sleep "$READY_QUERY_TIMEOUT_SECONDS"', - ' kill -TERM "$ready_query_pid" 2>/dev/null || true', - " sleep 0.2", - ' kill -KILL "$ready_query_pid" 2>/dev/null || true', - " ) &", - ' ready_watchdog_pid="$!"', - " ready_query_status=0", - ' wait "$ready_query_pid" || ready_query_status="$?"', - ' kill "$ready_watchdog_pid" 2>/dev/null || true', - ' wait "$ready_watchdog_pid" 2>/dev/null || true', - ' test "$ready_query_status" -eq 0 &&', - " grep -Eq '(^|[[:space:]])Ready([[:space:]]|$)' \"$READY_QUERY_OUTPUT\"", - ' ready_query_status="$?"', - ' rm -f "$READY_QUERY_OUTPUT"', - ' return "$ready_query_status"', - "}", - "", "is_sandbox_create=0", + "is_target_sandbox=0", "has_gpu_flag=0", 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "create" ]]; then', " is_sandbox_create=1", + ' previous_arg=""', ' for arg in "$@"; do', - ' if [[ "$arg" == "--gpu" ]]; then', - " has_gpu_flag=1", - " break", - " fi", + ' case "$previous_arg:$arg" in', + ' "--name:$TARGET_SANDBOX_NAME"|*":--name=$TARGET_SANDBOX_NAME"|*":NEMOCLAW_SANDBOX_NAME=$TARGET_SANDBOX_NAME") is_target_sandbox=1 ;;', + " esac", + ' case "$arg" in', + " --gpu) has_gpu_flag=1 ;;", + " esac", + ' previous_arg="$arg"', " done", "fi", "", - 'if [[ "$is_sandbox_create" == "1" ]]; then', + 'if [[ "$is_sandbox_create" == "1" && "$is_target_sandbox" == "1" ]]; then', ' if [[ "$has_gpu_flag" == "1" ]]; then', ' if mkdir "$NATIVE_CREATE_REJECTED" 2>/dev/null; then', ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}' >>"$FALLBACK_STATE_DIR/events.log"`, @@ -176,38 +154,8 @@ export function createHermesGpuFallbackWrapper( " exit 2", " else", ` printf '%s\\n' '${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}' >>"$FALLBACK_STATE_DIR/events.log"`, - ' COMPATIBILITY_PID=""', - " forward_compatibility_signal() {", - ' local signal="$1"', - ' local status="$2"', - " trap - HUP INT TERM", - ' if [[ -n "$COMPATIBILITY_PID" ]] && kill -0 "$COMPATIBILITY_PID" 2>/dev/null; then', - ' kill "-$signal" "$COMPATIBILITY_PID" 2>/dev/null || true', - " fi", - " (", - ' sleep "$COMPATIBILITY_SIGNAL_TIMEOUT_SECONDS"', - ' kill -KILL "$COMPATIBILITY_PID" 2>/dev/null || true', - " ) &", - ' compatibility_watchdog_pid="$!"', - ' wait "$COMPATIBILITY_PID" 2>/dev/null || true', - ' kill "$compatibility_watchdog_pid" 2>/dev/null || true', - ' wait "$compatibility_watchdog_pid" 2>/dev/null || true', - " sandbox_is_ready && commit_compatibility_handoff || true", - ' exit "$status"', - " }", - " trap 'forward_compatibility_signal HUP 129' HUP", - " trap 'forward_compatibility_signal INT 130' INT", - " trap 'forward_compatibility_signal TERM 143' TERM", - ' (exec "$REAL_OPENSHELL" "$@") &', - ' COMPATIBILITY_PID="$!"', - ' wait "$COMPATIBILITY_PID" || {', - ' compatibility_status="$?"', - " trap - HUP INT TERM", - ' exit "$compatibility_status"', - " }", - " trap - HUP INT TERM", " commit_compatibility_handoff", - " exit 0", + ' exec "$0" "$@"', " fi", "fi", "", diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 501a4c1be92..3d74c4f2cab 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -440,7 +440,9 @@ test( timeoutMs: 30_000, }); expect(realOpenshell.exitCode, resultText(realOpenshell)).toBe(0); - const wrapper = createHermesGpuFallbackWrapper(realOpenshell.stdout.trim()); + const wrapper = createHermesGpuFallbackWrapper(realOpenshell.stdout.trim(), { + sandboxName: SANDBOX_NAME, + }); // Security-scoped #6110 fault injection: always remove the private wrapper root through the // E2E cleanup stack. Do not generalize PATH interception to other tests without review. cleanup.trackDisposable("remove Hermes GPU fallback wrapper", () => @@ -448,7 +450,7 @@ test( ); await artifacts.writeJson("gpu-fallback-wrapper.json", { behavior: - "reject the exact native --gpu create before progress, keep the rejecting wrapper installed during compatibility create, commit the real-CLI link after normal success or an independently verified Ready termination, and retain the wrapper after failure or pre-Ready interruption unless an overlapping success already committed", + "reject the intended sandbox's native --gpu create before progress, replace the wrapper with the real CLI link when that sandbox enters compatibility create, and do not let another sandbox retire the wrapper", eventVocabulary: HERMES_GPU_FALLBACK_EVENTS, }); return wrapper; @@ -506,7 +508,9 @@ test( ), ), ); - expect([...fallbackEvents, `forward-ownership:${forwardOwnership.join(",")}`].join("\n")).toBe( + expect( + [...fallbackEvents, `forward-ownership:${forwardOwnership.join(",")}`].join("\n"), + ).toBe( `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff}\nforward-ownership:true,true`, ); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 4d6f8edcbe6..5710b5cfdab 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -6,7 +6,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it } from "vitest"; import { buildDirectSandboxGpuProofCommands } from "../../../src/lib/onboard/initial-policy"; import { @@ -50,7 +50,10 @@ function createWrapperFixture( realDir, realOpenshell, root, - wrapper: createHermesGpuFallbackWrapper(realOpenshell, { rootDir: path.join(root, "wrapper") }), + wrapper: createHermesGpuFallbackWrapper(realOpenshell, { + rootDir: path.join(root, "wrapper"), + sandboxName: "alpha", + }), }; } @@ -69,10 +72,6 @@ function waitForChild(child: ReturnType): Promise { }); } -async function waitForFile(filePath: string): Promise { - await vi.waitUntil(() => fs.existsSync(filePath), { interval: 20, timeout: 5_000 }); -} - describe("Hermes GPU startup scenario selection", () => { it.each([ [undefined, false, { route: "native-success", scenario: "native" }], @@ -166,6 +165,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { "image", "--gpu", "--", + "NEMOCLAW_SANDBOX_NAME=alpha", `TOKEN=${secretMarkers[0]}`, `OPENAI_API_KEY=${secretMarkers[1]}`, `PASSWORD=${secretMarkers[2]}`, @@ -184,7 +184,16 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { const compatibility = runWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + [ + "sandbox", + "create", + "--from", + "image", + "--gpu-device", + "all", + "--", + "NEMOCLAW_SANDBOX_NAME=alpha", + ], env, ); expect(compatibility.status, compatibility.stderr).toBe(0); @@ -193,7 +202,16 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { const repeatedCompatibility = runWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + [ + "sandbox", + "create", + "--from", + "image", + "--gpu-device", + "all", + "--", + "NEMOCLAW_SANDBOX_NAME=alpha", + ], env, ); expect(repeatedCompatibility.status, repeatedCompatibility.stderr).toBe(0); @@ -232,11 +250,11 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { "delegated", ]); expect(fs.readFileSync(delegateExecutableLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ - realOpenshell, realOpenshell, wrapper.wrapperPath, wrapper.wrapperPath, wrapper.wrapperPath, + wrapper.wrapperPath, ]); }); @@ -246,7 +264,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { const firstNativeCreate = runWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu"], + ["sandbox", "create", "--from", "image", "--gpu", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], env, ); expect(firstNativeCreate.status).toBe(2); @@ -261,7 +279,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { const secondNativeCreate = runWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu"], + ["sandbox", "create", "--from", "image", "--gpu", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], env, ); expect(secondNativeCreate.status).toBe(2); @@ -270,285 +288,39 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ]); }); - it("keeps native fault injection when compatibility create fails (#11239)", () => { - const { wrapper } = createWrapperFixture("hermes-gpu-fallback-failed-create-test-", { - openshell: [ - "#!/usr/bin/env bash", - 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "create" ]]; then exit 23; fi', - "exit 0", - "", - ].join("\n"), - }); + it("does not let another sandbox retire the target sandbox fault injection (#11239)", () => { + const { wrapper } = createWrapperFixture("hermes-gpu-fallback-other-sandbox-test-"); const env = { ...process.env, ...wrapper.componentEnv }; - expect( - runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) - .status, - ).toBe(2); expect( runWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], + [ + "sandbox", + "create", + "--from", + "image", + "--gpu-device", + "all", + "--", + "NEMOCLAW_SANDBOX_NAME=beta", + ], env, ).status, - ).toBe(23); - expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); - expect( - runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) - .status, - ).toBe(2); - }); - - it("rejects a native create while compatibility handoff is still pending (#11239)", async () => { - const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-pending-test-", { - openshell: [ - "#!/usr/bin/env bash", - 'for arg in "$@"; do', - ' if [[ "$arg" == "--gpu" ]]; then', - ` printf '%s\\n' native-bypass >>"$E2E_FAKE_DELEGATE_LOG"`, - " exit 97", - " fi", - "done", - `printf '%s\\n' compatibility >>"$E2E_FAKE_DELEGATE_LOG"`, - ': >"$E2E_FAKE_READY"', - 'while [[ ! -f "$E2E_FAKE_RELEASE" ]]; do sleep 0.02; done', - "exit 0", - "", - ].join("\n"), - }); - const ready = path.join(root, "compatibility-ready"); - const release = path.join(root, "compatibility-release"); - const delegateLog = path.join(root, "delegate.log"); - const env = { - ...process.env, - ...wrapper.componentEnv, - E2E_FAKE_DELEGATE_LOG: delegateLog, - E2E_FAKE_READY: ready, - E2E_FAKE_RELEASE: release, - }; - const compatibility = spawnWrapper( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], - env, - ); - const compatibilityStatus = waitForChild(compatibility); - await waitForFile(ready); - - expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); - expect( - runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) - .status, - ).toBe(2); - expect(fs.readFileSync(delegateLog, "utf8").trim()).toBe("compatibility"); - - fs.writeFileSync(release, ""); - expect(await compatibilityStatus).toBe(0); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - }); - - it("retains the successful handoff when an overlapping compatibility create fails (#11239)", async () => { - const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-overlap-test-", { - openshell: [ - "#!/usr/bin/env bash", - "mode=failure", - 'for arg in "$@"; do [[ "$arg" == "--fixture-success" ]] && mode=success; done', - 'if [[ "$mode" == "success" ]]; then', - ' ready="$E2E_SUCCESS_READY"', - ' release="$E2E_SUCCESS_RELEASE"', - "else", - ' ready="$E2E_FAILURE_READY"', - ' release="$E2E_FAILURE_RELEASE"', - "fi", - ': >"$ready"', - 'while [[ ! -f "$release" ]]; do sleep 0.02; done', - '[[ "$mode" == "success" ]] && exit 0', - "exit 23", - "", - ].join("\n"), - }); - const successReady = path.join(root, "success-ready"); - const successRelease = path.join(root, "success-release"); - const failureReady = path.join(root, "failure-ready"); - const failureRelease = path.join(root, "failure-release"); - const env = { - ...process.env, - ...wrapper.componentEnv, - E2E_FAILURE_READY: failureReady, - E2E_FAILURE_RELEASE: failureRelease, - E2E_SUCCESS_READY: successReady, - E2E_SUCCESS_RELEASE: successRelease, - }; - const successful = spawnWrapper( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all", "--fixture-success"], - env, - ); - const successfulStatus = waitForChild(successful); - const failing = spawnWrapper( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], - env, - ); - const failingStatus = waitForChild(failing); - await Promise.all([waitForFile(successReady), waitForFile(failureReady)]); - - fs.writeFileSync(successRelease, ""); - expect(await successfulStatus).toBe(0); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - fs.writeFileSync(failureRelease, ""); - expect(await failingStatus).toBe(23); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - }); - - it("leaves native fault injection installed when compatibility create is interrupted (#11239)", async () => { - const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-interrupt-test-", { - openshell: [ - "#!/usr/bin/env bash", - 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then exit 1; fi', - "trap 'exit 143' HUP INT TERM", - ': >"$E2E_FAKE_READY"', - "while :; do sleep 1; done", - "", - ].join("\n"), - }); - const ready = path.join(root, "compatibility-ready"); - const env = { - ...process.env, - ...wrapper.componentEnv, - E2E_FAKE_READY: ready, - }; - const compatibility = spawnWrapper( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu-device", "all"], - env, - ); - const compatibilityStatus = waitForChild(compatibility); - await waitForFile(ready); - - expect(compatibility.kill("SIGTERM")).toBe(true); - expect(await compatibilityStatus).toBe(143); + ).toBe(0); expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); expect( - runWrapper(wrapper.wrapperPath, ["sandbox", "create", "--from", "image", "--gpu"], env) - .status, + runWrapper( + wrapper.wrapperPath, + ["sandbox", "create", "--from", "image", "--gpu", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], + env, + ).status, ).toBe(2); - }); - - it("commits the handoff when the create client is terminated after Ready (#11239)", async () => { - const { realOpenshell, root, wrapper } = createWrapperFixture( - "hermes-gpu-fallback-ready-termination-test-", - { - openshell: [ - "#!/usr/bin/env bash", - 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then', - " printf '%s\\n' 'Phase: Ready'", - " exit 0", - "fi", - "trap 'exit 143' HUP INT TERM", - ': >"$E2E_FAKE_READY"', - "while :; do sleep 1; done", - "", - ].join("\n"), - }, - ); - const ready = path.join(root, "compatibility-ready"); - const env = { - ...process.env, - ...wrapper.componentEnv, - E2E_FAKE_READY: ready, - }; - const compatibility = spawnWrapper( - wrapper.wrapperPath, - [ - "sandbox", - "create", - "--from", - "image", - "--gpu-device", - "all", - "--", - "NEMOCLAW_SANDBOX_NAME=alpha", - ], - env, - ); - const compatibilityStatus = waitForChild(compatibility); - await waitForFile(ready); - - expect(compatibility.kill("SIGTERM")).toBe(true); - expect(await compatibilityStatus).toBe(143); - expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); - expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ - HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, - HERMES_GPU_FALLBACK_EVENTS.commitCompatibilityHandoff, + HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, ]); }); - it("bounds a stuck Ready query and retains native fault injection (#11239)", async () => { - const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-ready-timeout-test-", { - openshell: [ - "#!/usr/bin/env bash", - 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then exec sleep 30; fi', - "trap 'exit 143' HUP INT TERM", - ': >"$E2E_FAKE_READY"', - "while :; do sleep 1; done", - "", - ].join("\n"), - }); - const ready = path.join(root, "compatibility-ready"); - const env = { ...process.env, ...wrapper.componentEnv, E2E_FAKE_READY: ready }; - const compatibility = spawnWrapper( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], - env, - ); - const compatibilityStatus = waitForChild(compatibility); - await waitForFile(ready); - const terminatedAt = Date.now(); - - expect(compatibility.kill("SIGTERM")).toBe(true); - expect(await compatibilityStatus).toBe(143); - expect(Date.now() - terminatedAt).toBeLessThan(4_000); - expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); - }); - - it("kills and reaps a compatibility child that ignores cancellation (#11239)", async () => { - const { root, wrapper } = createWrapperFixture("hermes-gpu-fallback-child-timeout-test-", { - openshell: [ - "#!/usr/bin/env bash", - 'if [[ "${1:-}" == "sandbox" && "${2:-}" == "get" ]]; then exit 1; fi', - "trap '' HUP INT TERM", - 'printf \'%s\\n\' "$$" >"$E2E_FAKE_CHILD_PID"', - ': >"$E2E_FAKE_READY"', - "exec sleep 30", - "", - ].join("\n"), - }); - const ready = path.join(root, "compatibility-ready"); - const childPidPath = path.join(root, "compatibility-child.pid"); - const env = { - ...process.env, - ...wrapper.componentEnv, - E2E_FAKE_CHILD_PID: childPidPath, - E2E_FAKE_READY: ready, - }; - const compatibility = spawnWrapper( - wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], - env, - ); - const compatibilityStatus = waitForChild(compatibility); - await waitForFile(ready); - const delegatedPid = Number(fs.readFileSync(childPidPath, "utf8").trim()); - const terminatedAt = Date.now(); - - expect(compatibility.kill("SIGTERM")).toBe(true); - expect(await compatibilityStatus).toBe(143); - expect(Date.now() - terminatedAt).toBeLessThan(4_000); - expect(() => process.kill(delegatedPid, 0)).toThrow(); - expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); - }); - it("preserves the fallback wrapper while staging the existing OpenShell service (#7140)", () => { const { realDir, root, wrapper } = createWrapperFixture( "hermes-gpu-fallback-installer-selection-", @@ -667,7 +439,7 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { waitForChild( spawnWrapper( wrapper.wrapperPath, - ["sandbox", "create", "--from", "image", "--gpu"], + ["sandbox", "create", "--from", "image", "--gpu", "--", "NEMOCLAW_SANDBOX_NAME=alpha"], env, ), ), From b884e3f87b15cc0d1e3910899a8e8f5e0a1c05a6 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 02:53:19 -0700 Subject: [PATCH 19/23] test(e2e): remove obsolete GPU probe copy Signed-off-by: Aaron Erickson --- ci/e2e-assertion-budget.json | 6 +-- test/e2e/live/hermes-gpu-startup-fallback.ts | 8 ---- .../hermes-gpu-startup-fallback.test.ts | 37 ++----------------- 3 files changed, 6 insertions(+), 45 deletions(-) diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index 91897ab9ec0..31c3104662a 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -35,8 +35,8 @@ "throwGuards": 633, "objectFieldAssertions": 342, "assertionPoints": 4303, - "generatedProbeBlocks": 276, - "generatedProbeConditions": 947 + "generatedProbeBlocks": 275, + "generatedProbeConditions": 946 }, "fileMetricOrder": [ "directExpectCalls", @@ -68,7 +68,7 @@ "test/e2e/live/gpu-e2e.test.ts": [40,45,73,91,3], "test/e2e/live/hermes-discord.test.ts": [10,25,17,64,14], "test/e2e/live/hermes-e2e.test.ts": [82,93,112,127,3], - "test/e2e/live/hermes-gpu-startup.test.ts": [19,27,63,106,10], + "test/e2e/live/hermes-gpu-startup.test.ts": [19,27,63,106,9], "test/e2e/live/hermes-inference-switch.test.ts": [61,67,72,92,2], "test/e2e/live/hermes-root-entrypoint-smoke.test.ts": [4,27,4,27,4], "test/e2e/live/hermes-sandbox-secret-boundary.test.ts": [20,27,20,27,4], diff --git a/test/e2e/live/hermes-gpu-startup-fallback.ts b/test/e2e/live/hermes-gpu-startup-fallback.ts index 55711a5f249..9c854133f4a 100644 --- a/test/e2e/live/hermes-gpu-startup-fallback.ts +++ b/test/e2e/live/hermes-gpu-startup-fallback.ts @@ -13,14 +13,6 @@ export const HERMES_GPU_FALLBACK_EVENTS = { commitCompatibilityHandoff: "commit-compatibility-handoff", } as const; -export const HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF = [ - "set -eu;", - "if command -v nvidia-smi >/dev/null 2>&1; then", - "exec nvidia-smi;", - "fi;", - 'echo "nvidia-smi not installed; skipping optional visibility check"', -].join(" "); - export interface HermesGpuFallbackWrapper { componentEnv: NodeJS.ProcessEnv; eventsPath: string; diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 5710b5cfdab..856a36663eb 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -8,7 +8,6 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; -import { buildDirectSandboxGpuProofCommands } from "../../../src/lib/onboard/initial-policy"; import { hasRequiredOpenshellMessagingFeatures, REQUIRED_OPENSHELL_SANDBOX_MCP_FEATURE, @@ -17,7 +16,6 @@ import { createHermesGpuFallbackWrapper, extractHermesGpuDiagnosticsDirectory, HERMES_GPU_FALLBACK_EVENTS, - HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF, readHermesGpuFallbackEvents, resolveHermesGpuStartupScenario, } from "../live/hermes-gpu-startup-fallback.ts"; @@ -110,22 +108,6 @@ describe("Hermes GPU startup failure diagnostics", () => { }); describe("Hermes GPU startup fallback OpenShell wrapper", () => { - it("tracks the exact production nvidia-smi proof argv", () => { - const proof = buildDirectSandboxGpuProofCommands("alpha").find( - (candidate) => candidate.id === "nvidia-smi", - ); - expect(proof?.args).toEqual([ - "sandbox", - "exec", - "-n", - "alpha", - "--", - "sh", - "-lc", - HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF, - ]); - }); - it("keeps the real OpenShell CLI at the wrapper path after compatibility create succeeds (#11239)", () => { const { realOpenshell, root, wrapper } = createWrapperFixture("hermes-gpu-fallback-test-", { openshell: [ @@ -216,13 +198,6 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ); expect(repeatedCompatibility.status, repeatedCompatibility.stderr).toBe(0); - const compatibilityProof = runWrapper( - wrapper.wrapperPath, - ["sandbox", "exec", "-n", "alpha", "--", "sh", "-lc", HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF], - env, - ); - expect(compatibilityProof.status, compatibilityProof.stderr).toBe(0); - const version = runWrapper(wrapper.wrapperPath, ["--version"], env); expect(version.status, version.stderr).toBe(0); expect(readHermesGpuFallbackEvents(wrapper.eventsPath)).toEqual([ @@ -247,18 +222,16 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { "create-without-gpu", "create-without-gpu", "delegated", - "delegated", ]); expect(fs.readFileSync(delegateExecutableLog, "utf8").split(/\r?\n/u).filter(Boolean)).toEqual([ realOpenshell, wrapper.wrapperPath, wrapper.wrapperPath, wrapper.wrapperPath, - wrapper.wrapperPath, ]); }); - it("keeps native fault injection when the exact proof precedes compatibility create (#11239)", () => { + it("keeps native fault injection when a delegated command precedes compatibility create (#11239)", () => { const { wrapper } = createWrapperFixture("hermes-gpu-fallback-order-test-"); const env = { ...process.env, ...wrapper.componentEnv }; @@ -269,12 +242,8 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { ); expect(firstNativeCreate.status).toBe(2); - const prematureProof = runWrapper( - wrapper.wrapperPath, - ["sandbox", "exec", "-n", "alpha", "--", "sh", "-lc", HERMES_GPU_NATIVE_NVIDIA_SMI_PROOF], - env, - ); - expect(prematureProof.status, prematureProof.stderr).toBe(0); + const delegatedVersion = runWrapper(wrapper.wrapperPath, ["--version"], env); + expect(delegatedVersion.status, delegatedVersion.stderr).toBe(0); expect(fs.lstatSync(wrapper.wrapperPath).isFile()).toBe(true); const secondNativeCreate = runWrapper( From 6bccff5c66f88e12e6c7d57c7aee487170e5aba3 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 06:37:50 -0700 Subject: [PATCH 20/23] fix(e2e): resolve runtime forward ports Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup.test.ts | 12 ++++-- .../hermes-gpu-startup-fallback.test.ts | 37 +------------------ 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 59cce7a899f..d0f0ea93e10 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -4,6 +4,7 @@ import fs from "node:fs"; import path from "node:path"; +import { resolveSandboxLaunchForwardPorts } from "../../../src/lib/actions/sandbox/process-recovery"; import { createForwardServiceTarget, isForwardServiceListenerOwner, @@ -492,7 +493,8 @@ test( }); const verifyFallback = (wrapper: ReturnType) => { - const forwardOwnership = [18_789, 8_642].map((port) => + const forwardPorts = resolveSandboxLaunchForwardPorts(SANDBOX_NAME); + const forwardOwnership = (forwardPorts ?? []).map((port) => isForwardServiceListenerOwner( createForwardServiceTarget( { @@ -507,9 +509,13 @@ test( ), ); expect( - [...fallbackEvents, `forward-ownership:${forwardOwnership.join(",")}`].join("\n"), + [ + ...fallbackEvents, + `forward-ports:${forwardPorts?.join(",") ?? "unresolved"}`, + `forward-ownership:${forwardOwnership.length > 0 && forwardOwnership.every(Boolean)}`, + ].join("\n"), ).toBe( - `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}\nforward-ownership:true,true`, + `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}\nforward-ports:${forwardPorts?.join(",") ?? "unresolved"}\nforward-ownership:true`, ); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( diff --git a/test/e2e/support/hermes-gpu-startup-fallback.test.ts b/test/e2e/support/hermes-gpu-startup-fallback.test.ts index 1fbc9e68d9b..1049f98d103 100644 --- a/test/e2e/support/hermes-gpu-startup-fallback.test.ts +++ b/test/e2e/support/hermes-gpu-startup-fallback.test.ts @@ -8,7 +8,6 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; -import { createForwardServiceTarget } from "../../../src/lib/adapters/openshell/forward-service"; import { buildDirectSandboxGpuProofCommands } from "../../../src/lib/onboard/initial-policy"; import { hasRequiredOpenshellMessagingFeatures, @@ -190,42 +189,8 @@ describe("Hermes GPU startup fallback OpenShell wrapper", () => { env, ); expect(compatibilityProof.status, compatibilityProof.stderr).toBe(0); + expect(fs.lstatSync(wrapper.wrapperPath).isSymbolicLink()).toBe(true); expect(fs.realpathSync(wrapper.wrapperPath)).toBe(fs.realpathSync(realOpenshell)); - expect( - [18_789, 8_642].map((port) => - createForwardServiceTarget( - { - executable: wrapper.wrapperPath, - gatewayName: "nemoclaw", - localHost: "127.0.0.1", - sandboxName: "alpha", - workspace: "default", - }, - port, - ), - ), - ).toEqual([ - { - executable: wrapper.wrapperPath, - gatewayName: "nemoclaw", - localHost: "127.0.0.1", - localPort: 18_789, - sandboxName: "alpha", - targetHost: "127.0.0.1", - targetPort: 18_789, - workspace: "default", - }, - { - executable: wrapper.wrapperPath, - gatewayName: "nemoclaw", - localHost: "127.0.0.1", - localPort: 8_642, - sandboxName: "alpha", - targetHost: "127.0.0.1", - targetPort: 8_642, - workspace: "default", - }, - ]); const version = runWrapper(wrapper.wrapperPath, ["--version"], env); expect(version.status, version.stderr).toBe(0); From 4f3e831e2d64dc3067eaffad0066d8b62385ff01 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 07:13:40 -0700 Subject: [PATCH 21/23] test(e2e): report forward ownership by port Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup.test.ts | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index d0f0ea93e10..67a621d02db 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -494,28 +494,29 @@ test( const verifyFallback = (wrapper: ReturnType) => { const forwardPorts = resolveSandboxLaunchForwardPorts(SANDBOX_NAME); - const forwardOwnership = (forwardPorts ?? []).map((port) => - isForwardServiceListenerOwner( - createForwardServiceTarget( - { - executable: wrapper.wrapperPath, - gatewayName: "nemoclaw", - localHost: "127.0.0.1", - sandboxName: SANDBOX_NAME, - workspace: "default", - }, - port, - ), - ), + const forwardOwnership = (forwardPorts ?? []).map( + (port) => + `${port}=${isForwardServiceListenerOwner( + createForwardServiceTarget( + { + executable: wrapper.wrapperPath, + gatewayName: "nemoclaw", + localHost: "127.0.0.1", + sandboxName: SANDBOX_NAME, + workspace: "default", + }, + port, + ), + )}`, ); expect( [ ...fallbackEvents, - `forward-ports:${forwardPorts?.join(",") ?? "unresolved"}`, - `forward-ownership:${forwardOwnership.length > 0 && forwardOwnership.every(Boolean)}`, + `forward-ownership:${forwardOwnership.join(",")}`, + `forward-ownership-complete:${forwardOwnership.length > 0 && forwardOwnership.every((entry) => entry.endsWith("=true"))}`, ].join("\n"), ).toBe( - `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}\nforward-ports:${forwardPorts?.join(",") ?? "unresolved"}\nforward-ownership:true`, + `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}\nforward-ownership:${(forwardPorts ?? []).map((port) => `${port}=true`).join(",")}\nforward-ownership-complete:true`, ); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( From 613d036498399a3afee73c39b62eb80458cee944 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 07:49:16 -0700 Subject: [PATCH 22/23] test(e2e): require both forward owners Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup.test.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 67a621d02db..0bffd05bfba 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -509,15 +509,18 @@ test( ), )}`, ); + const expectedFallbackEvents = [ + HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress, + HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate, + HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback, + ]; expect( - [ - ...fallbackEvents, - `forward-ownership:${forwardOwnership.join(",")}`, - `forward-ownership-complete:${forwardOwnership.length > 0 && forwardOwnership.every((entry) => entry.endsWith("=true"))}`, - ].join("\n"), - ).toBe( - `${HERMES_GPU_FALLBACK_EVENTS.rejectNativeCreateBeforeProgress}\n${HERMES_GPU_FALLBACK_EVENTS.delegateCompatibilityCreate}\n${HERMES_GPU_FALLBACK_EVENTS.delegateNvidiaSmiProofAfterFallback}\nforward-ownership:${(forwardPorts ?? []).map((port) => `${port}=true`).join(",")}\nforward-ownership-complete:true`, - ); + fallbackEvents.join("\n") === expectedFallbackEvents.join("\n") && + forwardOwnership.length === 2 && + new Set(forwardPorts ?? []).size === 2 && + forwardOwnership.every((entry) => entry.endsWith("=true")), + `fallback events: ${fallbackEvents.join(", ")}; forward ownership: ${forwardOwnership.join(", ") || "unresolved"}`, + ).toBe(true); expect(resultText(install)).toContain("Native GPU diagnostics saved:"); expect( HERMES_GPU_FALLBACK_DISCLOSURE_FRAGMENTS.every((fragment) => From 604ac0671929ecad5f4e6182a251f8802712b0d9 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Wed, 9 Sep 2026 08:18:43 -0700 Subject: [PATCH 23/23] test(e2e): simplify fallback checks Signed-off-by: Aaron Erickson --- test/e2e/live/hermes-gpu-startup.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/e2e/live/hermes-gpu-startup.test.ts b/test/e2e/live/hermes-gpu-startup.test.ts index 0bffd05bfba..00f7233867f 100644 --- a/test/e2e/live/hermes-gpu-startup.test.ts +++ b/test/e2e/live/hermes-gpu-startup.test.ts @@ -482,9 +482,7 @@ test( const fallbackEvents = fallbackWrapper ? readHermesGpuFallbackEvents(fallbackWrapper.eventsPath) : []; - await (fallbackWrapper - ? artifacts.writeJson("gpu-fallback-events.json", fallbackEvents) - : Promise.resolve()); + await (fallbackWrapper && artifacts.writeJson("gpu-fallback-events.json", fallbackEvents)); expect(install.exitCode, resultText(install)).toBe(0); assertStockManagedImageReceipt({ environment: env, @@ -528,7 +526,7 @@ test( ), ).toBe(true); }; - await (fallbackWrapper ? Promise.resolve(verifyFallback(fallbackWrapper)) : Promise.resolve()); + fallbackWrapper && verifyFallback(fallbackWrapper); progress.phase("validate GPU startup and supervisor proof"); const status = await host.command("nemoclaw", [SANDBOX_NAME, "status"], {