diff --git a/ci/platform-matrix.json b/ci/platform-matrix.json index cc84f687305..43e548bb33e 100644 --- a/ci/platform-matrix.json +++ b/ci/platform-matrix.json @@ -208,7 +208,7 @@ { "name": "Managed inference", "status": "tested", - "notes": "Provider-routed model calls through OpenShell, transparent to the agent. NVIDIA Endpoints and supported fixed hosted providers use native endpoints through sandbox-attached OpenShell providers. New Deep Agents Code selections of Ollama, standalone vLLM, llama.cpp, and qualifying local compatible endpoints use sandbox-attached providers for their qualified host-local endpoints. Hermes implements the same attachment path, with live qualification for its new local lifecycle pending. OpenClaw, Pi, owned Local NVIDIA NIM, and other custom or local selections retain the shared `inference.local` route. OpenShell keeps provider credentials outside the sandbox. Supports every entry in the Providers table." + "notes": "Provider-routed model calls through OpenShell, transparent to the agent. NVIDIA Endpoints and supported fixed hosted providers use native endpoints through sandbox-attached OpenShell providers. New Deep Agents Code selections of Ollama, standalone vLLM, llama.cpp, and qualifying local compatible endpoints use sandbox-attached providers for their qualified host-local endpoints. Hermes implements the same attachment path, with live qualification for its new local lifecycle pending. New OpenClaw selections of Ollama, standalone vLLM, and llama.cpp also use sandbox-attached providers, and their `status`, `connect`, and `start` health checks send requests to the recorded provider endpoint. Earlier OpenClaw sandboxes without a sandbox-attached provider, Pi, owned Local NVIDIA NIM, and other custom or local selections retain the shared `inference.local` route. OpenShell keeps provider credentials outside the sandbox. Supports every entry in the Providers table." }, { "name": "Declarative network policy", diff --git a/docs/get-started/quickstart.mdx b/docs/get-started/quickstart.mdx index 03d8b724438..3b98b3e215d 100644 --- a/docs/get-started/quickstart.mdx +++ b/docs/get-started/quickstart.mdx @@ -382,7 +382,8 @@ Use these details when your first-run path needs more control. After confirmation, NemoClaw registers the selected provider with OpenShell. NVIDIA Endpoints and supported fixed hosted providers use native endpoints through sandbox-attached OpenShell providers. - Custom and local providers retain the shared `inference.local` route. + New Ollama, standalone vLLM, and llama.cpp selections also use sandbox-attached providers for their host-local endpoints. + Local NVIDIA NIM, custom endpoints, and earlier local selections without a sandbox-attached provider retain the shared `inference.local` route. The wizard asks whether to enable web search and offers Brave Search or Tavily Search. Provide `BRAVE_API_KEY` for Brave Search or `TAVILY_API_KEY` for Tavily Search when prompted. NemoClaw validates the selected key before it creates the sandbox, registers a sandbox-scoped OpenShell provider, and writes only an OpenShell resolver placeholder into the OpenClaw configuration. diff --git a/docs/reference/platform-support.mdx b/docs/reference/platform-support.mdx index 43fef04e495..434c76ff542 100644 --- a/docs/reference/platform-support.mdx +++ b/docs/reference/platform-support.mdx @@ -135,7 +135,7 @@ Each row below is a launch-facing capability claim that NemoClaw makes in docs, |------------|--------|-------| | Guided onboarding | Tested | Single-command interactive wizard (`$$nemoclaw onboard`) that walks the user through inference provider selection, credential setup, and sandbox creation or update. It opens the agent dashboard when the selected runtime provides one. Non-interactive mode is supported with `--non-interactive` and `NEMOCLAW_*` environment variables for CI and scripted installs. | | Sandboxed execution | Tested with limitations | Landlock, seccomp, network namespace isolation, no-new-privileges, privilege dropping, and process limits (nproc 512 at `scripts/lib/sandbox-rlimits.sh:8`) are tested and on by default. OpenShell owns capability enforcement for managed entrypoints, exec processes, and connect shells; those paths do not call NemoClaw capability handling. Direct container runtimes that explicitly override the image user to root retain the existing compatibility drop and required `setpriv` transition. Direct container launches must configure capabilities at the container runtime. | -| Managed inference | Tested | Provider-routed model calls through OpenShell, transparent to the agent. NVIDIA Endpoints and supported fixed hosted providers use native endpoints through sandbox-attached OpenShell providers. New Deep Agents Code selections of Ollama, standalone vLLM, llama.cpp, and qualifying local compatible endpoints use sandbox-attached providers for their qualified host-local endpoints. Hermes implements the same attachment path, with live qualification for its new local lifecycle pending. OpenClaw, Pi, owned Local NVIDIA NIM, and other custom or local selections retain the shared `inference.local` route. OpenShell keeps provider credentials outside the sandbox. Supports every entry in the Providers table. | +| Managed inference | Tested | Provider-routed model calls through OpenShell, transparent to the agent. NVIDIA Endpoints and supported fixed hosted providers use native endpoints through sandbox-attached OpenShell providers. New Deep Agents Code selections of Ollama, standalone vLLM, llama.cpp, and qualifying local compatible endpoints use sandbox-attached providers for their qualified host-local endpoints. Hermes implements the same attachment path, with live qualification for its new local lifecycle pending. New OpenClaw selections of Ollama, standalone vLLM, and llama.cpp also use sandbox-attached providers, and their `status`, `connect`, and `start` health checks send requests to the recorded provider endpoint. Earlier OpenClaw sandboxes without a sandbox-attached provider, Pi, owned Local NVIDIA NIM, and other custom or local selections retain the shared `inference.local` route. OpenShell keeps provider credentials outside the sandbox. Supports every entry in the Providers table. | | Declarative network policy | Tested | YAML-defined egress with policy presets. Presets include `slack`, `discord`, `telegram`, `weather`, `openclaw-pricing`, `huggingface`, `npm`, `pypi`, `brew`, and others. Hot-reloadable at runtime with `$$nemoclaw policy add`. | | State persistence and rebuild transfer | Tested | OpenShell preserves the native agent home during routine lifecycle operations. Before destructive replacement, NemoClaw archives and integrity-checks the complete native home/workspace, then restores it into the replacement sandbox. | | Agent skills | Tested | Packaged agent skills are discoverable by Cursor, Claude Code, and other coding assistants under `.agents/skills/`. Skills also install into the sandbox with `$$nemoclaw skill install`. | diff --git a/src/lib/actions/sandbox/inference-invocation-probe.test.ts b/src/lib/actions/sandbox/inference-invocation-probe.test.ts index d4b028e5e50..b2a5f35fd23 100644 --- a/src/lib/actions/sandbox/inference-invocation-probe.test.ts +++ b/src/lib/actions/sandbox/inference-invocation-probe.test.ts @@ -27,6 +27,11 @@ import { READINESS_INFERENCE_INVOCATION_TIMEOUT_MS, type SandboxInferenceInvocationInput, } from "./inference-invocation-probe"; +import { + NATIVE_LOCAL_CREDENTIAL_HANDLE, + recordingProbeShell, +} from "../../../../test/helpers/native-local-probe-shell"; +import { nativeLocalTestReceipt } from "../../../../test/helpers/inference-set"; const input = { sandboxName: "dcode-workspace", @@ -977,3 +982,108 @@ it.each([true, undefined])( ).toEqual({ ok: true }); }, ); + +describe("OpenClaw native local probe routing (#13338)", () => { + const PROVIDERS = [ + ["vllm-local", "http://host.openshell.internal:18000/v1"], + ["llama-cpp-local", "http://host.openshell.internal:8081/v1"], + ["ollama-local", "http://host.openshell.internal:11435/v1"], + ] as const; + const okBody = '{"choices":[{"message":{"content":"OK"}}]}'; + + function openClawInput( + provider: (typeof PROVIDERS)[number][0], + endpointUrl: string, + agentName: string | null | undefined, + agent: "openclaw" | null = "openclaw", + ): SandboxInferenceInvocationInput { + return { + sandboxName: "alpha", + gatewayName: "nemoclaw", + ...(agentName === undefined ? {} : { agentName }), + provider, + model: "local-model", + preferredInferenceApi: "openai-completions", + nativeLocalProviderAttachment: nativeLocalTestReceipt( + provider, + endpointUrl, + agent ? { agent } : {}, + ), + }; + } + + it.each( + PROVIDERS.flatMap(([provider, endpointUrl]) => + [undefined, null, "openclaw"].map((agentName) => ({ provider, endpointUrl, agentName })), + ), + )( + "sends $provider to the recorded endpoint when agentName is $agentName", + async ({ provider, endpointUrl, agentName }) => { + const selected = openClawInput(provider, endpointUrl, agentName); + const shell = recordingProbeShell("200", okBody); + await expect( + probeSandboxInferenceInvocation(selected, { execute: shell.execute }), + ).resolves.toEqual({ ok: true }); + expect(shell.destinations()).toEqual([`${endpointUrl}/chat/completions`]); + expect(shell.requests[0]).toContain( + `Authorization: Bearer ${NATIVE_LOCAL_CREDENTIAL_HANDLE}`, + ); + expect(shell.requests[0].join("\n")).not.toContain("inference.local"); + }, + ); + + it("reports the endpoint that actually failed", async () => { + const [provider, endpointUrl] = PROVIDERS[0]; + const shell = recordingProbeShell("503"); + const result = await probeSandboxInferenceInvocation( + openClawInput(provider, endpointUrl, null), + { + execute: shell.execute, + }, + ); + expect(result).toMatchObject({ ok: false, httpStatus: 503 }); + assert(!result.ok); + expect(result.endpoint).toBe(shell.destinations()[0]); + expect(result.endpoint).toBe(`${endpointUrl}/chat/completions`); + }); + + it("refuses a raw credential before calling curl", async () => { + const [provider, endpointUrl] = PROVIDERS[2]; + const shell = recordingProbeShell("200", okBody, { + NEMOCLAW_LOCAL_INFERENCE_TOKEN: "raw-local-secret", + }); + const result = await probeSandboxInferenceInvocation( + openClawInput(provider, endpointUrl, null), + { + execute: shell.execute, + }, + ); + expect(result.ok).toBe(false); + expect(shell.requests).toEqual([]); + }); + + it.each([ + ["ollama-local", undefined], + ["ollama-local", "openclaw"], + ["vllm-local", "openclaw"], + ] as const)( + "keeps a %s selection without native authority (agent %s) on the shared route", + async (provider, agentName) => { + const shell = recordingProbeShell("200", okBody, {}); + await expect( + probeSandboxInferenceInvocation( + { + sandboxName: "alpha", + ...(agentName ? { agentName } : {}), + provider, + model: "local-model", + preferredInferenceApi: "openai-completions", + }, + { execute: shell.execute }, + ), + ).resolves.toEqual({ ok: true }); + expect(shell.destinations()).toEqual(["https://inference.local/v1/chat/completions"]); + expect(shell.requests[0].join("\n")).not.toContain("Authorization"); + }, + ); +}); diff --git a/src/lib/actions/sandbox/inference-invocation-probe.ts b/src/lib/actions/sandbox/inference-invocation-probe.ts index 3577a75280b..60d5031707b 100644 --- a/src/lib/actions/sandbox/inference-invocation-probe.ts +++ b/src/lib/actions/sandbox/inference-invocation-probe.ts @@ -145,7 +145,8 @@ function buildProbeRequest(input: SandboxInferenceInvocationInput): { ? nativeHosted.endpoint : isNativeNvidiaProvider(input.provider) || hosted ? "https://inference.local/v1" - : config.inferenceBaseUrl + : // A native local attachment is the route, whichever agent the caller names. + (local?.endpointUrl ?? config.inferenceBaseUrl) ).replace(/\/+$/u, ""); // Gemini's existing OpenAI-compatible API ends in /v1beta/openai, not /v1. const apiBaseUrl = diff --git a/src/lib/actions/sandbox/inference-route-health.ts b/src/lib/actions/sandbox/inference-route-health.ts index d9fe85ddecf..21ac8025a76 100644 --- a/src/lib/actions/sandbox/inference-route-health.ts +++ b/src/lib/actions/sandbox/inference-route-health.ts @@ -438,7 +438,9 @@ export function buildSandboxInferenceRouteHealth( ok: invocation?.ok === true, probed: invocation !== null, providerLabel: "Native local inference", - endpoint: `${context.nativeLocalEndpoint}/chat/completions`, + endpoint: + (invocation?.ok === false && invocation.endpoint) || + `${context.nativeLocalEndpoint}/chat/completions`, detail: invocation?.ok ? "The attached provider served a native local inference request." : invocation diff --git a/src/lib/actions/sandbox/launch-readiness-gateway-health.test.ts b/src/lib/actions/sandbox/launch-readiness-gateway-health.test.ts index fcd20301d5f..3425592de11 100644 --- a/src/lib/actions/sandbox/launch-readiness-gateway-health.test.ts +++ b/src/lib/actions/sandbox/launch-readiness-gateway-health.test.ts @@ -16,6 +16,13 @@ import { requireNativeInferenceHealth, type LaunchReadinessHealthDeps, } from "./launch-readiness/health"; +import { probeSandboxInferenceInvocation } from "./inference-invocation-probe"; +import { runSandboxInferenceInvocationProbe } from "./inference-route-health"; +import { + NATIVE_LOCAL_CREDENTIAL_HANDLE, + recordingProbeShell, +} from "../../../../test/helpers/native-local-probe-shell"; +import { nativeLocalTestReceipt } from "../../../../test/helpers/inference-set"; import { isSandboxGatewayRunningForStatus, waitForStartedHermesGatewayProcess, @@ -448,3 +455,51 @@ describe("Hermes native-local readiness authority", () => { ); }); }); + +describe("OpenClaw native-local readiness identity (#13338)", () => { + it.each([ + { agentName: undefined, agent: "openclaw" }, + { agentName: undefined, agent: undefined }, + { agentName: "openclaw", agent: "openclaw" }, + ])( + "sends the health request to the recorded endpoint (selected $agentName, recorded $agent)", + async ({ agentName, agent }) => { + const receipt = nativeLocalTestReceipt( + "llama-cpp-local", + "http://host.openshell.internal:8081/v1", + { + agent: "openclaw", + gatewayName: "selected", + }, + ); + const shell = recordingProbeShell("200", '{"choices":[{"message":{"content":"OK"}}]}'); + await expect( + requireNativeInferenceHealth({ + sandboxName: "alpha", + gatewayName: "selected", + ...(agentName ? { agentName } : {}), + entry: { + name: "alpha", + ...(agent ? { agent } : {}), + provider: "llama-cpp-local", + model: "local-model", + nativeLocalProviderAttachment: receipt, + }, + deps: { + verifyNativeLocalAttachment: vi.fn(async () => {}), + inferenceInvocationProbe: (input) => + runSandboxInferenceInvocationProbe(input, (selected, _deps, timeoutMs) => + probeSandboxInferenceInvocation(selected, { execute: shell.execute }, timeoutMs), + ), + }, + }), + ).resolves.toBe(true); + expect(shell.destinations()).toEqual([ + "http://host.openshell.internal:8081/v1/chat/completions", + ]); + expect(shell.requests[0]).toContain( + `Authorization: Bearer ${NATIVE_LOCAL_CREDENTIAL_HANDLE}`, + ); + }, + ); +}); diff --git a/src/lib/actions/sandbox/status-snapshot-inference-health.test.ts b/src/lib/actions/sandbox/status-snapshot-inference-health.test.ts index b00f917e64e..bc75e1b0608 100644 --- a/src/lib/actions/sandbox/status-snapshot-inference-health.test.ts +++ b/src/lib/actions/sandbox/status-snapshot-inference-health.test.ts @@ -9,6 +9,9 @@ import type { SandboxEntry } from "../../state/registry"; import type { SandboxInferenceInvocationResult } from "./inference-invocation-probe"; import type { SandboxInferenceRouteHealth } from "./inference-route-health"; import { collectSandboxStatusSnapshot } from "./status-snapshot"; +import { probeSandboxInferenceInvocation } from "./inference-invocation-probe"; +import { recordingProbeShell } from "../../../../test/helpers/native-local-probe-shell"; +import { nativeLocalTestReceipt } from "../../../../test/helpers/inference-set"; // Direct, unmocked coverage of `buildSandboxInferenceRouteHealth` through the // exported `collectSandboxStatusSnapshot` entry point (it is not itself @@ -1158,3 +1161,51 @@ describe("collectSandboxStatusSnapshot inference route health", () => { expect(snapshot.inferenceHealth).toMatchObject({ ok: false, failureLabel: "unhealthy" }); }); }); + +describe("status native local request identity (#13338)", () => { + it.each(["openclaw", undefined] as const)( + "probes and reports the recorded OpenClaw endpoint when the registry agent is %s", + async (agent) => { + const receipt = nativeLocalTestReceipt( + "vllm-local", + "http://host.openshell.internal:18000/v1", + { + agent: "openclaw", + authMode: "sentinel", + }, + ); + const options = snapshotDeps( + null, + null, + { ok: true }, + { + agent, + provider: "vllm-local", + model: "local-model", + gatewayName: "nemoclaw", + nativeLocalProviderAttachment: receipt, + }, + ); + const shell = recordingProbeShell("503"); + const snapshot = await collectSandboxStatusSnapshot("alpha", { + ...options, + deps: { + ...options.deps, + inferenceRouteObserver: { observeInferenceRoute: vi.fn() }, + verifyNativeLocalProviderAttachmentImpl: async () => undefined, + probeSandboxInferenceInvocationImpl: (input, _deps, timeoutMs) => + probeSandboxInferenceInvocation(input, { execute: shell.execute }, timeoutMs), + delayInferenceRecoveryProbe: async () => undefined, + }, + }); + expect(shell.destinations().length).toBeGreaterThan(0); + expect(new Set(shell.destinations())).toEqual( + new Set(["http://host.openshell.internal:18000/v1/chat/completions"]), + ); + expect(snapshot.inferenceHealth).toMatchObject({ + ok: false, + endpoint: shell.destinations()[0], + }); + }, + ); +}); diff --git a/test/e2e/fixtures/native-local-chat.ts b/test/e2e/fixtures/native-local-chat.ts new file mode 100644 index 00000000000..0fd7183e2b3 --- /dev/null +++ b/test/e2e/fixtures/native-local-chat.ts @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { NATIVE_LOCAL_AUTH_HEADER_SCRIPT } from "../../../src/lib/inference/native-local/agent-config.ts"; +import { shellQuote } from "./clients/command.ts"; + +/** + * Sandbox shell command for a chat request to a sandbox-owned native local provider (#13293). + * The auth script accepts only the credential handle that OpenShell issues, so the raw local + * credential never enters the request. The endpoint and body are shell-quoted, so request data + * stays one curl argument. + */ +export function nativeLocalChatCommand( + endpointUrl: string, + body: string, + curlFlags: "-fsS" | "-sS", +): string { + return `${NATIVE_LOCAL_AUTH_HEADER_SCRIPT}; curl ${curlFlags} --max-time 120 ${shellQuote(`${endpointUrl}/chat/completions`)} -H "$AUTH_HEADER" -H 'Content-Type: application/json' --data ${shellQuote(body)}`; +} diff --git a/test/e2e/live/gpu-double-onboard.test.ts b/test/e2e/live/gpu-double-onboard.test.ts index 03777ab4a0e..786ee92beea 100644 --- a/test/e2e/live/gpu-double-onboard.test.ts +++ b/test/e2e/live/gpu-double-onboard.test.ts @@ -4,6 +4,8 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; +import { normalizeNativeLocalProviderAttachment } from "../../../src/lib/inference/native-local/contract.ts"; +import { getSandbox } from "../../../src/lib/state/registry.ts"; import { containsAnswer } from "../../helpers/e2e-answer-assertions.ts"; import { execTimeout, testTimeout } from "../../helpers/timeouts.ts"; import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; @@ -15,6 +17,7 @@ import { resultText } from "../fixtures/clients/command.ts"; import { type HostCliClient } from "../fixtures/clients/host.ts"; import { type SandboxClient, validateSandboxName } from "../fixtures/clients/sandbox.ts"; import { expect, test } from "../fixtures/e2e-test.ts"; +import { nativeLocalChatCommand } from "../fixtures/native-local-chat.ts"; import { CLI_ENTRYPOINT, REPO_ROOT } from "../fixtures/paths.ts"; import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; @@ -140,12 +143,18 @@ async function expectSandboxInference42( model: string, artifactName: string, ): Promise { + // OpenClaw local inference uses a sandbox-owned provider behind the auth proxy, not the shared + // gateway route (#13293). Re-read it after re-onboarding recreates the sandbox. A missing + // attachment yields an unresolvable host, which fails the request assertion below. + const endpoint = + normalizeNativeLocalProviderAttachment(getSandbox(SANDBOX_NAME)?.nativeLocalProviderAttachment) + ?.endpointUrl ?? "http://missing-native-local-attachment.invalid/v1"; const response = await sandbox.exec( SANDBOX_NAME, [ "sh", "-lc", - `curl -fsS --max-time 120 https://inference.local/v1/chat/completions -H 'Content-Type: application/json' --data '${chatRequest(model)}' | ${parseReplyCommand()}`, + `${nativeLocalChatCommand(endpoint, chatRequest(model), "-fsS")} | ${parseReplyCommand()}`, ], { artifactName, @@ -192,7 +201,7 @@ test( "the persisted Ollama auth-proxy token works after first onboard", "nemoclaw onboard --non-interactive --yes recreates the sandbox", "the running proxy accepts the persisted token after re-onboard and rejects unauthenticated/wrong-token requests", - "sandbox inference.local reaches Ollama after re-onboard", + "the sandbox-owned native provider reaches Ollama after first onboard and re-onboard", ], }); diff --git a/test/e2e/live/gpu-e2e.test.ts b/test/e2e/live/gpu-e2e.test.ts index 0c0b895599d..e81a15feedd 100644 --- a/test/e2e/live/gpu-e2e.test.ts +++ b/test/e2e/live/gpu-e2e.test.ts @@ -7,14 +7,17 @@ import path from "node:path"; import { EXPORTED_VLLM_PROFILE_ID } from "../../../src/lib/config/model.ts"; import type { V1Alpha1OllamaProxyService } from "../../../src/lib/config/v1alpha1-export.ts"; import { cleanupLocalModelRuntimes } from "../../../src/lib/inference/local-model-profile/cleanup.ts"; +import { normalizeNativeLocalProviderAttachment } from "../../../src/lib/inference/native-local/contract.ts"; import { HOST_LOCAL_VLLM_CONTAINER_NAME } from "../../../src/lib/inference/serving/vllm-host-local-lifecycle.ts"; import { loadManagedVllmApiKey } from "../../../src/lib/inference/vllm-api-key.ts"; +import { getSandbox } from "../../../src/lib/state/registry.ts"; import { execTimeout, testTimeout } from "../../helpers/timeouts.ts"; import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; import { resultText } from "../fixtures/clients/index.ts"; import { trustedSandboxShellScript } from "../fixtures/clients/sandbox.ts"; import { parseConfigExport } from "../fixtures/phases/config-export-validation.ts"; import { expect, test } from "../fixtures/e2e-test.ts"; +import { nativeLocalChatCommand } from "../fixtures/native-local-chat.ts"; import { assertAgentExecutionSucceeded, assertGpuInstallProofs, @@ -84,7 +87,7 @@ test( "install Ollama and GPU sandbox", "validate GPU runtime status", "validate Ollama proxy credential boundary", - "run sandbox inference.local chat", + "run sandbox native Ollama chat", "restart Ollama and recover agent inference", ], }, @@ -93,7 +96,7 @@ test( await artifacts.target.declare({ id: "gpu-e2e", boundary: - "GPU host + install.sh Ollama provider + OpenShell sandbox + auth proxy + inference.local", + "GPU host + install.sh Ollama provider + OpenShell sandbox + auth proxy + sandbox-owned native provider", credentialBoundary: "The proxy token remains host/OpenShell-owned and is absent from sandbox env.", remoteInstallerBoundary: @@ -191,12 +194,12 @@ test( expect(retainedSandboxContainer.State).toBe("running"); expect(retainedSandboxContainer.Status).toMatch(/\(healthy\)/i); - const route = await sandbox.openshell(["inference", "get"], { - artifactName: "openshell-inference-route", - env: env(), - timeoutMs: 30_000, - }); - expect(resultText(route)).toMatch(/ollama/i); + // OpenClaw local inference uses a sandbox-owned provider behind the auth proxy, not the + // shared gateway route (#13293). + const nativeEndpoint = normalizeNativeLocalProviderAttachment( + getSandbox(SANDBOX_NAME)?.nativeLocalProviderAttachment, + )?.endpointUrl; + expect(nativeEndpoint).toBe(`http://host.openshell.internal:${PROXY_PORT}/v1`); progress.phase("validate Ollama proxy credential boundary"); const tokenRecord = readTokenFileChecked(ollamaProxyTokenFile()); @@ -238,13 +241,14 @@ test( "OpenShell owns proxy authentication; the host proxy token must not enter sandbox env", ).toBe(""); - progress.phase("run sandbox inference.local chat"); + progress.phase("run sandbox native Ollama chat"); const model = await detectOllamaModel(host); const chat = await sandbox.execShell( SANDBOX_NAME, trustedSandboxShellScript( - `curl -sS --max-time 120 https://inference.local/v1/chat/completions -H 'Content-Type: application/json' --data '${JSON.stringify( - { + nativeLocalChatCommand( + nativeEndpoint ?? "http://missing-native-local-attachment.invalid/v1", + JSON.stringify({ model, messages: [{ role: "user", content: "Reply with exactly one word: PONG" }], // Keep this assertion about routed inference, not the model's reasoning-token budget. @@ -252,10 +256,11 @@ test( seed: 0, temperature: 0, max_tokens: 32, - }, - )}'`, + }), + "-sS", + ), ), - { artifactName: "sandbox-inference-local-chat", env: env(), timeoutMs: 150_000 }, + { artifactName: "sandbox-native-ollama-chat", env: env(), timeoutMs: 150_000 }, ); expect(chatContent(chat.stdout)).toMatch(/pong/i); diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index 944c8ddccf2..2c8e2653ab3 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -602,9 +602,11 @@ }, { "live": "test/e2e/live/gpu-double-onboard.test.ts", + "liveSources": ["test/e2e/fixtures/native-local-chat.ts"], "fast": [ "test/e2e/support/e2e-cleanup-resources.test.ts", "test/e2e/support/e2e-clients.test.ts", + "test/e2e/support/gpu-e2e-helpers.test.ts", "test/helpers/e2e-answer-assertions.test.ts" ] }, @@ -612,7 +614,8 @@ "live": "test/e2e/live/gpu-e2e.test.ts", "liveSources": [ "test/e2e/live/gpu-e2e-helpers.ts", - "test/e2e/live/hermes-cli-adapter-live.ts" + "test/e2e/live/hermes-cli-adapter-live.ts", + "test/e2e/fixtures/native-local-chat.ts" ], "fast": [ "src/lib/adapters/config/live-export-source-ollama.test.ts", diff --git a/test/e2e/support/gpu-e2e-helpers.test.ts b/test/e2e/support/gpu-e2e-helpers.test.ts index 3eca30364b1..8ce1227225b 100644 --- a/test/e2e/support/gpu-e2e-helpers.test.ts +++ b/test/e2e/support/gpu-e2e-helpers.test.ts @@ -11,6 +11,7 @@ import path from "node:path"; import { describe, expect, it, vi } from "vitest"; +import { nativeLocalChatCommand } from "../fixtures/native-local-chat.ts"; import { HostCliClient } from "../fixtures/clients/host.ts"; import type { SandboxClient } from "../fixtures/clients/sandbox.ts"; import { CleanupRegistry } from "../fixtures/cleanup.ts"; @@ -854,3 +855,69 @@ describe("GPU E2E helpers", () => { } }); }); + +describe("GPU native local chat command", () => { + const endpointUrl = "http://host.openshell.internal:11435/v1"; + const body = JSON.stringify({ model: GPU_MODEL, messages: [{ role: "user", content: "hi" }] }); + + function runWithRecordingCurl(token: string, curlFlags: "-fsS" | "-sS", requestBody = body) { + const root = mkdtempSync(path.join(tmpdir(), "gpu-native-chat-")); + try { + const bin = path.join(root, "bin"); + mkdirSync(bin); + writeShellCommands(bin, [["curl", 'for arg in "$@"; do printf "%s\\n" "$arg"; done\n']]); + try { + const stdout = execFileSync( + "sh", + ["-c", nativeLocalChatCommand(endpointUrl, requestBody, curlFlags)], + { + ...SYNC_E2E_CHILD_OPTIONS, + encoding: "utf8", + env: { + PATH: `${bin}:${process.env.PATH ?? ""}`, + NEMOCLAW_LOCAL_INFERENCE_TOKEN: token, + }, + }, + ); + return { status: 0, args: stdout.split("\n").filter(Boolean) }; + } catch (error) { + return { status: (error as { status?: number }).status, args: [] as string[] }; + } + } finally { + rmSync(root, { recursive: true, force: true }); + } + } + + it("sends the OpenShell-issued handle to the recorded endpoint", () => { + const handle = "openshell:resolve:env:v7_NEMOCLAW_LOCAL_INFERENCE_TOKEN"; + expect(runWithRecordingCurl(handle, "-fsS")).toEqual({ + status: 0, + args: [ + "-fsS", + "--max-time", + "120", + `${endpointUrl}/chat/completions`, + "-H", + `Authorization: Bearer ${handle}`, + "-H", + "Content-Type: application/json", + "--data", + body, + ], + }); + expect(runWithRecordingCurl(handle, "-sS").args[0]).toBe("-sS"); + }); + + it("refuses a raw or missing credential before calling curl", () => { + expect(runWithRecordingCurl("raw-proxy-token-value", "-fsS")).toEqual({ status: 2, args: [] }); + expect(runWithRecordingCurl("", "-fsS")).toEqual({ status: 2, args: [] }); + }); + + it("keeps request data with shell syntax as one curl argument", () => { + const handle = "openshell:resolve:env:v7_NEMOCLAW_LOCAL_INFERENCE_TOKEN"; + const hostileBody = JSON.stringify({ model: "x'; echo injected; '$(echo also)", messages: [] }); + const result = runWithRecordingCurl(handle, "-fsS", hostileBody); + expect(result.status).toBe(0); + expect(result.args.slice(-2)).toEqual(["--data", hostileBody]); + }); +}); diff --git a/test/e2e/support/workflow-plan.test.ts b/test/e2e/support/workflow-plan.test.ts index 3b739488ea3..6a4e9879a0a 100644 --- a/test/e2e/support/workflow-plan.test.ts +++ b/test/e2e/support/workflow-plan.test.ts @@ -696,6 +696,19 @@ describe("E2E workflow plan", () => { expect(selectedWorkflowJobs(plan)).toEqual(["catalogue-standard", "jetson-nvmap-gpu"]); }); + it.each<[string, string[]]>([ + ["test/e2e/fixtures/native-local-chat.ts", ["gpu-double-onboard", "gpu-e2e"]], + [ + "src/lib/actions/sandbox/inference-invocation-probe.ts", + ["inference-routing-openclaw-native"], + ], + ["src/lib/actions/sandbox/inference-route-health.ts", ["inference-routing-openclaw-native"]], + ])("selects the live owners of %s", (changedFile, targets) => { + expect(catalogueTargetsForChangedFiles([changedFile]).map((target) => target.id)).toEqual( + expect.arrayContaining(targets), + ); + }); + it("selects Hermes GPU startup when its output proof changes", () => { const plan = buildE2eWorkflowPlan( {}, diff --git a/test/helpers/inference-set.ts b/test/helpers/inference-set.ts index 1e6945e61a6..ca4af828f4d 100644 --- a/test/helpers/inference-set.ts +++ b/test/helpers/inference-set.ts @@ -292,6 +292,7 @@ export type CaptureOpenshell = ( export function nativeLocalTestReceipt( provider: NativeLocalBinding["provider"] = "ollama-local", endpointUrl = "http://host.openshell.internal:11435/v1", + overrides: Partial = {}, ) { const binding: NativeLocalBinding = { provider, @@ -300,6 +301,7 @@ export function nativeLocalTestReceipt( gatewayName: "nemoclaw", credentialEnv: "NEMOCLAW_LOCAL_INFERENCE_TOKEN", authMode: "authenticated", + ...overrides, }; return { ...binding, diff --git a/test/helpers/native-local-probe-shell.ts b/test/helpers/native-local-probe-shell.ts new file mode 100644 index 00000000000..977d7ac5576 --- /dev/null +++ b/test/helpers/native-local-probe-shell.ts @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { spawnSync } from "node:child_process"; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import type { SandboxInferenceInvocationDeps } from "../../src/lib/actions/sandbox/inference-invocation-probe"; + +/** The shape OpenShell issues for an attached native local provider credential. */ +export const NATIVE_LOCAL_CREDENTIAL_HANDLE = + "openshell:resolve:env:v7_NEMOCLAW_LOCAL_INFERENCE_TOKEN"; + +/** + * Run each generated probe command in a real shell whose curl records its + * arguments and answers with a fixed HTTP status and body. The recorded + * arguments show the actual request destination and headers. + */ +export function recordingProbeShell( + code: string, + body = "", + environment: NodeJS.ProcessEnv = { + NEMOCLAW_LOCAL_INFERENCE_TOKEN: NATIVE_LOCAL_CREDENTIAL_HANDLE, + }, +) { + const requests: string[][] = []; + const execute: NonNullable = async ( + _sandboxName, + command, + ) => { + const dir = mkdtempSync(path.join(tmpdir(), "nemoclaw-probe-route-")); + try { + const bin = path.join(dir, "bin"); + const argv = path.join(dir, "argv.txt"); + mkdirSync(bin); + writeFileSync(path.join(dir, "body.txt"), body); + writeFileSync( + path.join(bin, "curl"), + [ + "#!/bin/sh", + `printf '%s\\n' "$@" > ${JSON.stringify(argv)}`, + 'out=""; prev=""', + 'for a in "$@"; do [ "$prev" = "-o" ] && out="$a"; prev="$a"; done', + `cat ${JSON.stringify(path.join(dir, "body.txt"))} > "$out"`, + `printf '%s' ${JSON.stringify(code)}`, + ].join("\n"), + { mode: 0o755 }, + ); + const run = spawnSync("/bin/sh", ["-c", command], { + encoding: "utf8", + env: { PATH: `${bin}:${process.env.PATH ?? ""}`, ...environment }, + }); + try { + requests.push(readFileSync(argv, "utf8").trimEnd().split("\n")); + } catch { + /* curl was not reached */ + } + return { status: run.status ?? 1, stdout: run.stdout ?? "", stderr: run.stderr ?? "" }; + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }; + return { + execute, + requests, + destinations: () => requests.map((argv) => argv.at(-1)), + }; +} diff --git a/tools/e2e/target-catalogue.mts b/tools/e2e/target-catalogue.mts index 894ea84cd39..e8546a80e1d 100644 --- a/tools/e2e/target-catalogue.mts +++ b/tools/e2e/target-catalogue.mts @@ -816,6 +816,7 @@ export const E2E_TARGET_CATALOGUE: readonly E2eCatalogueTarget[] = [ installMode: "authenticated", restoreCli: true, exposeCliBin: true, + owningPaths: ["test/e2e/fixtures/native-local-chat.ts"], environment: { ...nonInteractive, NEMOCLAW_MODEL: "qwen3.5:9b", @@ -836,6 +837,7 @@ export const E2E_TARGET_CATALOGUE: readonly E2eCatalogueTarget[] = [ exposeCliBin: true, owningPaths: [ "test/e2e/live/gpu-e2e-helpers.ts", + "test/e2e/fixtures/native-local-chat.ts", "test/e2e/live/hermes-cli-adapter-live.ts", "src/lib/inference/ollama/proxy.ts", "src/lib/inference/ollama/proxy-observation.ts", @@ -1058,6 +1060,8 @@ export const E2E_TARGET_CATALOGUE: readonly E2eCatalogueTarget[] = [ "src/lib/onboard/openclaw/initial-inference-route.ts", "src/lib/onboard/setup-inference.ts", "src/lib/actions/sandbox/rebuild-preflight-guards.ts", + "src/lib/actions/sandbox/inference-invocation-probe.ts", + "src/lib/actions/sandbox/inference-route-health.ts", "test/e2e/fixtures/inference-routing-openclaw-native.ts", "tools/e2e/onboard-timeout-contract.mts", ],