From 666d8aa3750037f464880fd3e8d7b7aae0487a9e Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:19:47 -0700 Subject: [PATCH 01/21] fix(inference): reject encoded native NVIDIA hosts Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> (cherry picked from commit 7e0408178cdb01b103e2e4fae1c289f53f0e5873) --- agents/hermes/managed_policy.py | 12 +++++++++++- scripts/nemoclaw-start.sh | 19 +++++++++++++++++++ src/lib/inference-credential.ts | 15 +++++++++++++++ test/fixtures/native-nvidia-inference-urls.ts | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/agents/hermes/managed_policy.py b/agents/hermes/managed_policy.py index 3f2d9dfe22c..0852d9fb2e3 100644 --- a/agents/hermes/managed_policy.py +++ b/agents/hermes/managed_policy.py @@ -10,7 +10,7 @@ import re import stat from pathlib import Path -from urllib.parse import urlsplit +from urllib.parse import unquote, urlsplit MANAGED_POLICY_PATH = Path("/usr/local/share/nemoclaw/hermes-managed-policy.json") MANAGED_POLICY_SCHEMA_VERSION = 3 @@ -118,6 +118,16 @@ def load_managed_policy(path: Path = MANAGED_POLICY_PATH) -> dict: _ = url.port except (TypeError, ValueError): raise ManagedPolicyError("managed policy model.base_url is invalid") from None + if ( + not native_nvidia + and "%" in (url.hostname or "") + and url.scheme.lower() == "https" + and unquote(url.hostname or "").lower() == "integrate.api.nvidia.com" + and url.port in (None, 443) + ): + raise ManagedPolicyError( + "Native NVIDIA inference requires https://integrate.api.nvidia.com/v1." + ) expected_key = NVIDIA_INFERENCE_PLACEHOLDER if native_nvidia else HERMES_PROXY_REWRITE_SENTINEL if policy_value(config, "model.api_key") != expected_key: raise ManagedPolicyError( diff --git a/scripts/nemoclaw-start.sh b/scripts/nemoclaw-start.sh index 56b034bfd93..6203a38aa37 100755 --- a/scripts/nemoclaw-start.sh +++ b/scripts/nemoclaw-start.sh @@ -74,6 +74,25 @@ clear_managed_inference_credentials() { printf '%s\n' '[SECURITY] Native NVIDIA inference requires https://integrate.api.nvidia.com/v1.' >&2 return 1 fi + if [[ "${NEMOCLAW_INFERENCE_BASE_URL:-}" == *%* ]] && ! is_managed_inference_route; then + # Decode an encoded host in a child without either provider credential. + local encoded_host_status=0 + env -i PATH="$PATH" NEMOCLAW_INFERENCE_BASE_URL="${NEMOCLAW_INFERENCE_BASE_URL:-}" node -e ' + try { + const url = new URL(process.env.NEMOCLAW_INFERENCE_BASE_URL); + if (url.protocol === "https:" && url.hostname === "integrate.api.nvidia.com" && + url.port === "") process.exit(42); + } catch {} + ' || encoded_host_status=$? + if [ "$encoded_host_status" -eq 42 ]; then + unset NVIDIA_API_KEY NVIDIA_INFERENCE_API_KEY + printf '%s\n' '[SECURITY] Native NVIDIA inference requires https://integrate.api.nvidia.com/v1.' >&2 + return 1 + fi + if [ "$encoded_host_status" -ne 0 ]; then + return "$encoded_host_status" + fi + fi if is_managed_inference_route; then unset NVIDIA_API_KEY if ! [[ "${NVIDIA_INFERENCE_API_KEY:-}" =~ ^openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$ ]]; then diff --git a/src/lib/inference-credential.ts b/src/lib/inference-credential.ts index 3348d9706e5..00f549b617b 100644 --- a/src/lib/inference-credential.ts +++ b/src/lib/inference-credential.ts @@ -19,5 +19,20 @@ export function managedInferenceApiKey( if (/^https:\/\/integrate\.api\.nvidia\.com(?::(?:0*443)?)?(?:[/?#]|(?![\s\S]))/u.test(route)) { throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); } + if (baseUrl.includes("%")) { + let parsed: URL; + try { + parsed = new URL(baseUrl); + } catch { + return fallback; + } + if ( + parsed.protocol === "https:" && + parsed.hostname === "integrate.api.nvidia.com" && + parsed.port === "" + ) { + throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); + } + } return fallback; } diff --git a/test/fixtures/native-nvidia-inference-urls.ts b/test/fixtures/native-nvidia-inference-urls.ts index af0303ac997..2e2104f5e63 100644 --- a/test/fixtures/native-nvidia-inference-urls.ts +++ b/test/fixtures/native-nvidia-inference-urls.ts @@ -13,6 +13,7 @@ export const INVALID_NATIVE_NVIDIA_URLS = [ "https://integrate.api.nvidia.com/./v1", "https://integrate.api.nvidia.com/x/../v1", "https://integrate.api.nvidia.com/%2e/v1", + "https://%69ntegrate.api.nvidia.com/v1", "https://integrate.api.nvidia.com/V1", "https://integrate.api.nvidia.com//v1", "https://integrate.api.nvidia.com/v1?", From 4d506d01829cc725e84282433180094c12a5cf20 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:49:40 -0700 Subject: [PATCH 02/21] docs(hermes): describe native NVIDIA credential reference Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> (cherry picked from commit c2ff5f31b1ed866a49cee2f91d51d3720c293c13) --- docs/inference/switch-providers.mdx | 4 +++- docs/security/credential-storage.mdx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/inference/switch-providers.mdx b/docs/inference/switch-providers.mdx index 871b2a689b4..e970ee95669 100644 --- a/docs/inference/switch-providers.mdx +++ b/docs/inference/switch-providers.mdx @@ -70,7 +70,9 @@ Run `$$nemoclaw doctor --fix`, then retry the agent turn. -For Hermes, NemoClaw updates the native `/sandbox/.hermes/config.yaml`, including the model, base URL, API-family mode, and OpenShell proxy API-key placeholder. +For Hermes, NemoClaw updates the native `/sandbox/.hermes/config.yaml`, including the model, base URL, API-family mode, and managed API-key value. +`inference.local` uses the OpenShell proxy rewrite sentinel. NVIDIA Build uses `${NVIDIA_INFERENCE_API_KEY}` from a supervisor-issued OpenShell reference. +Neither value is a raw provider credential. The gateway, CLI, TUI, and Web Dashboard all read that shared configuration; a normal runtime route change does not rebuild or restart Hermes. diff --git a/docs/security/credential-storage.mdx b/docs/security/credential-storage.mdx index 6fbf5bdbb83..4def483abe9 100644 --- a/docs/security/credential-storage.mdx +++ b/docs/security/credential-storage.mdx @@ -28,7 +28,9 @@ Those files should contain resolver placeholders, not live provider credentials. For managed tools and messaging, NemoClaw keeps host-side auth in OpenShell providers or host brokers and writes placeholder values into `/sandbox/.hermes/config.yaml`, `/sandbox/.hermes/.env`, and process environment entries visible to the sandbox. Hermes startup rejects raw secret-shaped values in those sandbox-visible surfaces. The managed Hermes wrapper reads that token from `/sandbox/.hermes/.env` and supplies it only through the dashboard process environment. -The shared native inference configuration uses the OpenShell proxy rewrite sentinel instead of raw provider credentials. +For `inference.local`, Hermes stores the OpenShell proxy rewrite sentinel in its native inference configuration. +For NVIDIA Build, Hermes stores `${NVIDIA_INFERENCE_API_KEY}`, which expands from a supervisor-issued OpenShell reference. +Neither value is a raw provider credential. NemoClaw manages Deep Agents Code provider credentials through the same OpenShell provider boundary. From ccd2aa7f7054a186efd34488a11515c867606014 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:32:45 -0700 Subject: [PATCH 03/21] test(e2e): use local baseline for native Hermes switch Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- test/e2e/live/hermes-inference-switch.test.ts | 4 +++- test/e2e/mock-parity.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/live/hermes-inference-switch.test.ts b/test/e2e/live/hermes-inference-switch.test.ts index c017315f0ad..917ac5c35a5 100644 --- a/test/e2e/live/hermes-inference-switch.test.ts +++ b/test/e2e/live/hermes-inference-switch.test.ts @@ -122,7 +122,9 @@ test( // OpenShell reaches this fixture from its gateway network namespace, where // the runner's loopback address is not routable. - const mockBaseline = mockAnthropicSwitchEnabled() + const useMockBaseline = + mockAnthropicSwitchEnabled() || SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER; + const mockBaseline = useMockBaseline ? await startFakeOpenAiCompatibleServer({ apiKey: MOCK_BASELINE_API_KEY, chatContent: "PONG", diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index d0b2034e536..688f2fe3800 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -653,6 +653,7 @@ "test/e2e/live/public-nvidia-switch-provider.ts" ], "fast": [ + "src/lib/actions/inference-set-patch-hermes.test.ts", "src/lib/actions/inference-set-compatible-provider.test.ts", "test/e2e/support/hermes-inference-switch-command-shape.test.ts", "test/e2e/support/public-nvidia-switch-provider.test.ts", From 83776f2eb240f138d2dfc23c5464aed0090a681c Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:54:00 -0700 Subject: [PATCH 04/21] test(e2e): protect native Hermes switch baseline Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .../e2e/live/hermes-inference-switch-helpers.ts | 9 +++++++++ test/e2e/live/hermes-inference-switch.test.ts | 6 ++---- test/e2e/mock-parity.json | 1 - ...ermes-inference-switch-command-shape.test.ts | 17 ++++++++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/test/e2e/live/hermes-inference-switch-helpers.ts b/test/e2e/live/hermes-inference-switch-helpers.ts index 608540e132e..940d3c8b135 100644 --- a/test/e2e/live/hermes-inference-switch-helpers.ts +++ b/test/e2e/live/hermes-inference-switch-helpers.ts @@ -103,6 +103,15 @@ export function mockAnthropicSwitchEnabled(runtimeEnv: NodeJS.ProcessEnv = proce ); } +export function useLocalHermesInferenceBaseline( + runtimeEnv: NodeJS.ProcessEnv = process.env, +): boolean { + return ( + (runtimeEnv.NEMOCLAW_SWITCH_PROVIDER ?? SWITCH_PROVIDER) === PUBLIC_NVIDIA_SWITCH_PROVIDER || + mockAnthropicSwitchEnabled(runtimeEnv) + ); +} + export function expectAuthenticatedBaselineInventoryRequest( baseline: Pick | undefined, ): void { diff --git a/test/e2e/live/hermes-inference-switch.test.ts b/test/e2e/live/hermes-inference-switch.test.ts index 917ac5c35a5..f6574ed86c7 100644 --- a/test/e2e/live/hermes-inference-switch.test.ts +++ b/test/e2e/live/hermes-inference-switch.test.ts @@ -32,7 +32,6 @@ import { installHermes, maybeAssertEnvHashStable, maybeAssertPidStable, - mockAnthropicSwitchEnabled, PROXY_FORBIDDEN_MARKERS, PROXY_RESOLUTION_PROVIDER, parseHermesModelBlock, @@ -49,6 +48,7 @@ import { SWITCH_MODEL, SWITCH_PROVIDER, strictHashPerms, + useLocalHermesInferenceBaseline, } from "./hermes-inference-switch-helpers.ts"; import { PUBLIC_NVIDIA_SWITCH_ATTACHMENT_EVIDENCE, @@ -122,9 +122,7 @@ test( // OpenShell reaches this fixture from its gateway network namespace, where // the runner's loopback address is not routable. - const useMockBaseline = - mockAnthropicSwitchEnabled() || SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER; - const mockBaseline = useMockBaseline + const mockBaseline = useLocalHermesInferenceBaseline() ? await startFakeOpenAiCompatibleServer({ apiKey: MOCK_BASELINE_API_KEY, chatContent: "PONG", diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index 688f2fe3800..d0b2034e536 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -653,7 +653,6 @@ "test/e2e/live/public-nvidia-switch-provider.ts" ], "fast": [ - "src/lib/actions/inference-set-patch-hermes.test.ts", "src/lib/actions/inference-set-compatible-provider.test.ts", "test/e2e/support/hermes-inference-switch-command-shape.test.ts", "test/e2e/support/public-nvidia-switch-provider.test.ts", diff --git a/test/e2e/support/hermes-inference-switch-command-shape.test.ts b/test/e2e/support/hermes-inference-switch-command-shape.test.ts index 621a8ec39fb..f9a8d63a1ff 100644 --- a/test/e2e/support/hermes-inference-switch-command-shape.test.ts +++ b/test/e2e/support/hermes-inference-switch-command-shape.test.ts @@ -23,6 +23,7 @@ import { inferenceLocalMaxTokens, installHermes, mockAnthropicSwitchEnabled, + useLocalHermesInferenceBaseline, openAiSurfaceEndpointUrl, openshellGatewayName, parseInferenceRoute, @@ -296,7 +297,7 @@ describe("Hermes inference switch command shape", () => { ).toThrow(); }); - it("enables local baseline inference only for the mock Anthropic lane", () => { + it("recognizes only the requested mock Anthropic switch", () => { const mockAnthropic = { NEMOCLAW_SWITCH_PROVIDER: "compatible-anthropic-endpoint", NEMOCLAW_SWITCH_INFERENCE_API: "anthropic-messages", @@ -315,6 +316,20 @@ describe("Hermes inference switch command shape", () => { expect(mockAnthropicSwitchEnabled({})).toBe(false); }); + it("uses an authenticated local baseline before native NVIDIA or mock Anthropic switches", () => { + expect(useLocalHermesInferenceBaseline({ NEMOCLAW_SWITCH_PROVIDER: "nvidia-prod" })).toBe(true); + expect( + useLocalHermesInferenceBaseline({ + NEMOCLAW_SWITCH_PROVIDER: "compatible-anthropic-endpoint", + NEMOCLAW_SWITCH_INFERENCE_API: "anthropic-messages", + NEMOCLAW_SWITCH_MOCK_ANTHROPIC: "1", + }), + ).toBe(true); + expect( + useLocalHermesInferenceBaseline({ NEMOCLAW_SWITCH_PROVIDER: "compatible-endpoint" }), + ).toBe(false); + }); + it("does not retry a successful Hermes response from the wrong model", async () => { const probeResult = (stdout: string): ShellProbeResult => ({ exitCode: 0, stdout, stderr: "" }) as ShellProbeResult; From b80617d71564e46a96d110a27c63306d91388121 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:09:24 -0700 Subject: [PATCH 05/21] test(e2e): verify Hermes native credential reference Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .../live/hermes-inference-switch-helpers.ts | 12 ++++-- ...mes-inference-switch-command-shape.test.ts | 42 +++++++++++++++---- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/test/e2e/live/hermes-inference-switch-helpers.ts b/test/e2e/live/hermes-inference-switch-helpers.ts index 940d3c8b135..0207c8e634b 100644 --- a/test/e2e/live/hermes-inference-switch-helpers.ts +++ b/test/e2e/live/hermes-inference-switch-helpers.ts @@ -763,9 +763,15 @@ export function expectedApiMode(): string | undefined { // This live lane runs on ubuntu-latest and intentionally uses GNU grep's // POSIX ERE character classes; support tests pin the accepted scalar shapes. export const API_KEY_SHAPE_PATTERN = `^[[:space:]]*api_key:[[:space:]]*("sk-[^"[:space:]]+"|'sk-[^'[:space:]]+'|sk-[^"'[:space:]]+)[[:space:]]*$`; - -export function apiKeyShapeCommand(): string[] { - return ["grep", "-Eq", API_KEY_SHAPE_PATTERN, "/sandbox/.hermes/config.yaml"]; +const NVIDIA_REFERENCE = "[$][{]NVIDIA_INFERENCE_API_KEY[}]"; +export const NVIDIA_API_KEY_SHAPE_PATTERN = `^[[:space:]]*api_key:[[:space:]]*("${NVIDIA_REFERENCE}"|'${NVIDIA_REFERENCE}'|${NVIDIA_REFERENCE})[[:space:]]*$`; + +export function apiKeyShapeCommand(provider: string = SWITCH_PROVIDER): string[] { + const pattern = + provider === PUBLIC_NVIDIA_SWITCH_PROVIDER + ? NVIDIA_API_KEY_SHAPE_PATTERN + : API_KEY_SHAPE_PATTERN; + return ["grep", "-Eq", pattern, "/sandbox/.hermes/config.yaml"]; } export async function apiKeyShape(sandbox: SandboxClient): Promise { diff --git a/test/e2e/support/hermes-inference-switch-command-shape.test.ts b/test/e2e/support/hermes-inference-switch-command-shape.test.ts index f9a8d63a1ff..511a97c4d3d 100644 --- a/test/e2e/support/hermes-inference-switch-command-shape.test.ts +++ b/test/e2e/support/hermes-inference-switch-command-shape.test.ts @@ -13,6 +13,7 @@ import { DEFAULT_HOSTED_INFERENCE_MODEL } from "../fixtures/hosted-inference.ts" import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; import { API_KEY_SHAPE_PATTERN, + NVIDIA_API_KEY_SHAPE_PATTERN, apiKeyShapeCommand, cleanupHermesSwitch, compatibleAnthropicMetadataArgs, @@ -44,9 +45,9 @@ import { describe("Hermes inference switch command shape", () => { afterEach(() => vi.unstubAllEnvs()); - function matchesApiKeyShape(line: string): boolean { + function matchesApiKeyShape(line: string, pattern: string = API_KEY_SHAPE_PATTERN): boolean { return ( - spawnSync("grep", ["-Eq", API_KEY_SHAPE_PATTERN], { + spawnSync("grep", ["-Eq", pattern], { encoding: "utf8", input: `${line}\n`, }).status === 0 @@ -157,16 +158,25 @@ describe("Hermes inference switch command shape", () => { }); it("uses direct single-line argv for the in-sandbox API-key probe", () => { - const command = apiKeyShapeCommand(); + const command = apiKeyShapeCommand("compatible-anthropic-endpoint"); + const nativeCommand = apiKeyShapeCommand(PUBLIC_NVIDIA_SWITCH_PROVIDER); expect(command).toEqual(["grep", "-Eq", API_KEY_SHAPE_PATTERN, "/sandbox/.hermes/config.yaml"]); - expect(command.every((argument) => !/[\r\n]/u.test(argument))).toBe(true); + expect(nativeCommand).toEqual([ + "grep", + "-Eq", + NVIDIA_API_KEY_SHAPE_PATTERN, + "/sandbox/.hermes/config.yaml", + ]); + expect([...command, ...nativeCommand].every((argument) => !/[\r\n]/u.test(argument))).toBe( + true, + ); }); it("accepts only complete sk-prefixed YAML scalars", () => { expect( - [" api_key: sk-value", ' api_key: "sk-value"', " api_key: 'sk-value'"].every( - matchesApiKeyShape, + [" api_key: sk-value", ' api_key: "sk-value"', " api_key: 'sk-value'"].every((line) => + matchesApiKeyShape(line), ), ).toBe(true); expect( @@ -175,7 +185,25 @@ describe("Hermes inference switch command shape", () => { " api_key: sk-value trailing", ' api_key: "sk-value', ' api_key: sk-value"', - ].some(matchesApiKeyShape), + ].some((line) => matchesApiKeyShape(line)), + ).toBe(false); + }); + + it("accepts only the supervisor-issued reference for native NVIDIA", () => { + const reference = "${NVIDIA_INFERENCE_API_KEY}"; + expect( + [` api_key: ${reference}`, ` api_key: "${reference}"`, ` api_key: '${reference}'`].every( + (line) => matchesApiKeyShape(line, NVIDIA_API_KEY_SHAPE_PATTERN), + ), + ).toBe(true); + expect( + [ + " api_key: sk-OPENSHELL-PROXY-REWRITE", + " api_key: nvapi-raw-key", + ` api_key: ${reference} trailing`, + ` api_key: "${reference}`, + ` api_key: ${reference}"`, + ].some((line) => matchesApiKeyShape(line, NVIDIA_API_KEY_SHAPE_PATTERN)), ).toBe(false); }); From 5ea10df24fd9a8b4190d07857e2f80e93755c47a Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 13:17:14 -0700 Subject: [PATCH 06/21] fix(inference): reject native URLs with user information Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- agents/hermes/managed_policy.py | 1 - scripts/nemoclaw-start.sh | 14 +++++----- src/lib/inference-credential.ts | 26 +++++++++---------- test/fixtures/native-nvidia-inference-urls.ts | 1 + 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/agents/hermes/managed_policy.py b/agents/hermes/managed_policy.py index 0852d9fb2e3..a9bc2d3501a 100644 --- a/agents/hermes/managed_policy.py +++ b/agents/hermes/managed_policy.py @@ -120,7 +120,6 @@ def load_managed_policy(path: Path = MANAGED_POLICY_PATH) -> dict: raise ManagedPolicyError("managed policy model.base_url is invalid") from None if ( not native_nvidia - and "%" in (url.hostname or "") and url.scheme.lower() == "https" and unquote(url.hostname or "").lower() == "integrate.api.nvidia.com" and url.port in (None, 443) diff --git a/scripts/nemoclaw-start.sh b/scripts/nemoclaw-start.sh index 6203a38aa37..ab39d23843a 100755 --- a/scripts/nemoclaw-start.sh +++ b/scripts/nemoclaw-start.sh @@ -74,23 +74,23 @@ clear_managed_inference_credentials() { printf '%s\n' '[SECURITY] Native NVIDIA inference requires https://integrate.api.nvidia.com/v1.' >&2 return 1 fi - if [[ "${NEMOCLAW_INFERENCE_BASE_URL:-}" == *%* ]] && ! is_managed_inference_route; then - # Decode an encoded host in a child without either provider credential. - local encoded_host_status=0 + if ! is_managed_inference_route; then + # Parse noncanonical routes in a child without either provider credential. + local parsed_host_status=0 env -i PATH="$PATH" NEMOCLAW_INFERENCE_BASE_URL="${NEMOCLAW_INFERENCE_BASE_URL:-}" node -e ' try { const url = new URL(process.env.NEMOCLAW_INFERENCE_BASE_URL); if (url.protocol === "https:" && url.hostname === "integrate.api.nvidia.com" && url.port === "") process.exit(42); } catch {} - ' || encoded_host_status=$? - if [ "$encoded_host_status" -eq 42 ]; then + ' || parsed_host_status=$? + if [ "$parsed_host_status" -eq 42 ]; then unset NVIDIA_API_KEY NVIDIA_INFERENCE_API_KEY printf '%s\n' '[SECURITY] Native NVIDIA inference requires https://integrate.api.nvidia.com/v1.' >&2 return 1 fi - if [ "$encoded_host_status" -ne 0 ]; then - return "$encoded_host_status" + if [ "$parsed_host_status" -ne 0 ]; then + return "$parsed_host_status" fi fi if is_managed_inference_route; then diff --git a/src/lib/inference-credential.ts b/src/lib/inference-credential.ts index 00f549b617b..4edb363df6e 100644 --- a/src/lib/inference-credential.ts +++ b/src/lib/inference-credential.ts @@ -19,20 +19,18 @@ export function managedInferenceApiKey( if (/^https:\/\/integrate\.api\.nvidia\.com(?::(?:0*443)?)?(?:[/?#]|(?![\s\S]))/u.test(route)) { throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); } - if (baseUrl.includes("%")) { - let parsed: URL; - try { - parsed = new URL(baseUrl); - } catch { - return fallback; - } - if ( - parsed.protocol === "https:" && - parsed.hostname === "integrate.api.nvidia.com" && - parsed.port === "" - ) { - throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); - } + let parsed: URL; + try { + parsed = new URL(baseUrl); + } catch { + return fallback; + } + if ( + parsed.protocol === "https:" && + parsed.hostname === "integrate.api.nvidia.com" && + parsed.port === "" + ) { + throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); } return fallback; } diff --git a/test/fixtures/native-nvidia-inference-urls.ts b/test/fixtures/native-nvidia-inference-urls.ts index 2e2104f5e63..b40236ffdd6 100644 --- a/test/fixtures/native-nvidia-inference-urls.ts +++ b/test/fixtures/native-nvidia-inference-urls.ts @@ -14,6 +14,7 @@ export const INVALID_NATIVE_NVIDIA_URLS = [ "https://integrate.api.nvidia.com/x/../v1", "https://integrate.api.nvidia.com/%2e/v1", "https://%69ntegrate.api.nvidia.com/v1", + "https://user@integrate.api.nvidia.com/v1", "https://integrate.api.nvidia.com/V1", "https://integrate.api.nvidia.com//v1", "https://integrate.api.nvidia.com/v1?", From 152550f461a72cffaf1c2aca2a919d44d0e89069 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:11:48 -0700 Subject: [PATCH 07/21] fix(inference): reject trailing-dot native host aliases Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- agents/hermes/managed_policy.py | 3 ++- docs/reference/commands.mdx | 12 +++++++++++- scripts/nemoclaw-start.sh | 3 ++- src/lib/inference-credential.ts | 2 +- test/fixtures/native-nvidia-inference-urls.ts | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/agents/hermes/managed_policy.py b/agents/hermes/managed_policy.py index a9bc2d3501a..2d082e02fa4 100644 --- a/agents/hermes/managed_policy.py +++ b/agents/hermes/managed_policy.py @@ -121,7 +121,8 @@ def load_managed_policy(path: Path = MANAGED_POLICY_PATH) -> dict: if ( not native_nvidia and url.scheme.lower() == "https" - and unquote(url.hostname or "").lower() == "integrate.api.nvidia.com" + and unquote(url.hostname or "").lower().removesuffix(".") + == "integrate.api.nvidia.com" and url.port in (None, 443) ): raise ManagedPolicyError( diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index fbf215fa45e..1e2fa366a8c 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3541,7 +3541,17 @@ Switch the active inference provider or model for a NemoClaw-managed OpenClaw sa -Switch the active inference provider or model for a NemoClaw-managed Hermes sandbox. For NVIDIA Endpoints, the command attaches or updates the sandbox's native NVIDIA provider. For other providers, it updates the shared OpenShell gateway route. It then patches the selected running agent config to match the selected inference path, recomputes the config hash, and updates the NemoClaw registry. It is also available in sandbox-first form as `$$nemoclaw inference set --provider --model `. For Hermes, the patch updates the shared native `/sandbox/.hermes/config.yaml` (`model.default`, `model.base_url`, `model.provider: custom`, API-family mode when needed, and the OpenShell proxy API-key placeholder) and does not rebuild or restart the gateway. The gateway, CLI, TUI, and Web Dashboard read that same configuration. Keeping the placeholder preserves dashboard and API authentication after provider switches. Under the `nemohermes` alias, the command uses the registered Hermes sandbox when exactly one exists; otherwise pass `--sandbox ` to target one explicitly. +Switch the active inference provider or model for a NemoClaw-managed Hermes sandbox. +For NVIDIA Endpoints, the command attaches or updates the sandbox's native NVIDIA provider. +For other providers, it updates the shared OpenShell gateway route. +It then patches the selected running agent config to match the selected inference path, recomputes the config hash, and updates the NemoClaw registry. +It is also available in sandbox-first form as `$$nemoclaw inference set --provider --model `. +For Hermes, the patch updates the shared native `/sandbox/.hermes/config.yaml` (`model.default`, `model.base_url`, `model.provider: custom`, API-family mode when needed, and a managed API-key reference) and does not rebuild or restart the gateway. +The `inference.local` route uses the OpenShell proxy rewrite sentinel. +NVIDIA Endpoints uses `${NVIDIA_INFERENCE_API_KEY}`, which OpenShell resolves from a supervisor-issued reference. +Neither value is a raw provider credential. +The gateway, CLI, TUI, and Web Dashboard read the same configuration. +Under the `nemohermes` alias, the command uses the registered Hermes sandbox when exactly one exists; otherwise pass `--sandbox ` to target one explicitly. diff --git a/scripts/nemoclaw-start.sh b/scripts/nemoclaw-start.sh index ab39d23843a..6d51b720b87 100755 --- a/scripts/nemoclaw-start.sh +++ b/scripts/nemoclaw-start.sh @@ -80,7 +80,8 @@ clear_managed_inference_credentials() { env -i PATH="$PATH" NEMOCLAW_INFERENCE_BASE_URL="${NEMOCLAW_INFERENCE_BASE_URL:-}" node -e ' try { const url = new URL(process.env.NEMOCLAW_INFERENCE_BASE_URL); - if (url.protocol === "https:" && url.hostname === "integrate.api.nvidia.com" && + if (url.protocol === "https:" && + url.hostname.replace(/\.$/, "") === "integrate.api.nvidia.com" && url.port === "") process.exit(42); } catch {} ' || parsed_host_status=$? diff --git a/src/lib/inference-credential.ts b/src/lib/inference-credential.ts index 4edb363df6e..707f9823a17 100644 --- a/src/lib/inference-credential.ts +++ b/src/lib/inference-credential.ts @@ -27,7 +27,7 @@ export function managedInferenceApiKey( } if ( parsed.protocol === "https:" && - parsed.hostname === "integrate.api.nvidia.com" && + parsed.hostname.replace(/\.$/u, "") === "integrate.api.nvidia.com" && parsed.port === "" ) { throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); diff --git a/test/fixtures/native-nvidia-inference-urls.ts b/test/fixtures/native-nvidia-inference-urls.ts index b40236ffdd6..f9e6025f139 100644 --- a/test/fixtures/native-nvidia-inference-urls.ts +++ b/test/fixtures/native-nvidia-inference-urls.ts @@ -15,6 +15,7 @@ export const INVALID_NATIVE_NVIDIA_URLS = [ "https://integrate.api.nvidia.com/%2e/v1", "https://%69ntegrate.api.nvidia.com/v1", "https://user@integrate.api.nvidia.com/v1", + "https://integrate.api.nvidia.com./v1", "https://integrate.api.nvidia.com/V1", "https://integrate.api.nvidia.com//v1", "https://integrate.api.nvidia.com/v1?", From d04bbf7e256c7fedb9789f1d6bfa4ca51ff2a614 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:52:46 -0700 Subject: [PATCH 08/21] fix(inference): reject repeated trailing-dot native hosts Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- agents/hermes/managed_policy.py | 2 +- scripts/nemoclaw-start.sh | 2 +- src/lib/inference-credential.ts | 2 +- test/fixtures/native-nvidia-inference-urls.ts | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/agents/hermes/managed_policy.py b/agents/hermes/managed_policy.py index 2d082e02fa4..5bf39578312 100644 --- a/agents/hermes/managed_policy.py +++ b/agents/hermes/managed_policy.py @@ -121,7 +121,7 @@ def load_managed_policy(path: Path = MANAGED_POLICY_PATH) -> dict: if ( not native_nvidia and url.scheme.lower() == "https" - and unquote(url.hostname or "").lower().removesuffix(".") + and unquote(url.hostname or "").lower().rstrip(".") == "integrate.api.nvidia.com" and url.port in (None, 443) ): diff --git a/scripts/nemoclaw-start.sh b/scripts/nemoclaw-start.sh index 6d51b720b87..02b9bfd5d48 100755 --- a/scripts/nemoclaw-start.sh +++ b/scripts/nemoclaw-start.sh @@ -81,7 +81,7 @@ clear_managed_inference_credentials() { try { const url = new URL(process.env.NEMOCLAW_INFERENCE_BASE_URL); if (url.protocol === "https:" && - url.hostname.replace(/\.$/, "") === "integrate.api.nvidia.com" && + url.hostname.replace(/\.+$/, "") === "integrate.api.nvidia.com" && url.port === "") process.exit(42); } catch {} ' || parsed_host_status=$? diff --git a/src/lib/inference-credential.ts b/src/lib/inference-credential.ts index 707f9823a17..df8a327a041 100644 --- a/src/lib/inference-credential.ts +++ b/src/lib/inference-credential.ts @@ -27,7 +27,7 @@ export function managedInferenceApiKey( } if ( parsed.protocol === "https:" && - parsed.hostname.replace(/\.$/u, "") === "integrate.api.nvidia.com" && + parsed.hostname.replace(/\.+$/u, "") === "integrate.api.nvidia.com" && parsed.port === "" ) { throw new Error("Native NVIDIA inference requires https://integrate.api.nvidia.com/v1."); diff --git a/test/fixtures/native-nvidia-inference-urls.ts b/test/fixtures/native-nvidia-inference-urls.ts index f9e6025f139..c20e92b96e1 100644 --- a/test/fixtures/native-nvidia-inference-urls.ts +++ b/test/fixtures/native-nvidia-inference-urls.ts @@ -16,6 +16,7 @@ export const INVALID_NATIVE_NVIDIA_URLS = [ "https://%69ntegrate.api.nvidia.com/v1", "https://user@integrate.api.nvidia.com/v1", "https://integrate.api.nvidia.com./v1", + "https://integrate.api.nvidia.com../v1", "https://integrate.api.nvidia.com/V1", "https://integrate.api.nvidia.com//v1", "https://integrate.api.nvidia.com/v1?", From 7f08e6c77798d35c9adddf1ae1d3ca25082885ec Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:15:36 -0700 Subject: [PATCH 09/21] fix: bind Hermes switch to attached credential handle Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/reference/commands.mdx | 2 +- .../actions/inference-set-hermes-run.test.ts | 53 ++++++++++++++++ .../inference-set-patch-hermes.test.ts | 27 +++++++++ src/lib/actions/inference-set-provider.ts | 60 +++++++++++++++++++ src/lib/actions/inference-set.test-support.ts | 7 +++ src/lib/actions/inference-set.ts | 15 +++++ src/lib/hermes-managed-route.ts | 16 ++++- src/lib/inference/native-nvidia/contract.ts | 6 ++ .../live/hermes-inference-switch-helpers.ts | 3 +- test/e2e/live/hermes-inference-switch.test.ts | 16 +++-- ...mes-inference-switch-command-shape.test.ts | 6 +- 11 files changed, 198 insertions(+), 13 deletions(-) diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 1e2fa366a8c..9c30409c74d 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3548,7 +3548,7 @@ It then patches the selected running agent config to match the selected inferenc It is also available in sandbox-first form as `$$nemoclaw inference set --provider --model `. For Hermes, the patch updates the shared native `/sandbox/.hermes/config.yaml` (`model.default`, `model.base_url`, `model.provider: custom`, API-family mode when needed, and a managed API-key reference) and does not rebuild or restart the gateway. The `inference.local` route uses the OpenShell proxy rewrite sentinel. -NVIDIA Endpoints uses `${NVIDIA_INFERENCE_API_KEY}`, which OpenShell resolves from a supervisor-issued reference. +For a live switch to NVIDIA Endpoints, NemoClaw writes the newly attached provider's OpenShell credential reference into the Hermes config. Neither value is a raw provider credential. The gateway, CLI, TUI, and Web Dashboard read the same configuration. Under the `nemohermes` alias, the command uses the registered Hermes sandbox when exactly one exists; otherwise pass `--sandbox ` to target one explicitly. diff --git a/src/lib/actions/inference-set-hermes-run.test.ts b/src/lib/actions/inference-set-hermes-run.test.ts index 5583bdf7fe8..a4d443aa74b 100644 --- a/src/lib/actions/inference-set-hermes-run.test.ts +++ b/src/lib/actions/inference-set-hermes-run.test.ts @@ -21,6 +21,59 @@ describe("runInferenceSet Hermes routing", () => { portableMocks.assertUnavailable.mockReset(); }); + it("reads the attached native handle before publishing a Hermes switch", async () => { + const config: ConfigObject = { model: { default: "local-model", provider: "custom" } }; + const deps = createDeps({ + config, + entry: { name: "hermes", agent: "hermes", provider: "vllm-local", model: "local-model" }, + defaultSandbox: "hermes", + target: HERMES_TARGET, + session: baseSession({ agent: "hermes", sandboxName: "hermes" }), + }); + await runInferenceSet( + { + provider: "nvidia-prod", + model: "nvidia/test-model", + sandboxName: "hermes", + noVerify: true, + }, + deps, + ); + expect(deps.calls.readNativeNvidiaCredentialHandle).toHaveBeenCalledWith("hermes", "nemoclaw"); + expect(config.model).toMatchObject({ + api_key: "openshell:resolve:env:v1_NVIDIA_INFERENCE_API_KEY", + }); + expect(deps.calls.writeSandboxConfig).toHaveBeenCalledOnce(); + }); + + it("leaves the Hermes config unchanged when the attached handle is unavailable", async () => { + const config: ConfigObject = { model: { default: "local-model", provider: "custom" } }; + const deps = createDeps({ + config, + entry: { name: "hermes", agent: "hermes", provider: "vllm-local", model: "local-model" }, + defaultSandbox: "hermes", + target: HERMES_TARGET, + session: baseSession({ agent: "hermes", sandboxName: "hermes" }), + readNativeNvidiaCredentialHandle: async () => { + throw new Error("provider-bound handle unavailable"); + }, + }); + await expect( + runInferenceSet( + { + provider: "nvidia-prod", + model: "nvidia/test-model", + sandboxName: "hermes", + noVerify: true, + }, + deps, + ), + ).rejects.toThrow("provider-bound handle unavailable"); + expect(config.model).toEqual({ default: "local-model", provider: "custom" }); + expect(deps.calls.writeSandboxConfig).not.toHaveBeenCalled(); + expect(deps.calls.updateSandbox).not.toHaveBeenCalled(); + }); + it("rejects schema-5 before OpenShell or registry mutation (#9203)", async () => { portableMocks.assertUnavailable.mockImplementation(() => { throw new Error("schema-5 rejected"); diff --git a/src/lib/actions/inference-set-patch-hermes.test.ts b/src/lib/actions/inference-set-patch-hermes.test.ts index e9675242d1c..6e253e73ad1 100644 --- a/src/lib/actions/inference-set-patch-hermes.test.ts +++ b/src/lib/actions/inference-set-patch-hermes.test.ts @@ -25,6 +25,33 @@ describe("patchHermesInferenceConfig", () => { }); }); + it("uses the attached provider handle on every Hermes native credential path", () => { + const config: ConfigObject = {}; + const handle = "openshell:resolve:env:v12_NVIDIA_INFERENCE_API_KEY"; + patchHermesInferenceConfig(config, "nvidia-prod", "nvidia/test-model", null, undefined, handle); + expect(config).toMatchObject({ + model: { api_key: handle }, + providers: { "nvidia-prod": { api_key: handle } }, + custom_providers: [{ api_key: handle }], + }); + expect(() => + patchHermesInferenceConfig( + {}, + "nvidia-prod", + "nvidia/test-model", + null, + undefined, + "nvapi-raw", + ), + ).toThrow(/provider-bound credential handle/u); + expect(() => + patchHermesInferenceConfig({}, "nvidia-prod", "nvidia/test-model", null, undefined, ""), + ).toThrow(/provider-bound credential handle/u); + expect(() => + patchHermesInferenceConfig({}, "vllm-local", "local-model", null, undefined, handle), + ).toThrow(/provider-bound credential handle/u); + }); + it("updates the complete Hermes route for the selected provider", () => { const config: ConfigObject = { model: { diff --git a/src/lib/actions/inference-set-provider.ts b/src/lib/actions/inference-set-provider.ts index 361abc59e8f..d11e3d87776 100644 --- a/src/lib/actions/inference-set-provider.ts +++ b/src/lib/actions/inference-set-provider.ts @@ -7,8 +7,14 @@ import type { OpenShellProviderMetadata, } from "../adapters/openshell/provider-adapter"; import { createCliOpenShellProviderAdapter } from "../adapters/openshell/provider-adapter-cli"; +import { captureSanitizedResolvedOpenshellAsync } from "../adapters/openshell/sanitized-capture"; import { namedOpenShellGateway } from "../adapters/openshell/sandbox-observer"; import { retryUntilAsync } from "../core/retry"; +import { + NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN, + NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, + NVIDIA_HOSTED_LOGICAL_PROVIDER, +} from "../inference/native-nvidia/contract"; import { matchesGatewayProviderBinding } from "../onboard/gateway-provider-metadata"; import { assertHermesPortableCommandUnavailable } from "../onboard/experimental/portable-agent-lifecycle"; import { @@ -35,6 +41,60 @@ export function createDefaultInferenceSetProviderAdapter(): OpenShellProviderAda return createCliOpenShellProviderAdapter(); } +export async function readNativeNvidiaCredentialHandle( + sandboxName: string, + gatewayName: string, +): Promise { + const failure = () => + new InferenceSetError( + `OpenShell did not expose a provider-bound NVIDIA credential handle to sandbox '${sandboxName}'. The inference route was not changed.`, + ); + try { + const result = await captureSanitizedResolvedOpenshellAsync( + [ + "sandbox", + "exec", + "--name", + sandboxName, + "-g", + gatewayName, + "--", + "sh", + "-c", + NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, + ], + { + ignoreError: true, + includeStderr: true, + includeStreams: true, + outputLimitBytes: 512, + timeout: 30_000, + }, + ); + const handle = result.stdout?.trim() ?? ""; + if (result.status !== 0 || !NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN.test(handle)) { + throw failure(); + } + return handle; + } catch { + // Never include captured output or an OpenShell diagnostic in this error. + throw failure(); + } +} + +export async function readHermesNativeNvidiaCredentialHandleIfNeeded(options: { + agentName: string; + provider: string; + sandboxName: string; + gatewayName: string; + read: (sandboxName: string, gatewayName: string) => Promise; +}): Promise { + if (options.agentName !== "hermes" || options.provider !== NVIDIA_HOSTED_LOGICAL_PROVIDER) { + return undefined; + } + return await options.read(options.sandboxName, options.gatewayName); +} + export type InferenceSetSandboxRouteProbe = ( input: SandboxInferenceInvocationInput, ) => Promise; diff --git a/src/lib/actions/inference-set.test-support.ts b/src/lib/actions/inference-set.test-support.ts index c93d815c813..8b1a08d4de8 100644 --- a/src/lib/actions/inference-set.test-support.ts +++ b/src/lib/actions/inference-set.test-support.ts @@ -271,6 +271,7 @@ export function createDeps(options: { prepareRunOpenshell?: () => void; rewriteConfigUrlsWithDnsPinning?: (value: ConfigValue) => Promise; resolveCredentialValue?: InferenceSetDeps["resolveCredentialValue"]; + readNativeNvidiaCredentialHandle?: InferenceSetDeps["readNativeNvidiaCredentialHandle"]; ensureHttpsPinRuntimeAdapter?: EnsureHttpsPinRuntimeAdapterFn; revokeHttpsPinRuntimeAdapterRoute?: InferenceSetDeps["revokeHttpsPinRuntimeAdapterRoute"]; probeSandboxRoute?: InferenceSetDeps["probeSandboxRoute"]; @@ -297,6 +298,7 @@ export function createDeps(options: { prepareRunOpenshell: ReturnType; rewriteConfigUrlsWithDnsPinning: ReturnType; resolveCredentialValue: ReturnType; + readNativeNvidiaCredentialHandle: ReturnType; ensureHttpsPinRuntimeAdapter: ReturnType; revokeHttpsPinRuntimeAdapterRoute: ReturnType; probeSandboxRoute: ReturnType; @@ -348,6 +350,10 @@ export function createDeps(options: { options.resolveCredentialValue ?? ((credentialEnv: string) => process.env[credentialEnv] ?? "test-credential-value"), ), + readNativeNvidiaCredentialHandle: vi.fn( + options.readNativeNvidiaCredentialHandle ?? + (async () => "openshell:resolve:env:v1_NVIDIA_INFERENCE_API_KEY"), + ), ensureHttpsPinRuntimeAdapter: vi.fn( options.ensureHttpsPinRuntimeAdapter ?? (async () => ({ @@ -465,6 +471,7 @@ export function createDeps(options: { resolveContextWindowForModel: calls.resolveContextWindowForModel, rewriteConfigUrlsWithDnsPinning: calls.rewriteConfigUrlsWithDnsPinning, resolveCredentialValue: calls.resolveCredentialValue, + readNativeNvidiaCredentialHandle: calls.readNativeNvidiaCredentialHandle, ensureHttpsPinRuntimeAdapter: calls.ensureHttpsPinRuntimeAdapter as unknown as EnsureHttpsPinRuntimeAdapterFn, revokeHttpsPinRuntimeAdapterRoute: diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index 9d8bf430ad3..60c0eee0f01 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -87,6 +87,8 @@ import { probeInferenceSetSandboxRoute, probeInferenceSetSandboxRouteUntilConverged, providerCommitMayHaveChangedBinding, + readHermesNativeNvidiaCredentialHandleIfNeeded, + readNativeNvidiaCredentialHandle, type RuntimeProviderBundleRegistry, RuntimeProviderSelectionError, requireInferenceSetRuntimeAuthority, @@ -209,6 +211,7 @@ export interface InferenceSetDeps extends InferenceGatewayRestartDeps { resolveContextWindowForModel: (provider: string, model: string) => number | null; rewriteConfigUrlsWithDnsPinning: (value: ConfigValue) => Promise; resolveCredentialValue: (credentialEnv: string) => string; + readNativeNvidiaCredentialHandle: (sandboxName: string, gatewayName: string) => Promise; ensureHttpsPinRuntimeAdapter: EnsureHttpsPinRuntimeAdapterFn; revokeHttpsPinRuntimeAdapterRoute: (routeId: string) => Promise; probeSandboxRoute: InferenceSetSandboxRouteProbe; @@ -341,6 +344,7 @@ function defaultDeps(): InferenceSetDeps { resolveContextWindowForModel, rewriteConfigUrlsWithDnsPinning, resolveCredentialValue: (credentialEnv) => process.env[credentialEnv] ?? "", + readNativeNvidiaCredentialHandle, ensureHttpsPinRuntimeAdapter: (options) => { if (!options.discoverAllowedSourceCidrs) { throw new Error("HTTPS Pin Runtime adapter is missing runtime-provider network authority."); @@ -822,6 +826,7 @@ export function patchHermesInferenceConfig( model: string, preferredInferenceApi: string | null = null, contextWindow?: number, + nativeCredentialHandle?: string, ): { changed: boolean; route: SandboxInferenceConfig } { const before = JSON.stringify(config); const route = getSandboxInferenceConfig(model, provider, preferredInferenceApi); @@ -831,6 +836,7 @@ export function patchHermesInferenceConfig( upstreamProvider: provider, inferenceApi: route.inferenceApi, contextWindow, + nativeCredentialHandle, }); return { changed: before !== JSON.stringify(config), route }; @@ -1589,6 +1595,7 @@ async function runInferenceSetWithoutHostLock( null; let assertProviderCurrentBeforeSelection: (() => Promise) | null = null; let nativeNvidiaProviderAttachment: NativeNvidiaProviderAttachment | undefined; + let nativeNvidiaCredentialHandle: string | undefined; let nativeNvidiaAttachmentChanged = false; let nativeNvidiaRegistryCommitted = false; let previousNativeNvidiaDetached = false; @@ -1633,6 +1640,13 @@ async function runInferenceSetWithoutHostLock( }); nativeNvidiaProviderAttachment = nativeNvidiaSelection.attachment; nativeNvidiaAttachmentChanged = nativeNvidiaSelection.attachmentChanged; + nativeNvidiaCredentialHandle = await readHermesNativeNvidiaCredentialHandleIfNeeded({ + agentName, + provider, + sandboxName, + gatewayName: preparedRoute.gatewayName, + read: deps.readNativeNvidiaCredentialHandle, + }); const providerBinding = httpsPinProviderBinding ?? directProviderBinding; if (providerBinding) { providerMutation = await prepareInferenceSetProviderBinding({ @@ -1888,6 +1902,7 @@ async function runInferenceSetWithoutHostLock( model, preferredInferenceApi, contextWindow, + nativeNvidiaCredentialHandle, ); } else { // Recompute the context window for the model being switched to, so it does diff --git a/src/lib/hermes-managed-route.ts b/src/lib/hermes-managed-route.ts index df5553fb94e..e746977289b 100644 --- a/src/lib/hermes-managed-route.ts +++ b/src/lib/hermes-managed-route.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { managedInferenceApiKey, NVIDIA_INFERENCE_PLACEHOLDER } from "./inference-credential.ts"; +import { NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN } from "./inference/native-nvidia/contract.ts"; // The inference.local route replaces this non-secret sentinel at egress. // Native NVIDIA routing instead expands the supervisor-issued environment handle. @@ -9,7 +10,7 @@ export const HERMES_PROXY_REWRITE_SENTINEL = "sk-OPENSHELL-PROXY-REWRITE"; type HermesManagedProvider = { name: string; - api_key: typeof HERMES_PROXY_REWRITE_SENTINEL | typeof NVIDIA_INFERENCE_PLACEHOLDER; + api_key: string; discover_models: true; api?: string; base_url?: string; @@ -28,7 +29,7 @@ export type HermesManagedRouting = { default: string; provider: "custom"; base_url: string; - api_key: typeof HERMES_PROXY_REWRITE_SENTINEL | typeof NVIDIA_INFERENCE_PLACEHOLDER; + api_key: string; api_mode?: string; context_length?: number; }; @@ -42,6 +43,7 @@ export type HermesManagedRoute = { upstreamProvider: string; inferenceApi: string; contextWindow?: number | null; + nativeCredentialHandle?: string; }; function isObjectRecord(value: unknown): value is Record { @@ -81,7 +83,15 @@ export function applyHermesManagedRoute( const providerName = route.upstreamProvider || "nemoclaw-inference"; const providerKey = hermesProviderKey(providerName); const apiMode = hermesApiMode(route.inferenceApi); - const apiKey = managedInferenceApiKey(route.baseUrl, HERMES_PROXY_REWRITE_SENTINEL); + const managedKey = managedInferenceApiKey(route.baseUrl, HERMES_PROXY_REWRITE_SENTINEL); + if ( + route.nativeCredentialHandle !== undefined && + (managedKey !== NVIDIA_INFERENCE_PLACEHOLDER || + !NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN.test(route.nativeCredentialHandle)) + ) { + throw new Error("Hermes native NVIDIA route requires a provider-bound credential handle."); + } + const apiKey = route.nativeCredentialHandle ?? managedKey; const previousUpstream = isObjectRecord(config._nemoclaw_upstream) ? config._nemoclaw_upstream : {}; diff --git a/src/lib/inference/native-nvidia/contract.ts b/src/lib/inference/native-nvidia/contract.ts index 5a9ded0042c..da3079b49f1 100644 --- a/src/lib/inference/native-nvidia/contract.ts +++ b/src/lib/inference/native-nvidia/contract.ts @@ -6,6 +6,12 @@ export const NVIDIA_HOSTED_NATIVE_ENDPOINT = "https://integrate.api.nvidia.com/v export const NVIDIA_HOSTED_NATIVE_PROFILE_ID = "nemoclaw-nvidia-inference-v1"; export const NVIDIA_HOSTED_NATIVE_PROVIDER = "nemoclaw-nvidia-prod-v1"; export const NVIDIA_HOSTED_CREDENTIAL_ENV = "NVIDIA_INFERENCE_API_KEY"; +export const NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN = + /^openshell:resolve:env:(?:v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$/u; + +// Emit only a provider-bound handle. A raw credential can never reach stdout. +export const NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT = + 'printf "%s" "${NVIDIA_INFERENCE_API_KEY:-}" | LC_ALL=C grep -E "^openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$"'; export type NativeNvidiaProviderAttachment = Readonly<{ schemaVersion: 1; diff --git a/test/e2e/live/hermes-inference-switch-helpers.ts b/test/e2e/live/hermes-inference-switch-helpers.ts index 0207c8e634b..732583c1e23 100644 --- a/test/e2e/live/hermes-inference-switch-helpers.ts +++ b/test/e2e/live/hermes-inference-switch-helpers.ts @@ -763,7 +763,8 @@ export function expectedApiMode(): string | undefined { // This live lane runs on ubuntu-latest and intentionally uses GNU grep's // POSIX ERE character classes; support tests pin the accepted scalar shapes. export const API_KEY_SHAPE_PATTERN = `^[[:space:]]*api_key:[[:space:]]*("sk-[^"[:space:]]+"|'sk-[^'[:space:]]+'|sk-[^"'[:space:]]+)[[:space:]]*$`; -const NVIDIA_REFERENCE = "[$][{]NVIDIA_INFERENCE_API_KEY[}]"; +const NVIDIA_REFERENCE = + "openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY"; export const NVIDIA_API_KEY_SHAPE_PATTERN = `^[[:space:]]*api_key:[[:space:]]*("${NVIDIA_REFERENCE}"|'${NVIDIA_REFERENCE}'|${NVIDIA_REFERENCE})[[:space:]]*$`; export function apiKeyShapeCommand(provider: string = SWITCH_PROVIDER): string[] { diff --git a/test/e2e/live/hermes-inference-switch.test.ts b/test/e2e/live/hermes-inference-switch.test.ts index f6574ed86c7..493a657d90d 100644 --- a/test/e2e/live/hermes-inference-switch.test.ts +++ b/test/e2e/live/hermes-inference-switch.test.ts @@ -243,12 +243,16 @@ test( model: SWITCH_MODEL, }); - const config = await sandbox.exec(SANDBOX_NAME, ["cat", "/sandbox/.hermes/config.yaml"], { - artifactName: "hermes-config-yaml", - env: env(), - redactionValues, - timeoutMs: 30_000, - }); + const config = await sandbox.exec( + SANDBOX_NAME, + ["sed", "/^[[:space:]]*api_key:/d", "/sandbox/.hermes/config.yaml"], + { + artifactName: "hermes-config-yaml", + env: env(), + redactionValues, + timeoutMs: 30_000, + }, + ); expect(config.exitCode, resultText(config)).toBe(0); const model = parseHermesModelBlock(config.stdout); expect(model.default).toBe(SWITCH_MODEL); diff --git a/test/e2e/support/hermes-inference-switch-command-shape.test.ts b/test/e2e/support/hermes-inference-switch-command-shape.test.ts index 511a97c4d3d..fa2672a0cd6 100644 --- a/test/e2e/support/hermes-inference-switch-command-shape.test.ts +++ b/test/e2e/support/hermes-inference-switch-command-shape.test.ts @@ -189,8 +189,8 @@ describe("Hermes inference switch command shape", () => { ).toBe(false); }); - it("accepts only the supervisor-issued reference for native NVIDIA", () => { - const reference = "${NVIDIA_INFERENCE_API_KEY}"; + it("accepts only a provider-bound reference for a native NVIDIA switch", () => { + const reference = "openshell:resolve:env:v1_NVIDIA_INFERENCE_API_KEY"; expect( [` api_key: ${reference}`, ` api_key: "${reference}"`, ` api_key: '${reference}'`].every( (line) => matchesApiKeyShape(line, NVIDIA_API_KEY_SHAPE_PATTERN), @@ -200,6 +200,8 @@ describe("Hermes inference switch command shape", () => { [ " api_key: sk-OPENSHELL-PROXY-REWRITE", " api_key: nvapi-raw-key", + " api_key: ${NVIDIA_INFERENCE_API_KEY}", + " api_key: openshell:resolve:env:NVIDIA_INFERENCE_API_KEY", ` api_key: ${reference} trailing`, ` api_key: "${reference}`, ` api_key: ${reference}"`, From 50a453f5474f4b5c85ff922aca47704a5ea3070b Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 06:39:22 -0700 Subject: [PATCH 10/21] fix(hermes): include native NVIDIA contract in image payload Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- agents/hermes/Dockerfile | 2 ++ test/generation/generate-hermes-config.test.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/agents/hermes/Dockerfile b/agents/hermes/Dockerfile index e62358bcb53..7a81083daaa 100644 --- a/agents/hermes/Dockerfile +++ b/agents/hermes/Dockerfile @@ -63,6 +63,7 @@ COPY agents/hermes/managed_policy.py /opt/nemoclaw-hermes-config/managed_policy. COPY agents/hermes/host/managed-tool-gateway-matrix.json /opt/nemoclaw-hermes-config/managed-tool-gateway-matrix.json COPY src/lib/hermes-managed-route.ts /src/lib/hermes-managed-route.ts COPY src/lib/tool-disclosure.ts src/lib/providerless-inference.ts src/lib/inference-credential.ts /src/lib/ +COPY src/lib/inference/native-nvidia/contract.ts /src/lib/inference/native-nvidia/contract.ts COPY src/lib/inference/native-provider/agent-config.ts src/lib/inference/native-provider/hosted.ts src/lib/inference/native-provider/contract.ts /src/lib/inference/native-provider/ COPY src/lib/messaging/ /src/lib/messaging/ COPY scripts/lib/openclaw-npm-remediation.mts /scripts/lib/openclaw-npm-remediation.mts @@ -383,6 +384,7 @@ RUN chmod -R a+rX /opt/nemoclaw-hermes-plugin/ RUN find /opt/nemoclaw-hermes-config -type d -exec chmod 755 {} + \ && find /opt/nemoclaw-hermes-config -type f -exec chmod 444 {} + \ && chmod 444 /src/lib/hermes-managed-route.ts /src/lib/tool-disclosure.ts /src/lib/providerless-inference.ts /src/lib/inference-credential.ts \ + /src/lib/inference/native-nvidia/contract.ts \ && chmod 444 /scripts/lib/reviewed-npm-archive.mts /scripts/lib/bundled-npm-package.mts \ /scripts/lib/openclaw-npm-remediation.mts /scripts/lib/reviewed-npm-audit.mts \ /scripts/lib/reviewed-npm-identity.mts \ diff --git a/test/generation/generate-hermes-config.test.ts b/test/generation/generate-hermes-config.test.ts index f713af35a94..06411f9fde3 100644 --- a/test/generation/generate-hermes-config.test.ts +++ b/test/generation/generate-hermes-config.test.ts @@ -264,6 +264,12 @@ function copyConfigGeneratorFixture(fixtureRoot: string): string { path.join(import.meta.dirname, "../..", "src", "lib", "inference-credential.ts"), path.join(fixtureRoot, "src", "lib", "inference-credential.ts"), ); + const nativeNvidiaConfigDir = path.join("src", "lib", "inference", "native-nvidia"); + fs.mkdirSync(path.join(fixtureRoot, nativeNvidiaConfigDir), { recursive: true }); + fs.copyFileSync( + path.join(import.meta.dirname, "../..", nativeNvidiaConfigDir, "contract.ts"), + path.join(fixtureRoot, nativeNvidiaConfigDir, "contract.ts"), + ); fs.copyFileSync( path.join(import.meta.dirname, "../..", "src", "lib", "providerless-inference.ts"), path.join(fixtureRoot, "src", "lib", "providerless-inference.ts"), From b99b10029964ab1689122b9abe5acaa8df0c19c2 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 06:52:25 -0700 Subject: [PATCH 11/21] fix(hermes): admit native contract to portable build context Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .../onboard/experimental/hermes-portable-build-context-files.ts | 1 + src/lib/onboard/experimental/hermes-portable-build-context.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib/onboard/experimental/hermes-portable-build-context-files.ts b/src/lib/onboard/experimental/hermes-portable-build-context-files.ts index 656b25d6ce2..f04e759209a 100644 --- a/src/lib/onboard/experimental/hermes-portable-build-context-files.ts +++ b/src/lib/onboard/experimental/hermes-portable-build-context-files.ts @@ -145,6 +145,7 @@ export const HERMES_PORTABLE_BUILD_CONTEXT_FILES = [ mode: "100644", }, { path: "src/lib/hermes-managed-route.ts", mode: "100644" }, + { path: "src/lib/inference/native-nvidia/contract.ts", mode: "100644" }, { path: "src/lib/inference/native-provider/agent-config.ts", mode: "100644" }, { path: "src/lib/inference/native-provider/contract.ts", mode: "100644" }, { path: "src/lib/inference/native-provider/hosted.ts", mode: "100644" }, diff --git a/src/lib/onboard/experimental/hermes-portable-build-context.ts b/src/lib/onboard/experimental/hermes-portable-build-context.ts index 20240e4a965..77bc83f67cd 100644 --- a/src/lib/onboard/experimental/hermes-portable-build-context.ts +++ b/src/lib/onboard/experimental/hermes-portable-build-context.ts @@ -88,6 +88,7 @@ const LOCAL_COPY_SOURCES = [ "ci/reviewed-npm-audit.json", "src/lib/actions/sandbox/openshell-child-visible-credentials.v0.0.116.json", "src/lib/hermes-managed-route.ts", + "src/lib/inference/native-nvidia/contract.ts", "src/lib/inference/native-provider/agent-config.ts", "src/lib/inference/native-provider/contract.ts", "src/lib/inference/native-provider/hosted.ts", From 56cd8132243bae6f3f0522e7bec3eeb99806f4cc Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 07:11:15 -0700 Subject: [PATCH 12/21] fix(hermes): keep scoped handle logic out of Pi image inputs Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- agents/hermes/Dockerfile | 2 -- src/lib/actions/inference-set-provider.ts | 4 ++-- src/lib/hermes-managed-route.ts | 8 ++++---- src/lib/inference-credential.ts | 6 ++++++ src/lib/inference/native-nvidia/contract.ts | 6 ------ .../experimental/hermes-portable-build-context-files.ts | 1 - .../onboard/experimental/hermes-portable-build-context.ts | 1 - test/generation/generate-hermes-config.test.ts | 6 ------ 8 files changed, 12 insertions(+), 22 deletions(-) diff --git a/agents/hermes/Dockerfile b/agents/hermes/Dockerfile index 7a81083daaa..e62358bcb53 100644 --- a/agents/hermes/Dockerfile +++ b/agents/hermes/Dockerfile @@ -63,7 +63,6 @@ COPY agents/hermes/managed_policy.py /opt/nemoclaw-hermes-config/managed_policy. COPY agents/hermes/host/managed-tool-gateway-matrix.json /opt/nemoclaw-hermes-config/managed-tool-gateway-matrix.json COPY src/lib/hermes-managed-route.ts /src/lib/hermes-managed-route.ts COPY src/lib/tool-disclosure.ts src/lib/providerless-inference.ts src/lib/inference-credential.ts /src/lib/ -COPY src/lib/inference/native-nvidia/contract.ts /src/lib/inference/native-nvidia/contract.ts COPY src/lib/inference/native-provider/agent-config.ts src/lib/inference/native-provider/hosted.ts src/lib/inference/native-provider/contract.ts /src/lib/inference/native-provider/ COPY src/lib/messaging/ /src/lib/messaging/ COPY scripts/lib/openclaw-npm-remediation.mts /scripts/lib/openclaw-npm-remediation.mts @@ -384,7 +383,6 @@ RUN chmod -R a+rX /opt/nemoclaw-hermes-plugin/ RUN find /opt/nemoclaw-hermes-config -type d -exec chmod 755 {} + \ && find /opt/nemoclaw-hermes-config -type f -exec chmod 444 {} + \ && chmod 444 /src/lib/hermes-managed-route.ts /src/lib/tool-disclosure.ts /src/lib/providerless-inference.ts /src/lib/inference-credential.ts \ - /src/lib/inference/native-nvidia/contract.ts \ && chmod 444 /scripts/lib/reviewed-npm-archive.mts /scripts/lib/bundled-npm-package.mts \ /scripts/lib/openclaw-npm-remediation.mts /scripts/lib/reviewed-npm-audit.mts \ /scripts/lib/reviewed-npm-identity.mts \ diff --git a/src/lib/actions/inference-set-provider.ts b/src/lib/actions/inference-set-provider.ts index 83c86b3f1f4..6897b099de8 100644 --- a/src/lib/actions/inference-set-provider.ts +++ b/src/lib/actions/inference-set-provider.ts @@ -19,8 +19,8 @@ import { retryUntilAsync } from "../core/retry"; import { NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN, NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, - NVIDIA_HOSTED_LOGICAL_PROVIDER, -} from "../inference/native-nvidia/contract"; +} from "../inference-credential"; +import { NVIDIA_HOSTED_LOGICAL_PROVIDER } from "../inference/native-nvidia/contract"; import { matchesGatewayProviderBinding } from "../onboard/gateway-provider-metadata"; import { assertHermesPortableCommandUnavailable } from "../onboard/experimental/portable-agent-lifecycle"; import { diff --git a/src/lib/hermes-managed-route.ts b/src/lib/hermes-managed-route.ts index 8093ded3e94..7544ced2757 100644 --- a/src/lib/hermes-managed-route.ts +++ b/src/lib/hermes-managed-route.ts @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 import { nativeHostedAgentConfig } from "./inference/native-provider/agent-config.ts"; -import { managedInferenceApiKey, NVIDIA_INFERENCE_PLACEHOLDER } from "./inference-credential.ts"; import { NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN, - NVIDIA_HOSTED_LOGICAL_PROVIDER, -} from "./inference/native-nvidia/contract.ts"; + managedInferenceApiKey, + NVIDIA_INFERENCE_PLACEHOLDER, +} from "./inference-credential.ts"; // Shared inference routing replaces this sentinel at egress. Native NVIDIA // routing instead expands the supervisor-issued environment handle. @@ -90,7 +90,7 @@ export function applyHermesManagedRoute( : managedInferenceApiKey(route.baseUrl, HERMES_PROXY_REWRITE_SENTINEL); if (route.nativeCredentialHandle !== undefined) { if ( - route.upstreamProvider !== NVIDIA_HOSTED_LOGICAL_PROVIDER || + route.upstreamProvider !== "nvidia-prod" || apiKey !== NVIDIA_INFERENCE_PLACEHOLDER || !NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN.test(route.nativeCredentialHandle) ) { diff --git a/src/lib/inference-credential.ts b/src/lib/inference-credential.ts index 54dcd1e1239..a176bca11aa 100644 --- a/src/lib/inference-credential.ts +++ b/src/lib/inference-credential.ts @@ -7,6 +7,12 @@ // static resolver alias has no provider identity and is rejected by the // endpoint-bound native provider. export const NVIDIA_INFERENCE_PLACEHOLDER = "${NVIDIA_INFERENCE_API_KEY}"; +export const NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN = + /^openshell:resolve:env:(?:v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$/u; + +// Emit only a provider-bound handle. A raw credential can never reach stdout. +export const NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT = + 'printf "%s" "${NVIDIA_INFERENCE_API_KEY:-}" | LC_ALL=C grep -E "^openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$"'; export function managedInferenceApiKey( baseUrl: string, diff --git a/src/lib/inference/native-nvidia/contract.ts b/src/lib/inference/native-nvidia/contract.ts index da3079b49f1..5a9ded0042c 100644 --- a/src/lib/inference/native-nvidia/contract.ts +++ b/src/lib/inference/native-nvidia/contract.ts @@ -6,12 +6,6 @@ export const NVIDIA_HOSTED_NATIVE_ENDPOINT = "https://integrate.api.nvidia.com/v export const NVIDIA_HOSTED_NATIVE_PROFILE_ID = "nemoclaw-nvidia-inference-v1"; export const NVIDIA_HOSTED_NATIVE_PROVIDER = "nemoclaw-nvidia-prod-v1"; export const NVIDIA_HOSTED_CREDENTIAL_ENV = "NVIDIA_INFERENCE_API_KEY"; -export const NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN = - /^openshell:resolve:env:(?:v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$/u; - -// Emit only a provider-bound handle. A raw credential can never reach stdout. -export const NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT = - 'printf "%s" "${NVIDIA_INFERENCE_API_KEY:-}" | LC_ALL=C grep -E "^openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$"'; export type NativeNvidiaProviderAttachment = Readonly<{ schemaVersion: 1; diff --git a/src/lib/onboard/experimental/hermes-portable-build-context-files.ts b/src/lib/onboard/experimental/hermes-portable-build-context-files.ts index f04e759209a..656b25d6ce2 100644 --- a/src/lib/onboard/experimental/hermes-portable-build-context-files.ts +++ b/src/lib/onboard/experimental/hermes-portable-build-context-files.ts @@ -145,7 +145,6 @@ export const HERMES_PORTABLE_BUILD_CONTEXT_FILES = [ mode: "100644", }, { path: "src/lib/hermes-managed-route.ts", mode: "100644" }, - { path: "src/lib/inference/native-nvidia/contract.ts", mode: "100644" }, { path: "src/lib/inference/native-provider/agent-config.ts", mode: "100644" }, { path: "src/lib/inference/native-provider/contract.ts", mode: "100644" }, { path: "src/lib/inference/native-provider/hosted.ts", mode: "100644" }, diff --git a/src/lib/onboard/experimental/hermes-portable-build-context.ts b/src/lib/onboard/experimental/hermes-portable-build-context.ts index 77bc83f67cd..20240e4a965 100644 --- a/src/lib/onboard/experimental/hermes-portable-build-context.ts +++ b/src/lib/onboard/experimental/hermes-portable-build-context.ts @@ -88,7 +88,6 @@ const LOCAL_COPY_SOURCES = [ "ci/reviewed-npm-audit.json", "src/lib/actions/sandbox/openshell-child-visible-credentials.v0.0.116.json", "src/lib/hermes-managed-route.ts", - "src/lib/inference/native-nvidia/contract.ts", "src/lib/inference/native-provider/agent-config.ts", "src/lib/inference/native-provider/contract.ts", "src/lib/inference/native-provider/hosted.ts", diff --git a/test/generation/generate-hermes-config.test.ts b/test/generation/generate-hermes-config.test.ts index 06411f9fde3..f713af35a94 100644 --- a/test/generation/generate-hermes-config.test.ts +++ b/test/generation/generate-hermes-config.test.ts @@ -264,12 +264,6 @@ function copyConfigGeneratorFixture(fixtureRoot: string): string { path.join(import.meta.dirname, "../..", "src", "lib", "inference-credential.ts"), path.join(fixtureRoot, "src", "lib", "inference-credential.ts"), ); - const nativeNvidiaConfigDir = path.join("src", "lib", "inference", "native-nvidia"); - fs.mkdirSync(path.join(fixtureRoot, nativeNvidiaConfigDir), { recursive: true }); - fs.copyFileSync( - path.join(import.meta.dirname, "../..", nativeNvidiaConfigDir, "contract.ts"), - path.join(fixtureRoot, nativeNvidiaConfigDir, "contract.ts"), - ); fs.copyFileSync( path.join(import.meta.dirname, "../..", "src", "lib", "providerless-inference.ts"), path.join(fixtureRoot, "src", "lib", "providerless-inference.ts"), From 2e3e85f3c49093b90f6c88e865349860b2e9a9f0 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 07:42:04 -0700 Subject: [PATCH 13/21] test(hermes): expect scoped credential after inference switch Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- test/generation/providerless-agent-config.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/generation/providerless-agent-config.test.ts b/test/generation/providerless-agent-config.test.ts index ca9e7ebc2fa..baf1206bceb 100644 --- a/test/generation/providerless-agent-config.test.ts +++ b/test/generation/providerless-agent-config.test.ts @@ -148,6 +148,14 @@ const expectConfigured: Record void> = { expect(config.model.api_key).toBe("${NVIDIA_INFERENCE_API_KEY}"); }, }; +const expectManagedConfigured: Record void> = { + openclaw: expectConfigured.openclaw, + hermes(config) { + expect(config.model.default).toBe("fixture/model"); + expect(config.model.provider).toBe("custom"); + expect(config.model.api_key).toBe("openshell:resolve:env:v1_NVIDIA_INFERENCE_API_KEY"); + }, +}; type InferenceSetCalls = ReturnType["calls"]; const expectCommitted: Record void> = { openclaw(calls) { @@ -256,7 +264,7 @@ describe.each(["openclaw", "hermes"])("providerless %s configuration", (a deps, ); expect(result.inSandboxConfigSynced).toBe(true); - expectConfigured[agent](config); + expectManagedConfigured[agent](config); expectCommitted[agent](deps.calls); expect( deps.calls.captureOpenshell.mock.calls.some( From acf2e70988a7cf28ba22f5a202b04516f8630328 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 08:36:31 -0700 Subject: [PATCH 14/21] docs(hermes): distinguish generated and switched credential references Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/inference/switch-providers.mdx | 6 ++++-- docs/security/credential-storage.mdx | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/inference/switch-providers.mdx b/docs/inference/switch-providers.mdx index cb1cb471e80..5620268606a 100644 --- a/docs/inference/switch-providers.mdx +++ b/docs/inference/switch-providers.mdx @@ -71,8 +71,10 @@ Run `$$nemoclaw doctor --fix`, then retry the agent turn. For Hermes, NemoClaw updates the native `/sandbox/.hermes/config.yaml`, including the model, base URL, API-family mode, and managed API-key value. -`inference.local` uses the OpenShell proxy rewrite sentinel. NVIDIA Build uses `${NVIDIA_INFERENCE_API_KEY}` from a supervisor-issued OpenShell reference. -Neither value is a raw provider credential. +`inference.local` uses the OpenShell proxy rewrite sentinel. +Generated NVIDIA Build configuration uses `${NVIDIA_INFERENCE_API_KEY}` for supervisor expansion. +A live switch to NVIDIA Build writes the newly attached provider's scoped OpenShell credential reference. +These values do not expose the raw provider credential. The gateway, CLI, TUI, and Web Dashboard all read that shared configuration; a normal runtime route change does not rebuild or restart Hermes. diff --git a/docs/security/credential-storage.mdx b/docs/security/credential-storage.mdx index 4def483abe9..4d242c6979f 100644 --- a/docs/security/credential-storage.mdx +++ b/docs/security/credential-storage.mdx @@ -29,8 +29,9 @@ For managed tools and messaging, NemoClaw keeps host-side auth in OpenShell prov Hermes startup rejects raw secret-shaped values in those sandbox-visible surfaces. The managed Hermes wrapper reads that token from `/sandbox/.hermes/.env` and supplies it only through the dashboard process environment. For `inference.local`, Hermes stores the OpenShell proxy rewrite sentinel in its native inference configuration. -For NVIDIA Build, Hermes stores `${NVIDIA_INFERENCE_API_KEY}`, which expands from a supervisor-issued OpenShell reference. -Neither value is a raw provider credential. +Generated NVIDIA Build configuration uses `${NVIDIA_INFERENCE_API_KEY}` for supervisor expansion. +A live switch to NVIDIA Build writes the newly attached provider's scoped OpenShell credential reference into the native configuration. +These values do not expose the raw provider credential. NemoClaw manages Deep Agents Code provider credentials through the same OpenShell provider boundary. From f1d5db623fc5569724670af7bc6b9a4ad8044f3c Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 09:11:17 -0700 Subject: [PATCH 15/21] fix: accept scoped Hermes NVIDIA credential handles --- agents/hermes/managed_policy.py | 14 ++++- .../actions/inference-set-provider.test.ts | 61 +++++++++++++++++++ .../hermes/hermes-managed-policy.test.ts | 30 +++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/agents/hermes/managed_policy.py b/agents/hermes/managed_policy.py index fd53eb592c1..2aa3ac14277 100644 --- a/agents/hermes/managed_policy.py +++ b/agents/hermes/managed_policy.py @@ -16,6 +16,9 @@ MANAGED_POLICY_SCHEMA_VERSION = 3 HERMES_PROXY_REWRITE_SENTINEL = "sk-OPENSHELL-PROXY-REWRITE" NVIDIA_INFERENCE_PLACEHOLDER = "${NVIDIA_INFERENCE_API_KEY}" +NVIDIA_SCOPED_CREDENTIAL_HANDLE = re.compile( + r"openshell:resolve:env:(?:v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY" +) class ManagedPolicyError(Exception): @@ -175,7 +178,16 @@ def load_managed_policy(path: Path = MANAGED_POLICY_PATH) -> dict: expected_key = NVIDIA_INFERENCE_PLACEHOLDER if native_nvidia else HERMES_PROXY_REWRITE_SENTINEL api_key = policy_value(config, "model.api_key") hosted_placeholder = None if native_nvidia else _native_hosted_placeholder(config, base_url) - if api_key != expected_key and (hosted_placeholder is None or api_key != hosted_placeholder): + scoped_nvidia_handle = ( + native_nvidia + and isinstance(api_key, str) + and NVIDIA_SCOPED_CREDENTIAL_HANDLE.fullmatch(api_key) is not None + ) + if ( + api_key != expected_key + and (hosted_placeholder is None or api_key != hosted_placeholder) + and not scoped_nvidia_handle + ): raise ManagedPolicyError( "managed policy model.api_key must use an OpenShell credential placeholder or proxy rewrite sentinel " "matching its route" diff --git a/src/lib/actions/inference-set-provider.test.ts b/src/lib/actions/inference-set-provider.test.ts index adb9d91f9ea..bb96d70b739 100644 --- a/src/lib/actions/inference-set-provider.test.ts +++ b/src/lib/actions/inference-set-provider.test.ts @@ -6,15 +6,76 @@ import type { OpenShellProviderAdapter, OpenShellProviderMetadata, } from "../adapters/openshell/provider-adapter"; +import { captureSanitizedResolvedOpenshellAsync } from "../adapters/openshell/sanitized-capture"; +import { NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT } from "../inference-credential"; import { assertInferenceSetProviderOwnership, prepareInferenceSetProviderBinding, + readNativeNvidiaCredentialHandle, } from "./inference-set-provider"; import type { HttpsPinProviderBinding } from "./inference-set-route-containment"; +vi.mock("../adapters/openshell/sanitized-capture", async (importOriginal) => ({ + ...(await importOriginal()), + captureSanitizedResolvedOpenshellAsync: vi.fn(), +})); + const PROVIDER_ID = "11111111-2222-4333-8444-555555555555"; const TARGET = { kind: "named", gatewayName: "nemoclaw" } as const; +describe("native NVIDIA credential handle boundary", () => { + it.each([ + "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", + `openshell:resolve:env:s${"a".repeat(64)}_NVIDIA_INFERENCE_API_KEY`, + ])("reads only the scoped handle %s from a sanitized sandbox exec", async (handle) => { + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + capture.mockResolvedValueOnce({ status: 0, output: handle, stdout: handle, stderr: "" }); + + await expect(readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a")).resolves.toBe( + handle, + ); + expect(capture).toHaveBeenCalledExactlyOnceWith( + [ + "sandbox", + "exec", + "--name", + "hermes-sandbox", + "-g", + "gateway-a", + "--", + "sh", + "-c", + NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, + ], + { + ignoreError: true, + includeStderr: true, + includeStreams: true, + outputLimitBytes: 512, + timeout: 30_000, + }, + ); + capture.mockClear(); + }); + + it.each([ + [1, "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", ""], + [0, "sk-raw-secret", ""], + [0, "openshell:resolve:env:NVIDIA_INFERENCE_API_KEY", ""], + [0, "openshell:resolve:env:v7_OPENAI_API_KEY", ""], + [0, "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY extra", ""], + [0, "", "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY"], + ])("rejects invalid capture status %s and stdout %s", async (status, stdout, stderr) => { + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + capture.mockResolvedValueOnce({ status, output: `${stdout}${stderr}`, stdout, stderr }); + + await expect(readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a")).rejects.toThrow( + "OpenShell did not expose a provider-bound NVIDIA credential handle", + ); + capture.mockClear(); + }); +}); + function binding(overrides: Partial = {}): HttpsPinProviderBinding { return { baseUrl: "http://host.openshell.internal:11438/route/route-a/v1", diff --git a/test/agents/hermes/hermes-managed-policy.test.ts b/test/agents/hermes/hermes-managed-policy.test.ts index ada60983568..7483a3b7c79 100644 --- a/test/agents/hermes/hermes-managed-policy.test.ts +++ b/test/agents/hermes/hermes-managed-policy.test.ts @@ -174,6 +174,36 @@ describe("Hermes managed policy", () => { }, ); + it.each([ + "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", + `openshell:resolve:env:s${"a".repeat(64)}_NVIDIA_INFERENCE_API_KEY`, + ])("accepts a provider-bound native NVIDIA credential handle %s", (apiKey) => { + const policy = buildHermesManagedPolicy( + { ...SETTINGS, baseUrl: NATIVE_NVIDIA_URLS[0], upstreamProvider: "nvidia-prod" }, + {}, + ); + policy.config.model!.api_key = apiKey; + const result = loadWithPython(policy); + expect(result.status, result.stderr).toBe(0); + }); + + it.each([ + "openshell:resolve:env:NVIDIA_INFERENCE_API_KEY", + "openshell:resolve:env:v7_OPENAI_API_KEY", + "openshell:resolve:env:v123456789012345678901_NVIDIA_INFERENCE_API_KEY", + `openshell:resolve:env:s${"A".repeat(64)}_NVIDIA_INFERENCE_API_KEY`, + "sk-raw-policy-credential", + ])("rejects an invalid native NVIDIA credential handle %s", (apiKey) => { + const policy = buildHermesManagedPolicy( + { ...SETTINGS, baseUrl: NATIVE_NVIDIA_URLS[0], upstreamProvider: "nvidia-prod" }, + {}, + ); + policy.config.model!.api_key = apiKey; + const result = loadWithPython(policy); + expect(result.status).toBe(1); + expect(result.stderr).not.toContain(apiKey); + }); + it.each(INVALID_NATIVE_NVIDIA_URLS)( "rejects ambiguous native NVIDIA routing at %j", (baseUrl) => { From 2996b1214440d77cee2b7cf13aeebb19aa344b1e Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 10:52:12 -0700 Subject: [PATCH 16/21] fix(inference): parse framed Hermes credential handles --- .../actions/inference-set-provider.test.ts | 57 ++++++++++++++++++- src/lib/actions/inference-set-provider.ts | 16 +++++- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/lib/actions/inference-set-provider.test.ts b/src/lib/actions/inference-set-provider.test.ts index bb96d70b739..ef42256fe28 100644 --- a/src/lib/actions/inference-set-provider.test.ts +++ b/src/lib/actions/inference-set-provider.test.ts @@ -7,6 +7,7 @@ import type { OpenShellProviderMetadata, } from "../adapters/openshell/provider-adapter"; import { captureSanitizedResolvedOpenshellAsync } from "../adapters/openshell/sanitized-capture"; +import { SANDBOX_EXEC_STARTED_MARKER } from "../adapters/sandbox/sandbox-exec-output"; import { NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT } from "../inference-credential"; import { assertInferenceSetProviderOwnership, @@ -23,13 +24,24 @@ vi.mock("../adapters/openshell/sanitized-capture", async (importOriginal) => ({ const PROVIDER_ID = "11111111-2222-4333-8444-555555555555"; const TARGET = { kind: "named", gatewayName: "nemoclaw" } as const; +function markerFromCommand(args: string[]): string { + const marker = args + .at(-1) + ?.match(new RegExp(`${SANDBOX_EXEC_STARTED_MARKER}_[0-9a-f]{32}`, "u"))?.[0]; + expect(marker).toBeDefined(); + return marker ?? ""; +} + describe("native NVIDIA credential handle boundary", () => { it.each([ "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", `openshell:resolve:env:s${"a".repeat(64)}_NVIDIA_INFERENCE_API_KEY`, ])("reads only the scoped handle %s from a sanitized sandbox exec", async (handle) => { const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); - capture.mockResolvedValueOnce({ status: 0, output: handle, stdout: handle, stderr: "" }); + capture.mockImplementationOnce(async (args) => { + const stdout = `${markerFromCommand(args)}\n${handle}\n`; + return { status: 0, output: stdout, stdout, stderr: "" }; + }); await expect(readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a")).resolves.toBe( handle, @@ -45,7 +57,7 @@ describe("native NVIDIA credential handle boundary", () => { "--", "sh", "-c", - NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, + expect.stringContaining(NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT), ], { ignoreError: true, @@ -58,6 +70,28 @@ describe("native NVIDIA credential handle boundary", () => { capture.mockClear(); }); + it.each(["stdout", "stderr"])( + "reads a framed scoped handle from the %s stream", + async (stream) => { + const handle = "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY"; + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + capture.mockImplementationOnce(async (args) => { + const framed = `stdout: ${markerFromCommand(args)}\nstdout: ${handle}\n`; + return { + status: 0, + output: framed, + stdout: stream === "stdout" ? framed : "OpenShell preamble\n", + stderr: stream === "stderr" ? framed : "", + }; + }); + + await expect(readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a")).resolves.toBe( + handle, + ); + capture.mockClear(); + }, + ); + it.each([ [1, "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", ""], [0, "sk-raw-secret", ""], @@ -67,7 +101,24 @@ describe("native NVIDIA credential handle boundary", () => { [0, "", "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY"], ])("rejects invalid capture status %s and stdout %s", async (status, stdout, stderr) => { const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); - capture.mockResolvedValueOnce({ status, output: `${stdout}${stderr}`, stdout, stderr }); + capture.mockImplementationOnce(async (args) => { + const markedStdout = `${markerFromCommand(args)}\n${stdout}`; + return { status, output: `${markedStdout}${stderr}`, stdout: markedStdout, stderr }; + }); + + await expect(readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a")).rejects.toThrow( + "OpenShell did not expose a provider-bound NVIDIA credential handle", + ); + capture.mockClear(); + }); + + it("rejects duplicate marker boundaries even when one contains a valid handle", async () => { + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + capture.mockImplementationOnce(async (args) => { + const marker = markerFromCommand(args); + const stdout = `${marker}\nopenshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY\n`; + return { status: 0, output: stdout, stdout, stderr: `stdout: ${marker}\n` }; + }); await expect(readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a")).rejects.toThrow( "OpenShell did not expose a provider-bound NVIDIA credential handle", diff --git a/src/lib/actions/inference-set-provider.ts b/src/lib/actions/inference-set-provider.ts index 6897b099de8..792d573299e 100644 --- a/src/lib/actions/inference-set-provider.ts +++ b/src/lib/actions/inference-set-provider.ts @@ -14,6 +14,11 @@ import type { } from "../adapters/openshell/provider-adapter"; import { createCliOpenShellProviderAdapter } from "../adapters/openshell/provider-adapter-cli"; import { captureSanitizedResolvedOpenshellAsync } from "../adapters/openshell/sanitized-capture"; +import { + buildSandboxExecMarkedCommand, + createSandboxExecMarker, + extractSandboxExecCommandStdoutFromStreams, +} from "../adapters/sandbox/sandbox-exec-output"; import { namedOpenShellGateway } from "../adapters/openshell/sandbox-observer"; import { retryUntilAsync } from "../core/retry"; import { @@ -56,6 +61,7 @@ export async function readNativeNvidiaCredentialHandle( `OpenShell did not expose a provider-bound NVIDIA credential handle to sandbox '${sandboxName}'. The inference route was not changed.`, ); try { + const marker = createSandboxExecMarker(); const result = await captureSanitizedResolvedOpenshellAsync( [ "sandbox", @@ -67,7 +73,7 @@ export async function readNativeNvidiaCredentialHandle( "--", "sh", "-c", - NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, + buildSandboxExecMarkedCommand(NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, marker), ], { ignoreError: true, @@ -77,8 +83,12 @@ export async function readNativeNvidiaCredentialHandle( timeout: 30_000, }, ); - const handle = result.stdout?.trim() ?? ""; - if (result.status !== 0 || !NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN.test(handle)) { + const handle = extractSandboxExecCommandStdoutFromStreams(result, marker); + if ( + result.status !== 0 || + handle === null || + !NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN.test(handle) + ) { throw failure(); } return handle; From 696221c1c31b7f14641ff53160d599071bf07da5 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:34:11 -0700 Subject: [PATCH 17/21] fix: wait for Hermes native provider handle injection --- .../actions/inference-set-provider.test.ts | 81 +++++++++++++++++++ src/lib/actions/inference-set-provider.ts | 62 +++++++++----- src/lib/inference-credential.ts | 2 +- 3 files changed, 123 insertions(+), 22 deletions(-) diff --git a/src/lib/actions/inference-set-provider.test.ts b/src/lib/actions/inference-set-provider.test.ts index ef42256fe28..a1000c0c5c1 100644 --- a/src/lib/actions/inference-set-provider.test.ts +++ b/src/lib/actions/inference-set-provider.test.ts @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import { spawnSync } from "node:child_process"; import { describe, expect, it, vi } from "vitest"; import type { OpenShellProviderAdapter, @@ -33,6 +34,24 @@ function markerFromCommand(args: string[]): string { } describe("native NVIDIA credential handle boundary", () => { + it("emits a fixed pending signal without printing a missing or raw credential", () => { + const missing = spawnSync("sh", ["-c", NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT], { + encoding: "utf8", + env: { NVIDIA_INFERENCE_API_KEY: "" }, + }); + expect(missing.status).toBe(75); + expect(missing.stdout).toBe(""); + expect(missing.stderr).toBe("NEMOCLAW_NATIVE_PROVIDER_HANDLE_PENDING\n"); + + const raw = spawnSync("sh", ["-c", NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT], { + encoding: "utf8", + env: { NVIDIA_INFERENCE_API_KEY: "raw-test-secret" }, + }); + expect(raw.status).toBe(1); + expect(raw.stdout).toBe(""); + expect(raw.stderr).toBe(""); + }); + it.each([ "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", `openshell:resolve:env:s${"a".repeat(64)}_NVIDIA_INFERENCE_API_KEY`, @@ -92,6 +111,68 @@ describe("native NVIDIA credential handle boundary", () => { }, ); + it("waits for a newly attached provider handle only when OpenShell reports it pending", async () => { + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + const sleep = vi.fn(async () => undefined); + const handle = "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY"; + capture.mockImplementationOnce(async (args) => ({ + status: 75, + output: "", + stdout: `${markerFromCommand(args)}\n`, + stderr: "NEMOCLAW_NATIVE_PROVIDER_HANDLE_PENDING\n", + })); + capture.mockImplementationOnce(async (args) => { + const stdout = `${markerFromCommand(args)}\n${handle}\n`; + return { status: 0, output: stdout, stdout, stderr: "" }; + }); + + await expect( + readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a", { sleep }), + ).resolves.toBe(handle); + expect(sleep).toHaveBeenCalledExactlyOnceWith(2_000); + expect(capture).toHaveBeenCalledTimes(2); + expect(markerFromCommand(capture.mock.calls[0]?.[0] ?? [])).not.toBe( + markerFromCommand(capture.mock.calls[1]?.[0] ?? []), + ); + capture.mockClear(); + }); + + it("stops after ten explicitly pending read-only probes", async () => { + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + const sleep = vi.fn(async () => undefined); + capture.mockImplementation(async (args) => ({ + status: 75, + output: "", + stdout: `${markerFromCommand(args)}\n`, + stderr: "NEMOCLAW_NATIVE_PROVIDER_HANDLE_PENDING\n", + })); + + await expect( + readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a", { sleep }), + ).rejects.toThrow("OpenShell did not expose a provider-bound NVIDIA credential handle"); + expect(capture).toHaveBeenCalledTimes(10); + expect(sleep).toHaveBeenCalledTimes(9); + capture.mockReset(); + }); + + it("does not retry a non-pending credential probe failure", async () => { + const capture = vi.mocked(captureSanitizedResolvedOpenshellAsync); + const sleep = vi.fn(async () => undefined); + capture.mockImplementationOnce(async (args) => ({ + status: 75, + output: "", + stdout: `${markerFromCommand(args)}\n`, + stderr: "unrelated execution failure", + })); + + await expect( + readNativeNvidiaCredentialHandle("hermes-sandbox", "gateway-a", { sleep }), + ).rejects.toThrow("OpenShell did not expose a provider-bound NVIDIA credential handle"); + expect(capture).toHaveBeenCalledOnce(); + expect(sleep).not.toHaveBeenCalled(); + capture.mockClear(); + }); + it.each([ [1, "openshell:resolve:env:v7_NVIDIA_INFERENCE_API_KEY", ""], [0, "sk-raw-secret", ""], diff --git a/src/lib/actions/inference-set-provider.ts b/src/lib/actions/inference-set-provider.ts index 792d573299e..895b2668c46 100644 --- a/src/lib/actions/inference-set-provider.ts +++ b/src/lib/actions/inference-set-provider.ts @@ -55,37 +55,57 @@ export function createDefaultInferenceSetProviderAdapter(): OpenShellProviderAda export async function readNativeNvidiaCredentialHandle( sandboxName: string, gatewayName: string, + deps: { sleep: (milliseconds: number) => Promise } = { + sleep: sleepInferenceSetRouteConvergence, + }, ): Promise { const failure = () => new InferenceSetError( `OpenShell did not expose a provider-bound NVIDIA credential handle to sandbox '${sandboxName}'. The inference route was not changed.`, ); try { - const marker = createSandboxExecMarker(); - const result = await captureSanitizedResolvedOpenshellAsync( - [ - "sandbox", - "exec", - "--name", - sandboxName, - "-g", - gatewayName, - "--", - "sh", - "-c", - buildSandboxExecMarkedCommand(NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, marker), - ], + // OpenShell can confirm an attachment before a fresh exec receives its + // environment. This is a read-only probe, so retry only its explicit + // pending signal; never retry invalid handles or ambiguous exec failures. + const result = await retryUntilAsync( + async () => { + const marker = createSandboxExecMarker(); + const capture = await captureSanitizedResolvedOpenshellAsync( + [ + "sandbox", + "exec", + "--name", + sandboxName, + "-g", + gatewayName, + "--", + "sh", + "-c", + buildSandboxExecMarkedCommand(NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT, marker), + ], + { + ignoreError: true, + includeStderr: true, + includeStreams: true, + outputLimitBytes: 512, + timeout: 30_000, + }, + ); + return { capture, marker }; + }, { - ignoreError: true, - includeStderr: true, - includeStreams: true, - outputLimitBytes: 512, - timeout: 30_000, + accept: ({ capture }) => + capture.error !== undefined || + Boolean(capture.signal) || + capture.status !== 75 || + !String(capture.stderr ?? "").includes("NEMOCLAW_NATIVE_PROVIDER_HANDLE_PENDING"), + retryDelaysMs: Array(9).fill(2_000), + sleep: deps.sleep, }, ); - const handle = extractSandboxExecCommandStdoutFromStreams(result, marker); + const handle = extractSandboxExecCommandStdoutFromStreams(result.capture, result.marker); if ( - result.status !== 0 || + result.capture.status !== 0 || handle === null || !NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN.test(handle) ) { diff --git a/src/lib/inference-credential.ts b/src/lib/inference-credential.ts index a176bca11aa..5a641dce6ca 100644 --- a/src/lib/inference-credential.ts +++ b/src/lib/inference-credential.ts @@ -12,7 +12,7 @@ export const NATIVE_NVIDIA_SCOPED_HANDLE_PATTERN = // Emit only a provider-bound handle. A raw credential can never reach stdout. export const NATIVE_NVIDIA_SCOPED_HANDLE_READ_SCRIPT = - 'printf "%s" "${NVIDIA_INFERENCE_API_KEY:-}" | LC_ALL=C grep -E "^openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$"'; + 'if [ -z "${NVIDIA_INFERENCE_API_KEY:-}" ]; then printf "%s\\n" NEMOCLAW_NATIVE_PROVIDER_HANDLE_PENDING >&2; exit 75; fi; printf "%s" "$NVIDIA_INFERENCE_API_KEY" | LC_ALL=C grep -E "^openshell:resolve:env:(v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$"'; export function managedInferenceApiKey( baseUrl: string, From 4e88f84dff5b734bb783971d66f140e71ecff692 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:12:01 -0700 Subject: [PATCH 18/21] docs: explain Hermes native switch gateway restart --- docs/inference/switch-providers.mdx | 5 ++++- docs/reference/commands.mdx | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/inference/switch-providers.mdx b/docs/inference/switch-providers.mdx index 5620268606a..f071f987f96 100644 --- a/docs/inference/switch-providers.mdx +++ b/docs/inference/switch-providers.mdx @@ -75,7 +75,10 @@ For Hermes, NemoClaw updates the native `/sandbox/.hermes/config.yaml`, includin Generated NVIDIA Build configuration uses `${NVIDIA_INFERENCE_API_KEY}` for supervisor expansion. A live switch to NVIDIA Build writes the newly attached provider's scoped OpenShell credential reference. These values do not expose the raw provider credential. -The gateway, CLI, TUI, and Web Dashboard all read that shared configuration; a normal runtime route change does not rebuild or restart Hermes. +The gateway, CLI, TUI, and Web Dashboard all read that shared configuration. +Changes between shared routes do not rebuild or restart Hermes. +A switch to or from a native hosted provider restarts the Hermes gateway after configuration sync, including a live NVIDIA Build switch. +Active agent requests can be interrupted during the restart. diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 778eb207c70..8079e281152 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3614,7 +3614,13 @@ Switch the active inference provider or model for a NemoClaw-managed OpenClaw sa -Switch the active inference provider or model for a NemoClaw-managed Hermes sandbox. For NVIDIA Endpoints, OpenAI, Anthropic, Gemini, OpenRouter, and Hermes Provider, the command attaches or updates the selected sandbox's native provider. Custom endpoints and local providers retain their existing shared OpenShell route. It then patches the shared native `/sandbox/.hermes/config.yaml`, recomputes the config hash, and updates the NemoClaw registry without rebuilding or restarting the gateway. +Switch the active inference provider or model for a NemoClaw-managed Hermes sandbox. +For NVIDIA Endpoints, OpenAI, Anthropic, Gemini, OpenRouter, and Hermes Provider, the command attaches or updates the selected sandbox's native provider. +Custom endpoints and local providers retain their existing shared OpenShell route. +It then patches the shared native `/sandbox/.hermes/config.yaml`, recomputes the config hash, and updates the NemoClaw registry. +Changes between shared routes do not rebuild or restart Hermes. +A switch to or from a native hosted provider restarts the Hermes gateway after configuration sync, including a live NVIDIA Endpoints switch. +Active agent requests can be interrupted during the restart. Shared routes use the OpenShell proxy API-key placeholder. On a live NVIDIA Endpoints switch, NemoClaw writes the newly attached provider's scoped OpenShell credential reference into the Hermes config. Other native hosted providers use their managed credential placeholders. None of these values is a raw provider credential. The gateway, CLI, TUI, and Web Dashboard read the same configuration. From 2729417e0a3198f75bb655bc1a35a337964e53ad Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:49:54 -0700 Subject: [PATCH 19/21] docs: document Hermes gateway restart recovery --- docs/inference/switch-providers.mdx | 1 + docs/reference/commands.mdx | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/inference/switch-providers.mdx b/docs/inference/switch-providers.mdx index f071f987f96..c0809662722 100644 --- a/docs/inference/switch-providers.mdx +++ b/docs/inference/switch-providers.mdx @@ -79,6 +79,7 @@ The gateway, CLI, TUI, and Web Dashboard all read that shared configuration. Changes between shared routes do not rebuild or restart Hermes. A switch to or from a native hosted provider restarts the Hermes gateway after configuration sync, including a live NVIDIA Build switch. Active agent requests can be interrupted during the restart. +If the restart fails, the route and configuration remain committed. Run `$$nemoclaw gateway restart` to apply the switch. diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 8079e281152..31920b6cef7 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3621,6 +3621,7 @@ It then patches the shared native `/sandbox/.hermes/config.yaml`, recomputes the Changes between shared routes do not rebuild or restart Hermes. A switch to or from a native hosted provider restarts the Hermes gateway after configuration sync, including a live NVIDIA Endpoints switch. Active agent requests can be interrupted during the restart. +If the restart fails, the route and configuration remain committed. Run `$$nemoclaw gateway restart` to apply the switch. Shared routes use the OpenShell proxy API-key placeholder. On a live NVIDIA Endpoints switch, NemoClaw writes the newly attached provider's scoped OpenShell credential reference into the Hermes config. Other native hosted providers use their managed credential placeholders. None of these values is a raw provider credential. The gateway, CLI, TUI, and Web Dashboard read the same configuration. From 4aeead9381e379f73fd57e2846fc041af2262de4 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 14:48:52 -0700 Subject: [PATCH 20/21] test: verify Hermes native attachment rollback --- .../actions/inference-set-hermes-run.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib/actions/inference-set-hermes-run.test.ts b/src/lib/actions/inference-set-hermes-run.test.ts index 47574f2c1db..858ebe9ea9d 100644 --- a/src/lib/actions/inference-set-hermes-run.test.ts +++ b/src/lib/actions/inference-set-hermes-run.test.ts @@ -12,6 +12,7 @@ vi.mock("../onboard/experimental/portable-agent-lifecycle", async (importOrigina assertHermesPortableCommandUnavailable: portableMocks.assertUnavailable, })); import { HERMES_PROXY_REWRITE_SENTINEL } from "../hermes-managed-route"; +import { NVIDIA_HOSTED_NATIVE_PROVIDER } from "../inference/native-nvidia/contract"; import type { ConfigObject } from "../security/credential-filter"; import { runInferenceSet } from "./inference-set"; import { baseSession, createDeps, HERMES_TARGET } from "../../../test/helpers/inference-set"; @@ -58,6 +59,8 @@ describe("runInferenceSet Hermes routing", () => { throw new Error("provider-bound handle unavailable"); }, }); + const attachProvider = vi.spyOn(deps.providerAdapter, "attachProvider"); + const detachProvider = vi.spyOn(deps.providerAdapter, "detachProvider"); await expect( runInferenceSet( { @@ -72,6 +75,24 @@ describe("runInferenceSet Hermes routing", () => { expect(config.model).toEqual({ default: "local-model", provider: "custom" }); expect(deps.calls.writeSandboxConfig).not.toHaveBeenCalled(); expect(deps.calls.updateSandbox).not.toHaveBeenCalled(); + expect(attachProvider).toHaveBeenCalledWith( + expect.objectContaining({ + sandboxName: "hermes", + providerName: NVIDIA_HOSTED_NATIVE_PROVIDER, + }), + ); + expect(detachProvider).toHaveBeenCalledWith( + expect.objectContaining({ + sandboxName: "hermes", + providerName: NVIDIA_HOSTED_NATIVE_PROVIDER, + }), + ); + await expect( + deps.providerAdapter.listProviderAttachments({ + target: { kind: "named", gatewayName: "nemoclaw" }, + sandboxName: "hermes", + }), + ).resolves.toEqual({ ok: true, value: { names: [] } }); }); it("rejects schema-5 before OpenShell or registry mutation (#9203)", async () => { From e92ddf1bc3cc2c586db6bf91a363b58bc2c5d0f5 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 13 Oct 2026 15:54:16 -0700 Subject: [PATCH 21/21] test: expect native Hermes switch to clear endpoint metadata --- test/e2e/live/hermes-inference-switch.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/e2e/live/hermes-inference-switch.test.ts b/test/e2e/live/hermes-inference-switch.test.ts index 51b0e82d436..c29fd70be77 100644 --- a/test/e2e/live/hermes-inference-switch.test.ts +++ b/test/e2e/live/hermes-inference-switch.test.ts @@ -193,7 +193,6 @@ test( }); const baselineState = registryState(); const baselineSession = structuredClone(baselineState.session); - const baselineRegistry = structuredClone(baselineState.registry.sandboxes?.[SANDBOX_NAME]); const switchBinding = await prepareCompatibleAnthropicSwitchBinding(host, cleanup); const switchEndpointUrl = switchBinding?.endpointUrl ?? null; switchBinding && redactionValues.push(switchBinding.credentialValue); @@ -351,12 +350,12 @@ test( expect(state.session).toEqual(baselineSession); const publicSwitch = SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER; const durableEndpointUrl = publicSwitch - ? baselineRegistry?.endpointUrl + ? null : (switchEndpointUrl ?? process.env.NEMOCLAW_ENDPOINT_URL ?? DEFAULT_HOSTED_INFERENCE_BASE_URL); const durableCredentialEnv = publicSwitch - ? baselineRegistry?.credentialEnv + ? null : switchEndpointUrl ? "COMPATIBLE_ANTHROPIC_API_KEY" : "COMPATIBLE_API_KEY"; @@ -365,7 +364,7 @@ test( ); expect(state.registry.sandboxes?.[SANDBOX_NAME]?.credentialEnv).toBe(durableCredentialEnv); expect(state.registry.sandboxes?.[SANDBOX_NAME]?.preferredInferenceApi).toBe( - publicSwitch ? baselineRegistry?.preferredInferenceApi : RUNTIME_SWITCH_API, + publicSwitch ? null : RUNTIME_SWITCH_API, ); expect(state.registry.sandboxes?.[SANDBOX_NAME]?.nimContainer).toBeNull(); progress.phase("exercise sandbox inference and Hermes API");