Skip to content
Closed
2 changes: 1 addition & 1 deletion ci/source-architecture-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"allowedCycles": [],
"maxRootFiles": {
"src/lib/onboard": 310,
"src/lib/onboard": 311,
"src/lib/actions": 19,
"src/lib/actions/sandbox": 183,
"src/lib/state": 37,
Expand Down
8 changes: 3 additions & 5 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1326,12 +1326,10 @@ function destroyGateway(

const handleFinalGatewayStartFailure = createFinalGatewayStartFailureHandler({
getGatewayName: () => GATEWAY_NAME,
collectDiagnostics: () =>
runCaptureOpenshell(["doctor", "logs", "--name", GATEWAY_NAME], {
ignoreError: true,
timeout: 10_000,
}),
// biome-ignore format: keep src/lib/onboard.ts net-neutral for growth guardrail.
collectDiagnostics: () => runCaptureOpenshell(["doctor", "logs", "--name", GATEWAY_NAME], { ignoreError: true, timeout: 10_000 }),
cleanupGateway: destroyGateway,
supportsLifecycleCommands: () => gatewayCliSupportsLifecycleCommands(runCaptureOpenshell),
});

function getGatewayClusterContainerState(): string {
Expand Down
60 changes: 60 additions & 0 deletions src/lib/onboard/gateway-gpu-passthrough.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ vi.mock("../adapters/docker", () => ({
dockerInspect: vi.fn(),
}));

vi.mock("../state/registry", () => ({
listSandboxes: vi.fn(() => ({ sandboxes: [], defaultSandbox: null })),
}));

import * as docker from "../adapters/docker";
import type { GatewayReuseState } from "../state/gateway";
import * as registry from "../state/registry";
import {
canRestartCpuOnlyGatewayForGpuIntent,
decideGatewayGpuReuseForGpuIntent,
Expand Down Expand Up @@ -162,4 +167,59 @@ describe("gateway GPU passthrough inspection", () => {
expect(retireLegacyGatewayForDockerDriverUpgrade).not.toHaveBeenCalled();
expect(destroyGatewayRuntimeForGpuReuse).not.toHaveBeenCalled();
});

it("omits the legacy gateway destroy verb from the unreadable-registry hint (#8139)", () => {
const runReconcile = (supportsLifecycleCommands: boolean): string[] => {
const errors: string[] = [];
vi.mocked(docker.dockerInspect).mockReturnValue({
pid: 0,
output: [null, "[]", ""],
stdout: "[]",
stderr: "",
status: 0,
signal: null,
});
vi.mocked(registry.listSandboxes).mockImplementation(() => {
throw new Error("registry unreadable");
});
const errorSpy = vi.spyOn(console, "error").mockImplementation((message?: unknown) => {
errors.push(String(message));
});
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
throw new Error(`exit ${code}`);
}) as never);

try {
expect(() =>
reconcileGatewayGpuReuseForGpuIntent({
gatewayReuseState: healthy,
gpuPassthrough: true,
gatewayName: "nemoclaw",
currentSandboxName: null,
recreateSandbox: false,
confirmedDockerDriverGateway: false,
stopDashboardForwards: vi.fn(),
retireLegacyGatewayForDockerDriverUpgrade: vi.fn(),
destroyGatewayRuntimeForGpuReuse: vi.fn(),
supportsLifecycleCommands,
}),
).toThrow(/exit 1/);
} finally {
errorSpy.mockRestore();
exitSpy.mockRestore();
// Explicitly restore the shared module mocks for later tests in this file.
vi.mocked(registry.listSandboxes).mockReturnValue({ sandboxes: [], defaultSandbox: null });
vi.mocked(docker.dockerInspect).mockReset();
}
return errors;
};

const modern = runReconcile(false).join("\n");
expect(modern).toContain("openshell gateway remove nemoclaw");
expect(modern).not.toContain("gateway destroy");

const legacy = runReconcile(true).join("\n");
expect(legacy).toContain("openshell gateway remove nemoclaw");
expect(legacy).toContain("openshell gateway destroy -g nemoclaw");
});
});
31 changes: 25 additions & 6 deletions src/lib/onboard/gateway-gpu-passthrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { GatewayReuseState } from "../state/gateway";
import * as registry from "../state/registry";
import { isLinuxDockerDriverGatewayEnabled } from "./docker-driver-platform";
import { destroyGatewayForReuse } from "./gateway-cleanup";
import { gatewayRemovalHintLines } from "./gateway-removal-hint";
import { reportGpuPassthroughRecovery } from "./gpu-recovery";

export type LegacyGatewayGpuInspection = "gpu-enabled" | "cpu-only" | "not-found" | "unknown";
Expand All @@ -30,6 +31,7 @@ export type GatewayGpuReuseReconcileOptions = {
stopDashboardForwards: () => void;
retireLegacyGatewayForDockerDriverUpgrade: () => void;
destroyGatewayRuntimeForGpuReuse: () => boolean;
supportsLifecycleCommands?: boolean;
};

// Docker-driver/package-managed gateways do not expose reusable GPU state
Expand Down Expand Up @@ -109,6 +111,7 @@ function reportUnreadableSandboxRegistryForGpuGatewayReuse(
error: (line: string) => void,
exit: (code: number) => never,
gatewayName: string,
supportsLifecycleCommands: boolean,
): never {
error(" Existing gateway was started without GPU passthrough.");
error(
Expand All @@ -117,9 +120,9 @@ function reportUnreadableSandboxRegistryForGpuGatewayReuse(
error(
" Fix the registry read error and rerun, or manually verify no sandboxes depend on the gateway before running:",
);
error(` openshell gateway remove ${gatewayName}`);
error(" # For OpenShell releases that still expose lifecycle commands:");
error(` openshell gateway destroy -g ${gatewayName}`);
for (const line of gatewayRemovalHintLines(gatewayName, supportsLifecycleCommands)) {
error(line);
}
error(" sudo pkill -f openshell-gateway # if a privileged host gateway process remains");
error(" nemoclaw onboard --gpu");
exit(1);
Expand All @@ -144,6 +147,7 @@ export function reconcileGatewayGpuReuseForGpuIntent({
stopDashboardForwards,
retireLegacyGatewayForDockerDriverUpgrade,
destroyGatewayRuntimeForGpuReuse,
supportsLifecycleCommands = false,
}: GatewayGpuReuseReconcileOptions): GatewayReuseState {
if (
!shouldInspectLegacyGatewayGpuPassthrough(
Expand Down Expand Up @@ -174,7 +178,12 @@ export function reconcileGatewayGpuReuseForGpuIntent({
const registeredSandboxNames =
legacyGatewayGpuInspection === "cpu-only" ? readRegisteredSandboxNamesForGatewayGpuReuse() : [];
if (registeredSandboxNames === null) {
reportUnreadableSandboxRegistryForGpuGatewayReuse(console.error, process.exit, gatewayName);
reportUnreadableSandboxRegistryForGpuGatewayReuse(
console.error,
process.exit,
gatewayName,
supportsLifecycleCommands,
);
}

const gatewayGpuReuseDecision = decideGatewayGpuReuseForGpuIntent({
Expand Down Expand Up @@ -206,11 +215,21 @@ export function reconcileGatewayGpuReuseForGpuIntent({
);
}
if (gatewayReuseState !== "missing") {
reportGpuPassthroughRecovery(console.error, () => registeredSandboxNames);
reportGpuPassthroughRecovery(console.error, () => registeredSandboxNames, {
supportsLifecycleCommands,
});
process.exit(1);
}
} else if (gatewayGpuReuseDecision === "abort-with-recovery") {
reportGpuPassthroughRecovery(console.error, () => registeredSandboxNames);
// Defensive uniformity with the sibling call above: this branch is only
// reached with a non-empty registeredSandboxNames (abort-with-recovery
// implies !cpuOnlyGatewayRestartSafe, which implies names.length > 0), so
// gpuPassthroughRecoveryLines always takes its one-sandbox/multi-sandbox
// branch here and supportsLifecycleCommands cannot reach the gated
// gatewayRemovalHintLines output.
reportGpuPassthroughRecovery(console.error, () => registeredSandboxNames, {
supportsLifecycleCommands,
});
process.exit(1);
}
return gatewayReuseState;
Expand Down
37 changes: 37 additions & 0 deletions src/lib/onboard/gateway-removal-hint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";

import { gatewayRemovalHintLines } from "./gateway-removal-hint";

describe("gatewayRemovalHintLines", () => {
it("prints only the modern remove verb when the installed OpenShell has no lifecycle commands (#8139)", () => {
const lines = gatewayRemovalHintLines("nemoclaw", false);

expect(lines).toEqual([" openshell gateway remove nemoclaw"]);
expect(lines.join("\n")).not.toContain("gateway destroy");
});

it("omits the legacy destroy verb when support is unknown", () => {
expect(gatewayRemovalHintLines("nemoclaw").join("\n")).not.toContain("gateway destroy");
});

it("appends the legacy destroy verb only when the installed OpenShell advertises it", () => {
const lines = gatewayRemovalHintLines("nemoclaw", true);

expect(lines).toEqual([
" openshell gateway remove nemoclaw",
" # For OpenShell releases that still expose lifecycle commands:",
" openshell gateway destroy -g nemoclaw",
]);
});

it("renders the caller's gateway name in every emitted command", () => {
const lines = gatewayRemovalHintLines("nemoclaw-8081", true);

expect(lines).toContain(" openshell gateway remove nemoclaw-8081");
expect(lines).toContain(" openshell gateway destroy -g nemoclaw-8081");
expect(lines.join("\n")).not.toMatch(/\bnemoclaw\b(?!-8081)/);
});
});
31 changes: 31 additions & 0 deletions src/lib/onboard/gateway-removal-hint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/**
* Renders the manual gateway-removal command block shared by every onboard
* failure hint.
*
* OpenShell dropped the `gateway destroy` lifecycle verb in 0.0.44; current
* builds answer it with `error: unrecognized subcommand 'destroy'` (#8139).
* #6570 fixed the destroy-path hint but left the onboard hints printing the
* legacy verb behind a prose caveat the reader cannot evaluate, so gate it on
* the same capability probe the execution paths already use
* (`gatewayCliSupportsLifecycleCommands`).
*
* `supportsLifecycleCommands` defaults to false so an un-probed caller prints
* only the verb that current OpenShell accepts.
*
* Current consumers: gateway-start-failure.ts, gpu-recovery.ts,
* gateway-gpu-passthrough.ts.
*/
export function gatewayRemovalHintLines(
gatewayName: string,
supportsLifecycleCommands = false,
): string[] {
const lines = [` openshell gateway remove ${gatewayName}`];
if (supportsLifecycleCommands) {
lines.push(" # For OpenShell releases that still expose lifecycle commands:");
lines.push(` openshell gateway destroy -g ${gatewayName}`);
}
return lines;
}
22 changes: 22 additions & 0 deletions src/lib/onboard/gateway-start-failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,26 @@ describe("createFinalGatewayStartFailureHandler", () => {
expect(output).not.toContain("fghijklmno");
expect(output).toMatch(/NVIDIA_API_KEY=ghp_\*+/);
});

it("prints the legacy destroy verb from the deps-level supportsLifecycleCommands when no per-call override is given (#8139)", () => {
const printed: string[] = [];
const handleFailure = createFinalGatewayStartFailureHandler({
getGatewayName: () => "nemoclaw-test",
collectDiagnostics: () => "",
cleanupGateway: vi.fn(),
supportsLifecycleCommands: () => true,
});

expect(() =>
handleFailure({
retries: 0,
printError: (message = "") => printed.push(message),
exitProcess: (code): never => {
throw new Error(`exit ${code}`);
},
}),
).toThrow("exit 1");

expect(printed).toContain(" openshell gateway destroy -g nemoclaw-test");
});
});
10 changes: 7 additions & 3 deletions src/lib/onboard/gateway-start-failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { compactText } from "../core/url-utils";
import { redact } from "../security/redact";
import { classifyGatewayStartFailure } from "../validation";
import { gatewayRemovalHintLines } from "./gateway-removal-hint";

const ANSI_RE = /\x1B(?:\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\)|[@-_])/g;

Expand All @@ -14,12 +15,14 @@ export type FinalGatewayStartFailureOptions = {
cleanupGateway?: () => void;
exitProcess?: (code: number) => never;
printError?: (message?: string) => void;
supportsLifecycleCommands?: () => boolean;
};

export type FinalGatewayStartFailureDeps = {
getGatewayName(): string;
collectDiagnostics(): string | null | undefined;
cleanupGateway(): void;
supportsLifecycleCommands?(): boolean;
};

export function normalizeGatewayStartError(error: unknown): Error {
Expand Down Expand Up @@ -66,6 +69,7 @@ export function createFinalGatewayStartFailureHandler(deps: FinalGatewayStartFai
cleanupGateway = deps.cleanupGateway,
exitProcess = (code) => process.exit(code),
printError = (message = "") => console.error(message),
supportsLifecycleCommands = deps.supportsLifecycleCommands ?? (() => false),
}: FinalGatewayStartFailureOptions): never {
if (dockerUnreachable) {
printDockerDaemonRecovery(printError);
Expand Down Expand Up @@ -107,9 +111,9 @@ export function createFinalGatewayStartFailureHandler(deps: FinalGatewayStartFai
printError(" openshell doctor check");
printError("");
printError(" If gateway cleanup did not complete, run:");
printError(` openshell gateway remove ${gatewayName}`);
printError(" # For OpenShell releases that still expose lifecycle commands:");
printError(` openshell gateway destroy -g ${gatewayName}`);
for (const line of gatewayRemovalHintLines(gatewayName, supportsLifecycleCommands())) {
printError(line);
}
if (process.platform === "linux") {
printError(
" sudo pkill -f openshell-gateway # if a privileged host gateway process remains",
Expand Down
25 changes: 22 additions & 3 deletions src/lib/onboard/gpu-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ describe("gpuPassthroughRecoveryLines", () => {
expect(joined).toContain("Existing gateway was started without GPU passthrough");
expect(joined).toContain("attempted safe gateway replacement automatically");
expect(joined).toContain("openshell gateway remove nemoclaw");
expect(joined).toContain("openshell gateway destroy -g nemoclaw");
expect(joined).not.toContain("openshell gateway destroy -g nemoclaw");
expect(joined).toContain("sudo pkill -f openshell-gateway");
expect(joined).toContain("nemoclaw onboard --gpu");
expect(joined).not.toContain("nemoclaw uninstall");
// Must NOT suggest the per-sandbox `nemoclaw <name> destroy` form — there
// is nothing to destroy. (`openshell gateway destroy -g` is fine; it's
// the legacy gateway-lifecycle verb, not a sandbox destroy.)
// is nothing to destroy. The legacy `openshell gateway destroy -g` verb is
// also absent: current OpenShell rejects it (#8139).
expect(joined).not.toMatch(/nemoclaw [a-z-]+ destroy/);
});

Expand Down Expand Up @@ -90,6 +90,25 @@ describe("gpuPassthroughRecoveryLines", () => {
expect(joined).not.toContain("destroy --yes");
expect(joined).not.toContain("nemoclaw onboard --gpu");
});

it("emits the legacy gateway destroy verb only when the installed OpenShell advertises it (#8139)", () => {
const modern = gpuPassthroughRecoveryLines([], { supportsLifecycleCommands: false }).join("\n");
expect(modern).toContain("openshell gateway remove nemoclaw");
expect(modern).not.toContain("gateway destroy");

const legacy = gpuPassthroughRecoveryLines([], { supportsLifecycleCommands: true }).join("\n");
expect(legacy).toContain("openshell gateway remove nemoclaw");
expect(legacy).toContain("openshell gateway destroy -g nemoclaw");
});

it("keeps the legacy verb out of the sandbox-destroy branches regardless of CLI support", () => {
for (const names of [["alpha"], ["alpha", "beta"]]) {
const joined = gpuPassthroughRecoveryLines(names, {
supportsLifecycleCommands: true,
}).join("\n");
expect(joined).not.toContain("gateway destroy");
}
});
});

describe("reportGpuPassthroughRecovery", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/onboard/gpu-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
*/

import * as registry from "../state/registry";
import { gatewayRemovalHintLines } from "./gateway-removal-hint";

export type GpuPassthroughRecoveryOptions = {
missingRuntimePlatform?: "jetson" | null;
supportsLifecycleCommands?: boolean;
};

/**
Expand Down Expand Up @@ -53,9 +55,7 @@ export function gpuPassthroughRecoveryLines(
" Existing gateway was started without GPU passthrough.",
" No sandboxes are registered, so onboard attempted safe gateway replacement automatically.",
" If the retry still fails, clear the stale gateway state and re-onboard with GPU enabled:",
" openshell gateway remove nemoclaw",
" # For OpenShell releases that still expose lifecycle commands:",
" openshell gateway destroy -g nemoclaw",
...gatewayRemovalHintLines("nemoclaw", options.supportsLifecycleCommands ?? false),
" sudo pkill -f openshell-gateway # if a privileged host gateway process remains",
" nemoclaw onboard --gpu",
];
Expand Down
Loading
Loading