Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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 <name> 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.
Expand Down
24 changes: 24 additions & 0 deletions src/lib/actions/sandbox/connect-vllm-preflight.ts
Original file line number Diff line number Diff line change
@@ -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} <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);
}
2 changes: 2 additions & 0 deletions src/lib/actions/sandbox/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { preflightVllmModelEnvOrExit } from "./connect-vllm-preflight";
import {
ensureOllamaAuthProxy,
probeOllamaAuthProxyHealth,
Expand Down Expand Up @@ -759,6 +760,7 @@ export async function connectSandbox(
sandboxName: string,
{ probeOnly = false }: SandboxConnectOptions = {},
): Promise<void> {
preflightVllmModelEnvOrExit();
const { isSandboxReady, parseSandboxStatus } = require("../../onboard");
await ensureLiveSandboxOrExit(sandboxName, { allowNonReadyPhase: true });

Expand Down
53 changes: 53 additions & 0 deletions src/lib/inference/vllm-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
VLLM_MODELS,
assertGatedModelAccess,
buildVllmServeCommand,
preflightVllmModelEnv,
selectVllmModelFromEnv,
} from "../../../dist/lib/inference/vllm-models";

Expand Down Expand Up @@ -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", () => {
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'/);
}
});
});
36 changes: 36 additions & 0 deletions src/lib/inference/vllm-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> 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.
*/
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",
Expand Down
62 changes: 62 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,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<string, string> = {};
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");
Expand Down
Loading