-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(hermes): install safety-net + ciao NODE_OPTIONS preloads so recover can relaunch #5416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
hizrianraz
wants to merge
4
commits into
NVIDIA:main
from
hizrianraz:fix/hermes-recover-node-guards-2478
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8c9a3f7
fix(hermes): install safety-net + ciao NODE_OPTIONS preloads so recov…
hizrianraz 848f1a2
Merge branch 'main' into fix/hermes-recover-node-guards-2478
cv 1646a35
chore(hermes): format guard preload redirects
cjagwani e8ede91
fix(hermes): install recovery preloads in image
cjagwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { spawnSync } from "node:child_process"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| const ROOT = path.resolve(import.meta.dirname, ".."); | ||
| const START_SCRIPT = path.join(ROOT, "agents", "hermes", "start.sh"); | ||
| const DOCKERFILE = path.join(ROOT, "agents", "hermes", "Dockerfile"); | ||
|
|
||
| function extractGuardInstaller(source: string): string { | ||
| const start = source.indexOf("install_nemoclaw_node_guards() {"); | ||
| const end = source.indexOf("\n# Invoked with", start); | ||
| expect(start).toBeGreaterThanOrEqual(0); | ||
| expect(end).toBeGreaterThan(start); | ||
| return source.slice(start, end); | ||
| } | ||
|
|
||
| function shellQuote(value: string): string { | ||
| return `'${value.replaceAll("'", "'\\''")}'`; | ||
| } | ||
|
|
||
| function runGuardInstaller(sourceDir: string, emitFunction: string) { | ||
| const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-node-guards-")); | ||
| const safetyTarget = path.join(tempDir, "sandbox-safety-net.js"); | ||
| const ciaoTarget = path.join(tempDir, "ciao-network-guard.js"); | ||
| const source = fs | ||
| .readFileSync(START_SCRIPT, "utf8") | ||
| .replaceAll("/tmp/nemoclaw-sandbox-safety-net.js", safetyTarget) | ||
| .replaceAll("/tmp/nemoclaw-ciao-network-guard.js", ciaoTarget); | ||
| const script = [ | ||
| "set -euo pipefail", | ||
| emitFunction, | ||
| extractGuardInstaller(source), | ||
| 'NODE_OPTIONS=""', | ||
| `install_nemoclaw_node_guards ${shellQuote(sourceDir)}`, | ||
| 'printf "NODE_OPTIONS=%s\\n" "$NODE_OPTIONS"', | ||
| ].join("\n"); | ||
| const result = spawnSync("bash", ["--noprofile", "--norc", "-c", script], { | ||
| encoding: "utf8", | ||
| timeout: 5000, | ||
| }); | ||
| return { ciaoTarget, result, safetyTarget, tempDir }; | ||
| } | ||
|
|
||
| describe("Hermes Node guard installation", () => { | ||
| it("stages both image-owned guards and exports them through NODE_OPTIONS", () => { | ||
| const sourceDir = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-node-guard-source-")); | ||
| fs.writeFileSync(path.join(sourceDir, "sandbox-safety-net.js"), "// safety\n"); | ||
| fs.writeFileSync(path.join(sourceDir, "ciao-network-guard.js"), "// ciao\n"); | ||
| const harness = runGuardInstaller(sourceDir, 'emit_sandbox_sourced_file() { cat >"$1"; }'); | ||
| try { | ||
| expect(harness.result.status, harness.result.stderr).toBe(0); | ||
| expect(fs.readFileSync(harness.safetyTarget, "utf8")).toBe("// safety\n"); | ||
| expect(fs.readFileSync(harness.ciaoTarget, "utf8")).toBe("// ciao\n"); | ||
| expect(harness.result.stdout).toContain(`--require ${harness.safetyTarget}`); | ||
| expect(harness.result.stdout).toContain(`--require ${harness.ciaoTarget}`); | ||
| } finally { | ||
| fs.rmSync(sourceDir, { force: true, recursive: true }); | ||
| fs.rmSync(harness.tempDir, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("keeps startup alive when guard staging fails", () => { | ||
| const sourceDir = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-node-guard-source-")); | ||
| fs.writeFileSync(path.join(sourceDir, "sandbox-safety-net.js"), "// safety\n"); | ||
| fs.writeFileSync(path.join(sourceDir, "ciao-network-guard.js"), "// ciao\n"); | ||
| const harness = runGuardInstaller(sourceDir, "emit_sandbox_sourced_file() { return 1; }"); | ||
| try { | ||
| expect(harness.result.status, harness.result.stderr).toBe(0); | ||
| expect(harness.result.stdout).toBe("NODE_OPTIONS=\n"); | ||
| expect(harness.result.stderr).toContain("could not install sandbox-safety-net preload"); | ||
| expect(harness.result.stderr).toContain("could not install ciao-network-guard preload"); | ||
| } finally { | ||
| fs.rmSync(sourceDir, { force: true, recursive: true }); | ||
| fs.rmSync(harness.tempDir, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("keeps startup alive when the image guard directory is missing", () => { | ||
| const missingDir = path.join(os.tmpdir(), `missing-hermes-guards-${process.pid}`); | ||
| const harness = runGuardInstaller(missingDir, 'emit_sandbox_sourced_file() { cat >"$1"; }'); | ||
| try { | ||
| expect(harness.result.status, harness.result.stderr).toBe(0); | ||
| expect(harness.result.stdout).toBe("NODE_OPTIONS=\n"); | ||
| expect(harness.result.stderr).toContain("NemoClaw preload guards not found"); | ||
| } finally { | ||
| fs.rmSync(harness.tempDir, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("copies the recovery preloads into the Hermes image contract", () => { | ||
| const dockerfile = fs.readFileSync(DOCKERFILE, "utf8"); | ||
| expect(dockerfile).toContain( | ||
| "COPY nemoclaw-blueprint/scripts/*.js /usr/local/lib/nemoclaw/preloads/", | ||
| ); | ||
| expect(dockerfile).toContain( | ||
| "find /usr/local/lib/nemoclaw/preloads -type f -name '*.js' -exec chmod 644 {} +", | ||
| ); | ||
| expect(fs.readFileSync(START_SCRIPT, "utf8")).not.toContain("NEMOCLAW_GUARD_DIRS"); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add
(#2478)suffix to test titles per guideline.These tests directly cover the recovery-refusal / guard-preload behavior for issue
#2478(as referenced in thestart.shwarning strings), but their titles lack the local issue-reference suffix required for**/*.test.tsfiles.📝 Proposed fix
As per coding guidelines, "
**/*.test.ts: Write behavior-oriented test titles, and put local issue references in a final(#1234)suffix."Also applies to: 68-68, 84-84
🤖 Prompt for AI Agents
Source: Coding guidelines