From 3f3e2214492d50bf2e85e4b8fdbe7ed22926ed8d Mon Sep 17 00:00:00 2001 From: Tinson Lai Date: Sat, 30 May 2026 14:56:35 +0000 Subject: [PATCH 1/3] fix(inference): preflight NEMOCLAW_VLLM_MODEL on sandbox connect Signed-off-by: Tinson Lai --- docs/reference/commands.mdx | 2 +- src/lib/actions/sandbox/connect.ts | 22 +++++++++++ src/lib/inference/vllm-models.test.ts | 53 +++++++++++++++++++++++++++ src/lib/inference/vllm-models.ts | 36 ++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 0b5472af5c5..04fd6482e79 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -1358,7 +1358,7 @@ Set them before running `nemoclaw onboard`. | `NEMOCLAW_SANDBOX` | sandbox name | Alternate spelling of `NEMOCLAW_SANDBOX_NAME`; used by `services` and `debug` lookups when neither a flag nor `NEMOCLAW_SANDBOX_NAME` is set. | | `NEMOCLAW_INSTALL_REF` | git ref | For internal installer commands: the git ref to install from. Overridden by the `--install-ref` flag. | | `NEMOCLAW_INSTALL_TAG` | release tag | For internal installer commands: the release tag to install. Overridden by the `--install-tag` flag. | -| `NEMOCLAW_VLLM_MODEL` | registry slug or Hugging Face model id | Selects the model the managed-vLLM install path serves. Recognised slugs: `qwen3.6-27b`, `nemotron-3-nano-4b`, `deepseek-r1-distill-70b`. Unset uses the per-platform profile default. Gated models (e.g. `deepseek-r1-distill-70b`) require `HF_TOKEN` or `HUGGING_FACE_HUB_TOKEN`. | +| `NEMOCLAW_VLLM_MODEL` | registry slug or Hugging Face model id | Selects the model the managed-vLLM install path serves. Recognised slugs: `qwen3.6-27b`, `nemotron-3-nano-4b`, `deepseek-r1-distill-70b`. Unset uses the per-platform profile default. Gated models (e.g. `deepseek-r1-distill-70b`) require `HF_TOKEN` or `HUGGING_FACE_HUB_TOKEN`. `nemoclaw connect` only inspects the variable for fail-fast validation (unknown slug or gated model without an HF token) before attaching; it does not pull or serve a model itself. | | `NEMOCLAW_MODEL_ROUTER_PYTHON` | absolute path | Pins the host Python interpreter used to create the Model Router virtual environment. Strict. NemoClaw probes only that interpreter and aborts with the failure reason if it does not qualify, rather than silently falling back to another python. Relative command names such as `python3.12` are rejected. When unset, NemoClaw probes `python3.13`, `python3.12`, `python3.11`, `python3.10`, and bare `python3`, retains every interpreter whose version is in `[3.10, 3.14)` and whose `ensurepip`, `pyexpat`, `ssl`, and `venv` stdlib modules import cleanly, and tries `python -m venv` on each in priority order until one succeeds. Set the pin when the auto-discovered interpreter is broken (for example, Homebrew `python@3.14` with a `pyexpat` dlopen mismatch on macOS). | #### Linux Ollama install mode details diff --git a/src/lib/actions/sandbox/connect.ts b/src/lib/actions/sandbox/connect.ts index 71433f3fbd7..8fa0a73143d 100644 --- a/src/lib/actions/sandbox/connect.ts +++ b/src/lib/actions/sandbox/connect.ts @@ -19,6 +19,7 @@ import { D, G, R, YW } from "../../cli/terminal-style"; import * as agentRuntime from "../../agent/runtime"; import { parseGatewayInference } from "../../inference/config"; import { findReachableOllamaHost, probeLocalProviderHealth } from "../../inference/local"; +import { preflightVllmModelEnv } from "../../inference/vllm-models"; import { ensureOllamaAuthProxy, probeOllamaAuthProxyHealth, @@ -755,10 +756,31 @@ function exitWithSpawnResult(result: SpawnLikeResult): void { process.exit(1); } +// `NEMOCLAW_VLLM_MODEL` only steers the express-vLLM install path, but users +// often re-export it in the same shell they later run `connect` in. Run the +// installer's validators up-front so a typo or a gated model with no +// `HF_TOKEN` fails fast on the host — before any sandbox readiness probe, +// inference-route reset, or SSH attach — instead of being silently ignored. +// (#4543) +function preflightVllmModelEnvOrExit(): void { + const result = preflightVllmModelEnv(); + if (result.ok) return; + console.error(""); + console.error(` Error: ${result.message}`); + console.error( + ` Hint: NEMOCLAW_VLLM_MODEL is consumed by the managed-vLLM install path, not \`${CLI_NAME} connect\`.`, + ); + console.error( + " Unset NEMOCLAW_VLLM_MODEL before reconnecting, or fix the value (and token) and re-run the install path that serves the model.", + ); + process.exit(1); +} + export async function connectSandbox( sandboxName: string, { probeOnly = false }: SandboxConnectOptions = {}, ): Promise { + preflightVllmModelEnvOrExit(); const { isSandboxReady, parseSandboxStatus } = require("../../onboard"); await ensureLiveSandboxOrExit(sandboxName, { allowNonReadyPhase: true }); diff --git a/src/lib/inference/vllm-models.test.ts b/src/lib/inference/vllm-models.test.ts index 7084023d0ee..97aea1b02f8 100644 --- a/src/lib/inference/vllm-models.test.ts +++ b/src/lib/inference/vllm-models.test.ts @@ -8,6 +8,7 @@ import { VLLM_MODELS, assertGatedModelAccess, buildVllmServeCommand, + preflightVllmModelEnv, selectVllmModelFromEnv, } from "../../../dist/lib/inference/vllm-models"; @@ -99,3 +100,55 @@ describe("vllm model registry", () => { expect(cmd).not.toContain("--reasoning-parser qwen3"); }); }); + +describe("preflightVllmModelEnv", () => { + it("succeeds when NEMOCLAW_VLLM_MODEL is unset", () => { + expect(preflightVllmModelEnv({} as NodeJS.ProcessEnv)).toEqual({ ok: true }); + }); + + it("succeeds for a recognised non-gated slug", () => { + expect( + preflightVllmModelEnv({ NEMOCLAW_VLLM_MODEL: "qwen3.6-27b" } as NodeJS.ProcessEnv), + ).toEqual({ ok: true }); + }); + + it("succeeds for a gated slug when HF_TOKEN is set", () => { + expect( + preflightVllmModelEnv({ + NEMOCLAW_VLLM_MODEL: "deepseek-r1-distill-70b", + HF_TOKEN: "hf_abc", + } as NodeJS.ProcessEnv), + ).toEqual({ ok: true }); + }); + + it("succeeds for a gated slug when HUGGING_FACE_HUB_TOKEN is set", () => { + expect( + preflightVllmModelEnv({ + NEMOCLAW_VLLM_MODEL: "deepseek-r1-distill-70b", + HUGGING_FACE_HUB_TOKEN: "hf_abc", + } as NodeJS.ProcessEnv), + ).toEqual({ ok: true }); + }); + + it("fails fast for a gated slug with no Hugging Face token (#4543)", () => { + const result = preflightVllmModelEnv({ + NEMOCLAW_VLLM_MODEL: "deepseek-r1-distill-70b", + } as NodeJS.ProcessEnv); + expect(result.ok).toBe(false); + if (!result.ok) { + expect(result.message).toMatch(/gated on Hugging Face/); + expect(result.message).toMatch(/HF_TOKEN/); + expect(result.message).toMatch(/HUGGING_FACE_HUB_TOKEN/); + } + }); + + it("fails fast for an unknown slug", () => { + const result = preflightVllmModelEnv({ + NEMOCLAW_VLLM_MODEL: "made-up-model", + } as NodeJS.ProcessEnv); + expect(result.ok).toBe(false); + if (!result.ok) { + expect(result.message).toMatch(/Unknown NEMOCLAW_VLLM_MODEL='made-up-model'/); + } + }); +}); diff --git a/src/lib/inference/vllm-models.ts b/src/lib/inference/vllm-models.ts index 6e6179833ca..cbb8fb47d82 100644 --- a/src/lib/inference/vllm-models.ts +++ b/src/lib/inference/vllm-models.ts @@ -133,6 +133,42 @@ export function assertGatedModelAccess( ); } +export type PreflightVllmModelResult = { ok: true } | { ok: false; message: string }; + +/** + * Combined preflight for callers that hold a `NEMOCLAW_VLLM_MODEL` reference + * but do not themselves invoke the vLLM installer — for example + * `nemoclaw connect`, which simply attaches to a running sandbox. + * + * The variable steers the express-vLLM install path, so on every other code + * path the natural behaviour is to ignore it. Silent-ignore hides two real + * user mistakes: + * + * 1. typos in the slug (`deepseek-r1-distill-70b` vs an old marketing + * name), surfaced later as the wrong model being served and a confused + * user; and + * 2. requesting a gated model (DeepSeek-R1 Distill Llama 70B) without + * exporting `HF_TOKEN` / `HUGGING_FACE_HUB_TOKEN`, which downstream + * explodes as a 401 from Hugging Face partway through the pull. + * + * Running the same `selectVllmModelFromEnv` + `assertGatedModelAccess` checks + * the installer uses gives the caller a single fail-fast surface and one + * canonical message to print before any side effects. Returns + * `{ ok: true }` when the variable is unset or resolves cleanly. (#4543) + */ +export function preflightVllmModelEnv( + env: NodeJS.ProcessEnv = process.env, +): PreflightVllmModelResult { + try { + const model = selectVllmModelFromEnv(env); + if (!model) return { ok: true }; + assertGatedModelAccess(model, env); + return { ok: true }; + } catch (err) { + return { ok: false, message: (err as Error).message }; + } +} + const SHARED_VLLM_ARGS: readonly string[] = [ "--gpu-memory-utilization", "0.7", From 17a42854aaa73a86c1f0fa5f082ae2913f336761 Mon Sep 17 00:00:00 2001 From: Tinson Lai Date: Sat, 30 May 2026 15:30:31 +0000 Subject: [PATCH 2/3] test(connect): cover NEMOCLAW_VLLM_MODEL preflight regression Signed-off-by: Tinson Lai --- docs/reference/commands.mdx | 6 ++- src/lib/actions/sandbox/connect.ts | 1 - src/lib/inference/vllm-models.test.ts | 2 +- src/lib/inference/vllm-models.ts | 2 +- test/cli.test.ts | 62 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 04fd6482e79..53ced16ab64 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -347,6 +347,10 @@ Set `NEMOCLAW_NO_CONNECT_HINT=1` to suppress the hint in scripted workflows. If the sandbox is running an outdated agent version, a non-blocking warning prints before connecting with a `nemoclaw rebuild` hint. If another terminal is already connected to the sandbox, `connect` prints a note with the number of existing sessions before proceeding. Multiple concurrent sessions are allowed. +`connect` does not pull or serve a model itself, but it does inspect `NEMOCLAW_VLLM_MODEL` if you exported it for the managed-vLLM install path. +An unknown slug or a gated model (for example `deepseek-r1-distill-70b`) with no `HF_TOKEN` or `HUGGING_FACE_HUB_TOKEN` exits non-zero with the same error the installer would emit, before any sandbox readiness probe or SSH attach. +Unset the variable, or supply the missing token, before retrying. + After a host reboot, the OpenShell gateway rotates its SSH host keys. `connect` detects the resulting identity drift, prunes stale `openshell-*` entries from `~/.ssh/known_hosts`, and retries automatically. You no longer need to re-run `nemoclaw onboard` after a reboot in this case. @@ -1358,7 +1362,7 @@ Set them before running `nemoclaw onboard`. | `NEMOCLAW_SANDBOX` | sandbox name | Alternate spelling of `NEMOCLAW_SANDBOX_NAME`; used by `services` and `debug` lookups when neither a flag nor `NEMOCLAW_SANDBOX_NAME` is set. | | `NEMOCLAW_INSTALL_REF` | git ref | For internal installer commands: the git ref to install from. Overridden by the `--install-ref` flag. | | `NEMOCLAW_INSTALL_TAG` | release tag | For internal installer commands: the release tag to install. Overridden by the `--install-tag` flag. | -| `NEMOCLAW_VLLM_MODEL` | registry slug or Hugging Face model id | Selects the model the managed-vLLM install path serves. Recognised slugs: `qwen3.6-27b`, `nemotron-3-nano-4b`, `deepseek-r1-distill-70b`. Unset uses the per-platform profile default. Gated models (e.g. `deepseek-r1-distill-70b`) require `HF_TOKEN` or `HUGGING_FACE_HUB_TOKEN`. `nemoclaw connect` only inspects the variable for fail-fast validation (unknown slug or gated model without an HF token) before attaching; it does not pull or serve a model itself. | +| `NEMOCLAW_VLLM_MODEL` | registry slug or Hugging Face model id | Selects the model the managed-vLLM install path serves. Recognised slugs: `qwen3.6-27b`, `nemotron-3-nano-4b`, `deepseek-r1-distill-70b`. Unset uses the per-platform profile default. Gated models (e.g. `deepseek-r1-distill-70b`) require `HF_TOKEN` or `HUGGING_FACE_HUB_TOKEN`. | | `NEMOCLAW_MODEL_ROUTER_PYTHON` | absolute path | Pins the host Python interpreter used to create the Model Router virtual environment. Strict. NemoClaw probes only that interpreter and aborts with the failure reason if it does not qualify, rather than silently falling back to another python. Relative command names such as `python3.12` are rejected. When unset, NemoClaw probes `python3.13`, `python3.12`, `python3.11`, `python3.10`, and bare `python3`, retains every interpreter whose version is in `[3.10, 3.14)` and whose `ensurepip`, `pyexpat`, `ssl`, and `venv` stdlib modules import cleanly, and tries `python -m venv` on each in priority order until one succeeds. Set the pin when the auto-discovered interpreter is broken (for example, Homebrew `python@3.14` with a `pyexpat` dlopen mismatch on macOS). | #### Linux Ollama install mode details diff --git a/src/lib/actions/sandbox/connect.ts b/src/lib/actions/sandbox/connect.ts index 8fa0a73143d..298f9200e5f 100644 --- a/src/lib/actions/sandbox/connect.ts +++ b/src/lib/actions/sandbox/connect.ts @@ -761,7 +761,6 @@ function exitWithSpawnResult(result: SpawnLikeResult): void { // installer's validators up-front so a typo or a gated model with no // `HF_TOKEN` fails fast on the host — before any sandbox readiness probe, // inference-route reset, or SSH attach — instead of being silently ignored. -// (#4543) function preflightVllmModelEnvOrExit(): void { const result = preflightVllmModelEnv(); if (result.ok) return; diff --git a/src/lib/inference/vllm-models.test.ts b/src/lib/inference/vllm-models.test.ts index 97aea1b02f8..35c662dbbbe 100644 --- a/src/lib/inference/vllm-models.test.ts +++ b/src/lib/inference/vllm-models.test.ts @@ -130,7 +130,7 @@ describe("preflightVllmModelEnv", () => { ).toEqual({ ok: true }); }); - it("fails fast for a gated slug with no Hugging Face token (#4543)", () => { + it("fails fast for a gated slug with no Hugging Face token", () => { const result = preflightVllmModelEnv({ NEMOCLAW_VLLM_MODEL: "deepseek-r1-distill-70b", } as NodeJS.ProcessEnv); diff --git a/src/lib/inference/vllm-models.ts b/src/lib/inference/vllm-models.ts index cbb8fb47d82..293d3e0ee0c 100644 --- a/src/lib/inference/vllm-models.ts +++ b/src/lib/inference/vllm-models.ts @@ -154,7 +154,7 @@ export type PreflightVllmModelResult = { ok: true } | { ok: false; message: stri * Running the same `selectVllmModelFromEnv` + `assertGatedModelAccess` checks * the installer uses gives the caller a single fail-fast surface and one * canonical message to print before any side effects. Returns - * `{ ok: true }` when the variable is unset or resolves cleanly. (#4543) + * `{ ok: true }` when the variable is unset or resolves cleanly. */ export function preflightVllmModelEnv( env: NodeJS.ProcessEnv = process.env, diff --git a/test/cli.test.ts b/test/cli.test.ts index 5f7ecff8397..f62e8ea7e79 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -541,6 +541,68 @@ describe("CLI dispatch", () => { expect(r.out).not.toContain("Unknown command: liost"); }); + it("fails fast on gated NEMOCLAW_VLLM_MODEL without HF token before sandbox side effects", () => { + const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-cli-vllm-preflight-")); + try { + const localBin = path.join(home, "bin"); + fs.mkdirSync(localBin, { recursive: true }); + writeSandboxRegistry(home); + const openshellLog = path.join(home, "openshell-calls.log"); + fs.writeFileSync( + path.join(localBin, "openshell"), + [ + "#!/usr/bin/env bash", + `printf "%s\\n" "$*" >> ${JSON.stringify(openshellLog)}`, + "exit 0", + ].join("\n"), + { mode: 0o755 }, + ); + + const childEnv: Record = {}; + for (const [key, value] of Object.entries(process.env)) { + if (value !== undefined) childEnv[key] = value; + } + delete childEnv.HF_TOKEN; + delete childEnv.HUGGING_FACE_HUB_TOKEN; + childEnv.HOME = home; + childEnv.PATH = `${localBin}:${process.env.PATH || ""}`; + childEnv.NEMOCLAW_HEALTH_POLL_COUNT = "1"; + childEnv.NEMOCLAW_HEALTH_POLL_INTERVAL = "0"; + childEnv.NEMOCLAW_VLLM_MODEL = "deepseek-r1-distill-70b"; + + let code = 0; + let out = ""; + try { + execSync(`node "${CLI}" alpha connect 2>&1`, { + encoding: "utf-8", + stdio: "pipe", + timeout: execTimeout(), + env: childEnv, + }); + } catch (err) { + const e = err as { + status?: number; + stdout?: string | Buffer; + stderr?: string | Buffer; + }; + code = typeof e.status === "number" ? e.status : 1; + out = `${e.stdout ?? ""}${e.stderr ?? ""}`; + } + + expect(code).toBe(1); + expect(out).toMatch(/gated on Hugging Face/); + expect(out).toMatch(/HF_TOKEN/); + expect(out).toMatch(/HUGGING_FACE_HUB_TOKEN/); + expect(out).toContain( + "NEMOCLAW_VLLM_MODEL is consumed by the managed-vLLM install path", + ); + const calls = fs.existsSync(openshellLog) ? fs.readFileSync(openshellLog, "utf8") : ""; + expect(calls).not.toMatch(/\bsandbox\s+(get|connect|list)\b/); + } finally { + fs.rmSync(home, { recursive: true, force: true }); + } + }); + it("explains sandbox connect command order when the sandbox name is last", () => { const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-cli-connect-order-")); const localBin = path.join(home, "bin"); From 86faee6c28a09cfaa9ec9b55afb0d9bbcb73583c Mon Sep 17 00:00:00 2001 From: Tinson Lai Date: Sat, 30 May 2026 18:53:10 +0000 Subject: [PATCH 3/3] refactor(connect): extract vLLM preflight into dedicated helper module Signed-off-by: Tinson Lai --- .../actions/sandbox/connect-vllm-preflight.ts | 24 +++++++++++++++++++ src/lib/actions/sandbox/connect.ts | 21 +--------------- 2 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 src/lib/actions/sandbox/connect-vllm-preflight.ts diff --git a/src/lib/actions/sandbox/connect-vllm-preflight.ts b/src/lib/actions/sandbox/connect-vllm-preflight.ts new file mode 100644 index 00000000000..038415a5b7f --- /dev/null +++ b/src/lib/actions/sandbox/connect-vllm-preflight.ts @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { CLI_NAME } from "../../cli/branding"; +import { preflightVllmModelEnv } from "../../inference/vllm-models"; + +// `NEMOCLAW_VLLM_MODEL` only steers the express-vLLM install path, but users +// often re-export it in the same shell they later run `connect` in. Run the +// installer's validators up-front so a typo or a gated model with no +// `HF_TOKEN` fails fast on the host — before any sandbox readiness probe, +// inference-route reset, or SSH attach — instead of being silently ignored. +export function preflightVllmModelEnvOrExit(): void { + const result = preflightVllmModelEnv(); + if (result.ok) return; + console.error(""); + console.error(` Error: ${result.message}`); + console.error( + ` Hint: NEMOCLAW_VLLM_MODEL is consumed by the managed-vLLM install path, not \`${CLI_NAME} connect\`.`, + ); + console.error( + " Unset NEMOCLAW_VLLM_MODEL before reconnecting, or fix the value (and token) and re-run the install path that serves the model.", + ); + process.exit(1); +} diff --git a/src/lib/actions/sandbox/connect.ts b/src/lib/actions/sandbox/connect.ts index 298f9200e5f..236f18f4302 100644 --- a/src/lib/actions/sandbox/connect.ts +++ b/src/lib/actions/sandbox/connect.ts @@ -19,7 +19,7 @@ import { D, G, R, YW } from "../../cli/terminal-style"; import * as agentRuntime from "../../agent/runtime"; import { parseGatewayInference } from "../../inference/config"; import { findReachableOllamaHost, probeLocalProviderHealth } from "../../inference/local"; -import { preflightVllmModelEnv } from "../../inference/vllm-models"; +import { preflightVllmModelEnvOrExit } from "./connect-vllm-preflight"; import { ensureOllamaAuthProxy, probeOllamaAuthProxyHealth, @@ -756,25 +756,6 @@ function exitWithSpawnResult(result: SpawnLikeResult): void { process.exit(1); } -// `NEMOCLAW_VLLM_MODEL` only steers the express-vLLM install path, but users -// often re-export it in the same shell they later run `connect` in. Run the -// installer's validators up-front so a typo or a gated model with no -// `HF_TOKEN` fails fast on the host — before any sandbox readiness probe, -// inference-route reset, or SSH attach — instead of being silently ignored. -function preflightVllmModelEnvOrExit(): void { - const result = preflightVllmModelEnv(); - if (result.ok) return; - console.error(""); - console.error(` Error: ${result.message}`); - console.error( - ` Hint: NEMOCLAW_VLLM_MODEL is consumed by the managed-vLLM install path, not \`${CLI_NAME} connect\`.`, - ); - console.error( - " Unset NEMOCLAW_VLLM_MODEL before reconnecting, or fix the value (and token) and re-run the install path that serves the model.", - ); - process.exit(1); -} - export async function connectSandbox( sandboxName: string, { probeOnly = false }: SandboxConnectOptions = {},