From 49ee46190482a004a0421be2d87d371dca4a3113 Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Tue, 26 May 2026 18:05:47 -0700 Subject: [PATCH 1/4] fix(onboard): handle WSL Docker Desktop CDI remediation Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- docs/reference/troubleshooting.mdx | 9 +- scripts/install.sh | 8 +- src/lib/onboard/preflight.test.ts | 80 +++++++++++++++++ src/lib/onboard/preflight.ts | 26 +++++- src/lib/onboard/sandbox-gpu-preflight.test.ts | 65 ++++++++++++++ src/lib/onboard/sandbox-gpu-preflight.ts | 88 ++++++++++++++++++- test/install-preflight.test.ts | 32 ++++++- 7 files changed, 301 insertions(+), 7 deletions(-) diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index 9dce909ec42..19cdff7740f 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -1172,7 +1172,8 @@ Recent NVIDIA Container Toolkit installs configure the Docker daemon for Contain If no `nvidia.com/gpu` CDI spec has been generated on the host yet, gateway start fails with `Docker responded with status code 500: CDI device injection failed: unresolvable CDI devices nvidia.com/gpu=all`. The standard NemoClaw installer detects this gap before onboarding, first tries to enable the NVIDIA CDI refresh systemd units, and falls back to generating the spec directly with `nvidia-ctk`. If you run `nemoclaw onboard` directly, preflight prints the manual remediation instead. -The underlying fix is the same on any Docker host whose `docker info` advertises a non-empty `CDISpecDirs`. +The native Linux fix is the same on Docker hosts whose `docker info` advertises a non-empty `CDISpecDirs`. +On WSL with Docker Desktop, repair Docker Desktop GPU support from the Windows/Docker Desktop side instead of installing Linux host toolkit packages inside the WSL distro. Enable the refresh units, verify they list `nvidia.com/gpu` entries, then rerun onboarding: @@ -1192,6 +1193,12 @@ $ nvidia-ctk cdi list If GPU passthrough is not required on this host, rerun onboarding with `--no-gpu` instead. +On WSL with Docker Desktop, confirm Docker Desktop WSL integration is enabled for your distro, restart Docker Desktop, and verify GPU access from WSL: + +```console +$ docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark +``` + ### Docker GPU patch failed during sandbox create On Linux Docker-driver gateways, NemoClaw may create the sandbox first and then recreate the OpenShell-managed Docker container with NVIDIA GPU flags. diff --git a/scripts/install.sh b/scripts/install.sh index 1a5b5edc112..188f33daf63 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1823,9 +1823,13 @@ repair_installer_nvidia_cdi_spec() { node -e ' const preflightPath = process.argv[1]; try { - const { assessHost, getNvidiaCdiSpecPath } = require(preflightPath); + const { assessHost, getNvidiaCdiSpecPath, isWslDockerDesktopRuntime } = require(preflightPath); const host = assessHost(); - if (host && host.cdiNvidiaGpuSpecMissing) { + if ( + host && + host.cdiNvidiaGpuSpecMissing && + !isWslDockerDesktopRuntime(host) + ) { process.stdout.write(getNvidiaCdiSpecPath(host)); } } catch { diff --git a/src/lib/onboard/preflight.test.ts b/src/lib/onboard/preflight.test.ts index 7c87d8d3814..ac3203994d7 100644 --- a/src/lib/onboard/preflight.test.ts +++ b/src/lib/onboard/preflight.test.ts @@ -13,6 +13,7 @@ import { getNvidiaCdiSpecPath, ensureSwap, isDockerUnderProvisioned, + isWslDockerDesktopRuntime, MIN_RECOMMENDED_DOCKER_CPUS, MIN_RECOMMENDED_DOCKER_MEM_GIB, parseDockerCdiSpecDirs, @@ -839,6 +840,14 @@ describe("getNvidiaCdiSpecPath", () => { }); }); +describe("isWslDockerDesktopRuntime", () => { + it("only matches Docker Desktop-backed WSL hosts", () => { + expect(isWslDockerDesktopRuntime({ isWsl: true, runtime: "docker-desktop" })).toBe(true); + expect(isWslDockerDesktopRuntime({ isWsl: true, runtime: "docker" })).toBe(false); + expect(isWslDockerDesktopRuntime({ isWsl: false, runtime: "docker-desktop" })).toBe(false); + }); +}); + describe("planHostRemediation", () => { it("recommends starting docker when installed but unreachable and service inactive", () => { const actions = planHostRemediation({ @@ -1105,6 +1114,77 @@ describe("planHostRemediation", () => { expect(ctkGenerateIndex).toBeGreaterThan(ctkInstallIndex); }); + it("uses Docker Desktop remediation instead of Linux toolkit commands on WSL Docker Desktop", () => { + const actions = planHostRemediation({ + platform: "linux", + isWsl: true, + runtime: "docker-desktop", + packageManager: "apt", + systemctlAvailable: true, + dockerServiceActive: null, + dockerServiceEnabled: null, + dockerInstalled: true, + dockerRunning: true, + dockerReachable: true, + nodeInstalled: true, + openshellInstalled: true, + dockerCgroupVersion: "v2", + dockerDefaultCgroupnsMode: "unknown", + isContainerRuntimeUnderProvisioned: false, + hasNestedOverlayConflict: false, + requiresHostCgroupnsFix: false, + isUnsupportedRuntime: false, + isHeadlessLikely: false, + hasNvidiaGpu: true, + dockerCdiSpecDirs: ["/etc/cdi", "/var/run/cdi"], + cdiNvidiaGpuSpecMissing: true, + nvidiaContainerToolkitInstalled: false, + notes: ["Running under WSL"], + }); + + expect(actions.find((entry) => entry.id === "install_nvidia_container_toolkit")).toBeUndefined(); + const action = actions.find((entry) => entry.id === "repair_wsl_docker_desktop_gpu_cdi"); + expect(action).toBeTruthy(); + expect(action?.kind).toBe("manual"); + expect(action?.blocking).toBe(true); + expect(action?.title).toContain("Docker Desktop"); + expect(action?.commands.join("\n")).toContain("Docker Desktop Settings"); + expect(action?.commands.join("\n")).not.toContain("nvidia-ctk"); + expect(action?.commands.join("\n")).not.toContain("nvidia-container-toolkit"); + }); + + it("keeps NVIDIA Container Toolkit remediation for native Docker Engine inside WSL", () => { + const actions = planHostRemediation({ + platform: "linux", + isWsl: true, + runtime: "docker", + packageManager: "apt", + systemctlAvailable: true, + dockerServiceActive: true, + dockerServiceEnabled: true, + dockerInstalled: true, + dockerRunning: true, + dockerReachable: true, + nodeInstalled: true, + openshellInstalled: true, + dockerCgroupVersion: "v2", + dockerDefaultCgroupnsMode: "unknown", + isContainerRuntimeUnderProvisioned: false, + hasNestedOverlayConflict: false, + requiresHostCgroupnsFix: false, + isUnsupportedRuntime: false, + isHeadlessLikely: false, + hasNvidiaGpu: true, + dockerCdiSpecDirs: ["/etc/cdi", "/var/run/cdi"], + cdiNvidiaGpuSpecMissing: true, + nvidiaContainerToolkitInstalled: false, + notes: ["Running under WSL"], + }); + + expect(actions.find((entry) => entry.id === "repair_wsl_docker_desktop_gpu_cdi")).toBeUndefined(); + expect(actions.find((entry) => entry.id === "install_nvidia_container_toolkit")).toBeTruthy(); + }); + it("emits an install_nvidia_container_toolkit action with a docs pointer when nvidia-ctk is missing on unknown package managers", () => { const actions = planHostRemediation({ platform: "linux", diff --git a/src/lib/onboard/preflight.ts b/src/lib/onboard/preflight.ts index bff95ed83c7..bddd4068e7b 100644 --- a/src/lib/onboard/preflight.ts +++ b/src/lib/onboard/preflight.ts @@ -301,6 +301,12 @@ export function getNvidiaCdiSpecPath( return path.join(normalizeCdiSpecDir(assessment.dockerCdiSpecDirs[0]), "nvidia.yaml"); } +export function isWslDockerDesktopRuntime( + assessment: Pick, +): boolean { + return assessment.isWsl && assessment.runtime === "docker-desktop"; +} + // True when at least one CDI spec under the configured directories declares // `kind: nvidia.com/gpu` (the device class OpenShell injects with `--gpu`). // Specs are typically YAML, but the JSON shape is also accepted because @@ -809,7 +815,25 @@ export function planHostRemediation(assessment: HostAssessment): RemediationActi "nvidia-ctk cdi list # verify nvidia.com/gpu entries appear", "nemoclaw onboard # or rerun with --no-gpu to skip GPU passthrough", ]; - if (assessment.nvidiaContainerToolkitInstalled) { + if (isWslDockerDesktopRuntime(assessment)) { + actions.push({ + id: "repair_wsl_docker_desktop_gpu_cdi", + title: "Repair Docker Desktop WSL GPU support", + kind: "manual", + reason: + "Docker Desktop is configured for CDI device injection (CDISpecDirs is set) but no " + + "nvidia.com/gpu CDI spec is visible from WSL. Installing or running Linux host " + + "NVIDIA Container Toolkit commands inside the WSL distro may not repair Docker " + + "Desktop's managed Docker daemon. OpenShell's `gateway start --gpu` will fail with " + + "`unresolvable CDI devices nvidia.com/gpu=all` until Docker Desktop GPU support is repaired.", + commands: [ + "Open Docker Desktop Settings > Resources > WSL integration and confirm this distro is enabled.", + "Restart Docker Desktop, then verify GPU support from WSL with `docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark`.", + "Rerun `nemoclaw onboard`, or rerun with `--no-gpu` to skip GPU passthrough.", + ], + blocking: true, + }); + } else if (assessment.nvidiaContainerToolkitInstalled) { actions.push({ id: "generate_nvidia_cdi_spec", title: "Generate NVIDIA CDI device specs", diff --git a/src/lib/onboard/sandbox-gpu-preflight.test.ts b/src/lib/onboard/sandbox-gpu-preflight.test.ts index 806b051031d..1dd25b568ed 100644 --- a/src/lib/onboard/sandbox-gpu-preflight.test.ts +++ b/src/lib/onboard/sandbox-gpu-preflight.test.ts @@ -13,6 +13,7 @@ import { dockerNvidiaRuntimeAvailable, formatSandboxGpuPassthroughNote, parseDockerRuntimeNames, + sandboxGpuRemediationLines, validateSandboxGpuPreflight, } from "./sandbox-gpu-preflight"; @@ -92,6 +93,70 @@ describe("sandbox GPU preflight", () => { expect(dockerInfo).not.toHaveBeenCalled(); }); + it("prints Docker Desktop WSL remediation when CDI support is missing there", () => { + const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); + const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number | string | null) => { + throw new Error(`exit:${code}`); + }) as never); + + try { + expect(() => + validateSandboxGpuPreflight(sandboxGpuConfig(), { + platform: "linux", + env: { WSL_DISTRO_NAME: "Ubuntu" }, + dockerInfoFormat: vi.fn(() => '"Docker Desktop"'), + getDockerCdiSpecDirs: vi.fn(() => ["/etc/cdi"]), + findReadableNvidiaCdiSpecFiles: vi.fn(() => []), + }), + ).toThrow("exit:1"); + const message = errorSpy.mock.calls.map((call) => call[0]).join("\n"); + expect(message).toContain("Docker Desktop WSL GPU support was not detected"); + expect(message).toContain("Docker Desktop Settings"); + expect(message).not.toContain("sudo nvidia-ctk"); + expect(message).not.toContain("sudo systemctl restart docker"); + } finally { + errorSpy.mockRestore(); + exitSpy.mockRestore(); + } + }); + + it("prints neutral WSL remediation when Docker runtime cannot be determined", () => { + const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); + const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number | string | null) => { + throw new Error(`exit:${code}`); + }) as never); + + try { + expect(() => + validateSandboxGpuPreflight(sandboxGpuConfig(), { + platform: "linux", + env: { WSL_DISTRO_NAME: "Ubuntu" }, + dockerInfoFormat: vi.fn(() => ""), + getDockerCdiSpecDirs: vi.fn(() => ["/etc/cdi"]), + findReadableNvidiaCdiSpecFiles: vi.fn(() => []), + }), + ).toThrow("exit:1"); + const message = errorSpy.mock.calls.map((call) => call[0]).join("\n"); + expect(message).toContain("could not determine whether Docker is Docker Desktop"); + expect(message).toContain("If using Docker Desktop"); + expect(message).toContain("If using native Docker Engine inside WSL"); + expect(message).not.toContain("sudo systemctl restart docker"); + } finally { + errorSpy.mockRestore(); + exitSpy.mockRestore(); + } + }); + + it("keeps generic Linux CDI remediation outside Docker Desktop WSL", () => { + expect(sandboxGpuRemediationLines().join("\n")).toContain("sudo nvidia-ctk"); + expect(sandboxGpuRemediationLines({ wslDockerDesktop: true }).join("\n")).toContain( + "Docker Desktop WSL", + ); + expect(sandboxGpuRemediationLines({ wslDockerDesktopStatus: "unknown" }).join("\n")).toContain( + "could not determine", + ); + }); + it("treats optional direct sandbox GPU proof failures as non-fatal", () => { const runOpenshell = vi.fn(() => ({ status: 1, stdout: "", stderr: "optional proof failed" })); const verifier = createDirectSandboxGpuVerifier({ diff --git a/src/lib/onboard/sandbox-gpu-preflight.ts b/src/lib/onboard/sandbox-gpu-preflight.ts index 31653f65688..0ac847cb9cc 100644 --- a/src/lib/onboard/sandbox-gpu-preflight.ts +++ b/src/lib/onboard/sandbox-gpu-preflight.ts @@ -1,14 +1,23 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import fs from "node:fs"; +import os from "node:os"; + import { dockerInfoFormat } from "../adapters/docker"; import { findReadableNvidiaCdiSpecFiles, getDockerCdiSpecDirs } from "./docker-cdi"; import type { SandboxGpuConfig, SandboxGpuFlag } from "./sandbox-gpu-mode"; const SANDBOX_GPU_PREFLIGHT_TIMEOUT_MS = 30_000; +type WslDockerDesktopStatus = "docker-desktop" | "not-docker-desktop" | "unknown"; + export type SandboxGpuPreflightDeps = { platform?: NodeJS.Platform; + env?: NodeJS.ProcessEnv; + release?: string; + procVersion?: string; + readFileImpl?: (filePath: string, encoding: BufferEncoding) => string; dockerInfoFormat?: (format: string, opts?: Record) => string; getDockerCdiSpecDirs?: () => string[]; findReadableNvidiaCdiSpecFiles?: (dirs: string[]) => string[]; @@ -41,7 +50,78 @@ export function resolveSandboxGpuFlagFromOptions(opts: SandboxGpuFlagOptions): S return null; } -export function sandboxGpuRemediationLines(): string[] { +function detectWsl( + deps: Pick< + SandboxGpuPreflightDeps, + "env" | "platform" | "procVersion" | "readFileImpl" | "release" + >, +): boolean { + const platform = deps.platform ?? process.platform; + if (platform !== "linux") return false; + const env = deps.env ?? process.env; + if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return true; + const release = deps.release ?? os.release(); + if (/microsoft/i.test(release)) return true; + const procVersion = + deps.procVersion ?? + (() => { + try { + const readFileImpl = + deps.readFileImpl ?? + ((filePath: string, encoding: BufferEncoding) => fs.readFileSync(filePath, encoding)); + return readFileImpl("/proc/version", "utf-8"); + } catch { + return ""; + } + })(); + return /microsoft/i.test(procVersion); +} + +function detectDockerDesktopRuntime(deps: SandboxGpuPreflightDeps): WslDockerDesktopStatus { + const dockerInfo = deps.dockerInfoFormat ?? dockerInfoFormat; + try { + const output = String( + dockerInfo("{{json .OperatingSystem}}", { + ignoreError: true, + timeout: SANDBOX_GPU_PREFLIGHT_TIMEOUT_MS, + }), + ).trim(); + if (!output || output === "") return "unknown"; + return /^"?docker desktop\b/i.test(output) ? "docker-desktop" : "not-docker-desktop"; + } catch { + return "unknown"; + } +} + +function detectWslDockerDesktopStatus(deps: SandboxGpuPreflightDeps): WslDockerDesktopStatus { + if (!detectWsl(deps)) return "not-docker-desktop"; + return detectDockerDesktopRuntime(deps); +} + +export function sandboxGpuRemediationLines( + options: { wslDockerDesktop?: boolean; wslDockerDesktopStatus?: WslDockerDesktopStatus } = {}, +): string[] { + const status = + options.wslDockerDesktopStatus ?? + (options.wslDockerDesktop ? "docker-desktop" : "not-docker-desktop"); + if (status === "docker-desktop") { + return [ + "Docker Desktop WSL GPU support was not detected.", + "Open Docker Desktop Settings > Resources > WSL integration and confirm this distro is enabled.", + "Restart Docker Desktop, then verify from WSL:", + " docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark", + "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", + ]; + } + if (status === "unknown") { + return [ + "WSL detected, but NemoClaw could not determine whether Docker is Docker Desktop or native Docker Engine.", + "If using Docker Desktop, confirm Settings > Resources > WSL integration is enabled for this distro, restart Docker Desktop, and verify:", + " docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark", + "If using native Docker Engine inside WSL, install/configure NVIDIA Container Toolkit CDI, then restart Docker.", + "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", + ]; + } return [ "Install/configure NVIDIA Container Toolkit CDI, then restart Docker:", " sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml", @@ -191,7 +271,11 @@ export function validateSandboxGpuPreflight( if (cdiSpecFiles.length === 0) { console.error(""); console.error(" ✗ Docker CDI GPU support was not detected."); - for (const line of sandboxGpuRemediationLines()) console.error(` ${line}`); + for (const line of sandboxGpuRemediationLines({ + wslDockerDesktopStatus: detectWslDockerDesktopStatus(deps), + })) { + console.error(` ${line}`); + } process.exit(1); } console.log(` ✓ Docker CDI GPU support detected (${cdiSpecFiles.join(", ")})`); diff --git a/test/install-preflight.test.ts b/test/install-preflight.test.ts index 5336a00d4cb..66e5b6c78c4 100644 --- a/test/install-preflight.test.ts +++ b/test/install-preflight.test.ts @@ -1220,8 +1220,12 @@ fi`, function runNvidiaCdiInstallerRepairTest({ systemctlScript, + isWsl = false, + runtime = "docker", }: { systemctlScript: string; + isWsl?: boolean; + runtime?: string; }) { const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-install-cdi-repair-")); const fakeBin = path.join(tmp, "bin"); @@ -1238,13 +1242,16 @@ fi`, ` const fs = require("fs"); exports.assessHost = () => ({ - runtime: "docker", + runtime: ${JSON.stringify(runtime)}, + isWsl: ${isWsl ? "true" : "false"}, notes: [], dockerCdiSpecDirs: [process.env.CDI_DIR], cdiNvidiaGpuSpecMissing: !fs.existsSync(process.env.CDI_STATE), }); exports.getNvidiaCdiSpecPath = (host) => String(host.dockerCdiSpecDirs[0]).replace(/\\/+$/, "") + "/nvidia.yaml"; +exports.isWslDockerDesktopRuntime = (host) => + Boolean(host && host.isWsl && host.runtime === "docker-desktop"); exports.planHostRemediation = (host) => host.cdiNvidiaGpuSpecMissing ? [{ @@ -1330,6 +1337,7 @@ run_installer_host_preflight cdiDir, output: `${result.stdout}${result.stderr}`, result, + cdiStateExists: fs.existsSync(cdiState), sudoLog: fs.existsSync(sudoLog) ? fs.readFileSync(sudoLog, "utf-8") : "", systemctlLog: fs.existsSync(systemctlLog) ? fs.readFileSync(systemctlLog, "utf-8") : "", }; @@ -1394,6 +1402,28 @@ exit 1 expect(sudoLog).toContain(`nvidia-ctk cdi generate --output=${cdiDir}/nvidia.yaml`); }); + it("skips Linux NVIDIA CDI auto-repair on WSL Docker Desktop", () => { + const { cdiStateExists, output, result, sudoLog, systemctlLog } = + runNvidiaCdiInstallerRepairTest({ + isWsl: true, + runtime: "docker-desktop", + systemctlScript: `#!/usr/bin/env bash +set -euo pipefail +printf '%s\\n' "$*" >> "$SYSTEMCTL_LOG" +touch "$CDI_STATE" +exit 0 +`, + }); + + expect(result.status, output).toBe(1); + expect(cdiStateExists).toBe(false); + expect(output).toMatch(/Host preflight found issues/); + expect(output).not.toMatch(/Trying NVIDIA CDI refresh service/); + expect(output).not.toMatch(/Generated NVIDIA CDI device spec/); + expect(systemctlLog).toBe(""); + expect(sudoLog).toBe(""); + }); + it("warns on Podman but still runs onboarding", () => { const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-install-podman-warning-")); const fakeBin = path.join(tmp, "bin"); From 9fbf939636d8553fc056a38e6a33fd7877781489 Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Tue, 26 May 2026 22:53:11 -0700 Subject: [PATCH 2/4] fix(onboard): allow WSL Docker Desktop GPU setup to use Docker --gpus Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- docs/reference/troubleshooting.mdx | 9 +++--- src/lib/onboard.ts | 1 + src/lib/onboard/preflight.test.ts | 12 ++++---- src/lib/onboard/preflight.ts | 20 ++++++------- src/lib/onboard/sandbox-gpu-preflight.test.ts | 28 +++++++++---------- src/lib/onboard/sandbox-gpu-preflight.ts | 15 +++++++--- test/install-preflight.test.ts | 24 ++++++++++------ 7 files changed, 61 insertions(+), 48 deletions(-) diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index 19cdff7740f..e51446b5bb5 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -1173,7 +1173,8 @@ If no `nvidia.com/gpu` CDI spec has been generated on the host yet, gateway star The standard NemoClaw installer detects this gap before onboarding, first tries to enable the NVIDIA CDI refresh systemd units, and falls back to generating the spec directly with `nvidia-ctk`. If you run `nemoclaw onboard` directly, preflight prints the manual remediation instead. The native Linux fix is the same on Docker hosts whose `docker info` advertises a non-empty `CDISpecDirs`. -On WSL with Docker Desktop, repair Docker Desktop GPU support from the Windows/Docker Desktop side instead of installing Linux host toolkit packages inside the WSL distro. +On WSL with Docker Desktop, Docker may advertise CDI directories even though `--device nvidia.com/gpu=all` is not usable from the WSL distro. +For that runtime, NemoClaw skips Linux CDI repair and uses Docker's `--gpus` compatibility path for sandbox GPU access. Enable the refresh units, verify they list `nvidia.com/gpu` entries, then rerun onboarding: @@ -1191,14 +1192,14 @@ $ sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml $ nvidia-ctk cdi list ``` -If GPU passthrough is not required on this host, rerun onboarding with `--no-gpu` instead. - -On WSL with Docker Desktop, confirm Docker Desktop WSL integration is enabled for your distro, restart Docker Desktop, and verify GPU access from WSL: +On WSL with Docker Desktop, confirm Docker Desktop WSL integration is enabled for your distro and verify Docker GPU access from WSL: ```console $ docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark ``` +If GPU passthrough is not required on this host, rerun onboarding with `--no-gpu` instead. + ### Docker GPU patch failed during sandbox create On Linux Docker-driver gateways, NemoClaw may create the sandbox first and then recreate the OpenShell-managed Docker container with NVIDIA GPU flags. diff --git a/src/lib/onboard.ts b/src/lib/onboard.ts index 2a4706f61ff..d61cb9af964 100644 --- a/src/lib/onboard.ts +++ b/src/lib/onboard.ts @@ -1788,6 +1788,7 @@ function assertCdiNvidiaGpuSpecPresent( hostGpuPlatform: string | null | undefined = null, ): void { if (hostGpuPlatform === "jetson") return; + if (preflightUtils.isWslDockerDesktopRuntime(host)) return; if (!host.cdiNvidiaGpuSpecMissing || optedOutGpuPassthrough) return; console.error( " Docker is configured for CDI device injection (CDISpecDirs is set), but no", diff --git a/src/lib/onboard/preflight.test.ts b/src/lib/onboard/preflight.test.ts index ac3203994d7..4d585c498c0 100644 --- a/src/lib/onboard/preflight.test.ts +++ b/src/lib/onboard/preflight.test.ts @@ -1114,7 +1114,7 @@ describe("planHostRemediation", () => { expect(ctkGenerateIndex).toBeGreaterThan(ctkInstallIndex); }); - it("uses Docker Desktop remediation instead of Linux toolkit commands on WSL Docker Desktop", () => { + it("uses non-blocking Docker Desktop GPU compatibility guidance on WSL Docker Desktop", () => { const actions = planHostRemediation({ platform: "linux", isWsl: true, @@ -1143,12 +1143,12 @@ describe("planHostRemediation", () => { }); expect(actions.find((entry) => entry.id === "install_nvidia_container_toolkit")).toBeUndefined(); - const action = actions.find((entry) => entry.id === "repair_wsl_docker_desktop_gpu_cdi"); + const action = actions.find((entry) => entry.id === "wsl_docker_desktop_gpu_compatibility"); expect(action).toBeTruthy(); - expect(action?.kind).toBe("manual"); - expect(action?.blocking).toBe(true); + expect(action?.kind).toBe("info"); + expect(action?.blocking).toBe(false); expect(action?.title).toContain("Docker Desktop"); - expect(action?.commands.join("\n")).toContain("Docker Desktop Settings"); + expect(action?.reason).toContain("--gpus"); expect(action?.commands.join("\n")).not.toContain("nvidia-ctk"); expect(action?.commands.join("\n")).not.toContain("nvidia-container-toolkit"); }); @@ -1181,7 +1181,7 @@ describe("planHostRemediation", () => { notes: ["Running under WSL"], }); - expect(actions.find((entry) => entry.id === "repair_wsl_docker_desktop_gpu_cdi")).toBeUndefined(); + expect(actions.find((entry) => entry.id === "wsl_docker_desktop_gpu_compatibility")).toBeUndefined(); expect(actions.find((entry) => entry.id === "install_nvidia_container_toolkit")).toBeTruthy(); }); diff --git a/src/lib/onboard/preflight.ts b/src/lib/onboard/preflight.ts index bddd4068e7b..7a1d7b1f2c7 100644 --- a/src/lib/onboard/preflight.ts +++ b/src/lib/onboard/preflight.ts @@ -817,21 +817,19 @@ export function planHostRemediation(assessment: HostAssessment): RemediationActi ]; if (isWslDockerDesktopRuntime(assessment)) { actions.push({ - id: "repair_wsl_docker_desktop_gpu_cdi", - title: "Repair Docker Desktop WSL GPU support", - kind: "manual", + id: "wsl_docker_desktop_gpu_compatibility", + title: "Use Docker Desktop WSL GPU compatibility path", + kind: "info", reason: "Docker Desktop is configured for CDI device injection (CDISpecDirs is set) but no " + - "nvidia.com/gpu CDI spec is visible from WSL. Installing or running Linux host " + - "NVIDIA Container Toolkit commands inside the WSL distro may not repair Docker " + - "Desktop's managed Docker daemon. OpenShell's `gateway start --gpu` will fail with " + - "`unresolvable CDI devices nvidia.com/gpu=all` until Docker Desktop GPU support is repaired.", + "nvidia.com/gpu CDI spec is visible from WSL. On Docker Desktop-backed WSL, NemoClaw " + + "uses Docker's `--gpus` compatibility path instead of trying to repair Linux host CDI " + + "from inside the WSL distro.", commands: [ - "Open Docker Desktop Settings > Resources > WSL integration and confirm this distro is enabled.", - "Restart Docker Desktop, then verify GPU support from WSL with `docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark`.", - "Rerun `nemoclaw onboard`, or rerun with `--no-gpu` to skip GPU passthrough.", + "If sandbox GPU setup later fails, verify Docker Desktop GPU support from WSL with `docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark`.", + "Rerun with `--no-gpu` to skip GPU passthrough.", ], - blocking: true, + blocking: false, }); } else if (assessment.nvidiaContainerToolkitInstalled) { actions.push({ diff --git a/src/lib/onboard/sandbox-gpu-preflight.test.ts b/src/lib/onboard/sandbox-gpu-preflight.test.ts index 1dd25b568ed..f9e49028be1 100644 --- a/src/lib/onboard/sandbox-gpu-preflight.test.ts +++ b/src/lib/onboard/sandbox-gpu-preflight.test.ts @@ -93,11 +93,10 @@ describe("sandbox GPU preflight", () => { expect(dockerInfo).not.toHaveBeenCalled(); }); - it("prints Docker Desktop WSL remediation when CDI support is missing there", () => { - const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); - const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number | string | null) => { - throw new Error(`exit:${code}`); - }) as never); + it("skips CDI spec validation on Docker Desktop WSL so Docker --gpus can be used", () => { + const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined); + const getDockerCdiSpecDirs = vi.fn(() => ["/etc/cdi"]); + const findReadableNvidiaCdiSpecFiles = vi.fn(() => []); try { expect(() => @@ -105,18 +104,17 @@ describe("sandbox GPU preflight", () => { platform: "linux", env: { WSL_DISTRO_NAME: "Ubuntu" }, dockerInfoFormat: vi.fn(() => '"Docker Desktop"'), - getDockerCdiSpecDirs: vi.fn(() => ["/etc/cdi"]), - findReadableNvidiaCdiSpecFiles: vi.fn(() => []), + getDockerCdiSpecDirs, + findReadableNvidiaCdiSpecFiles, }), - ).toThrow("exit:1"); - const message = errorSpy.mock.calls.map((call) => call[0]).join("\n"); - expect(message).toContain("Docker Desktop WSL GPU support was not detected"); - expect(message).toContain("Docker Desktop Settings"); - expect(message).not.toContain("sudo nvidia-ctk"); - expect(message).not.toContain("sudo systemctl restart docker"); + ).not.toThrow(); + expect(getDockerCdiSpecDirs).not.toHaveBeenCalled(); + expect(findReadableNvidiaCdiSpecFiles).not.toHaveBeenCalled(); + expect(logSpy.mock.calls.map((call) => call[0]).join("\n")).toContain( + "Docker --gpus compatibility path", + ); } finally { - errorSpy.mockRestore(); - exitSpy.mockRestore(); + logSpy.mockRestore(); } }); diff --git a/src/lib/onboard/sandbox-gpu-preflight.ts b/src/lib/onboard/sandbox-gpu-preflight.ts index 0ac847cb9cc..d4c7660ad58 100644 --- a/src/lib/onboard/sandbox-gpu-preflight.ts +++ b/src/lib/onboard/sandbox-gpu-preflight.ts @@ -106,9 +106,8 @@ export function sandboxGpuRemediationLines( (options.wslDockerDesktop ? "docker-desktop" : "not-docker-desktop"); if (status === "docker-desktop") { return [ - "Docker Desktop WSL GPU support was not detected.", - "Open Docker Desktop Settings > Resources > WSL integration and confirm this distro is enabled.", - "Restart Docker Desktop, then verify from WSL:", + "Docker Desktop WSL detected; NemoClaw uses Docker --gpus compatibility instead of CDI spec validation.", + "If sandbox GPU setup later fails, verify from WSL:", " docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark", "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", ]; @@ -264,6 +263,14 @@ export function validateSandboxGpuPreflight( return; } + const wslDockerDesktopStatus = detectWslDockerDesktopStatus(deps); + if (wslDockerDesktopStatus === "docker-desktop") { + console.log( + " Docker Desktop WSL detected; using Docker --gpus compatibility path instead of CDI spec validation.", + ); + return; + } + const cdiSpecDirs = (deps.getDockerCdiSpecDirs ?? getDockerCdiSpecDirs)(); const cdiSpecFiles = (deps.findReadableNvidiaCdiSpecFiles ?? findReadableNvidiaCdiSpecFiles)( cdiSpecDirs, @@ -272,7 +279,7 @@ export function validateSandboxGpuPreflight( console.error(""); console.error(" ✗ Docker CDI GPU support was not detected."); for (const line of sandboxGpuRemediationLines({ - wslDockerDesktopStatus: detectWslDockerDesktopStatus(deps), + wslDockerDesktopStatus, })) { console.error(` ${line}`); } diff --git a/test/install-preflight.test.ts b/test/install-preflight.test.ts index 66e5b6c78c4..5336fa0cf83 100644 --- a/test/install-preflight.test.ts +++ b/test/install-preflight.test.ts @@ -1254,12 +1254,19 @@ exports.isWslDockerDesktopRuntime = (host) => Boolean(host && host.isWsl && host.runtime === "docker-desktop"); exports.planHostRemediation = (host) => host.cdiNvidiaGpuSpecMissing - ? [{ - title: "Generate NVIDIA CDI device specs", - reason: "missing nvidia.com/gpu", - commands: ["sudo nvidia-ctk cdi generate --output=" + exports.getNvidiaCdiSpecPath(host)], - blocking: true, - }] + ? host.isWsl && host.runtime === "docker-desktop" + ? [{ + title: "Use Docker Desktop WSL GPU compatibility path", + reason: "missing nvidia.com/gpu CDI; using Docker --gpus", + commands: ["verify Docker --gpus support from WSL"], + blocking: false, + }] + : [{ + title: "Generate NVIDIA CDI device specs", + reason: "missing nvidia.com/gpu", + commands: ["sudo nvidia-ctk cdi generate --output=" + exports.getNvidiaCdiSpecPath(host)], + blocking: true, + }] : []; `, ); @@ -1415,9 +1422,10 @@ exit 0 `, }); - expect(result.status, output).toBe(1); + expect(result.status, output).toBe(0); expect(cdiStateExists).toBe(false); - expect(output).toMatch(/Host preflight found issues/); + expect(output).toMatch(/Host preflight found warnings/); + expect(output).toMatch(/Use Docker Desktop WSL GPU compatibility path/); expect(output).not.toMatch(/Trying NVIDIA CDI refresh service/); expect(output).not.toMatch(/Generated NVIDIA CDI device spec/); expect(systemctlLog).toBe(""); From 8321e5abf3f6c05112b59c3e24a8d5e0071c31fd Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Tue, 26 May 2026 23:33:48 -0700 Subject: [PATCH 3/4] refactor(onboard): preserve line budget Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- src/lib/onboard.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/onboard.ts b/src/lib/onboard.ts index d61cb9af964..1b82e33ead9 100644 --- a/src/lib/onboard.ts +++ b/src/lib/onboard.ts @@ -1787,8 +1787,7 @@ function assertCdiNvidiaGpuSpecPresent( optedOutGpuPassthrough: boolean, hostGpuPlatform: string | null | undefined = null, ): void { - if (hostGpuPlatform === "jetson") return; - if (preflightUtils.isWslDockerDesktopRuntime(host)) return; + if (hostGpuPlatform === "jetson" || preflightUtils.isWslDockerDesktopRuntime(host)) return; if (!host.cdiNvidiaGpuSpecMissing || optedOutGpuPassthrough) return; console.error( " Docker is configured for CDI device injection (CDISpecDirs is set), but no", From 4ddcd6feaa99471a8166b432e565d317bd0d4f7b Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Wed, 27 May 2026 08:11:24 -0700 Subject: [PATCH 4/4] fix(onboard): address WSL Docker Desktop GPU review Signed-off-by: Carlos Villela --- docs/reference/troubleshooting.mdx | 1 + src/lib/onboard/preflight.test.ts | 80 ----------- src/lib/onboard/preflight.ts | 27 +--- src/lib/onboard/sandbox-gpu-preflight.test.ts | 25 ++++ src/lib/onboard/sandbox-gpu-preflight.ts | 92 ++---------- .../onboard/wsl-docker-desktop-gpu.test.ts | 66 +++++++++ src/lib/onboard/wsl-docker-desktop-gpu.ts | 134 ++++++++++++++++++ 7 files changed, 245 insertions(+), 180 deletions(-) create mode 100644 src/lib/onboard/wsl-docker-desktop-gpu.test.ts create mode 100644 src/lib/onboard/wsl-docker-desktop-gpu.ts diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index e51446b5bb5..bd94a2b8290 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -1175,6 +1175,7 @@ If you run `nemoclaw onboard` directly, preflight prints the manual remediation The native Linux fix is the same on Docker hosts whose `docker info` advertises a non-empty `CDISpecDirs`. On WSL with Docker Desktop, Docker may advertise CDI directories even though `--device nvidia.com/gpu=all` is not usable from the WSL distro. For that runtime, NemoClaw skips Linux CDI repair and uses Docker's `--gpus` compatibility path for sandbox GPU access. +This compatibility path can be retired once Docker Desktop exposes usable `nvidia.com/gpu` CDI specs inside WSL, or once OpenShell no longer requires host-visible CDI specs for Docker Desktop WSL GPU passthrough. Enable the refresh units, verify they list `nvidia.com/gpu` entries, then rerun onboarding: diff --git a/src/lib/onboard/preflight.test.ts b/src/lib/onboard/preflight.test.ts index 4d585c498c0..7c87d8d3814 100644 --- a/src/lib/onboard/preflight.test.ts +++ b/src/lib/onboard/preflight.test.ts @@ -13,7 +13,6 @@ import { getNvidiaCdiSpecPath, ensureSwap, isDockerUnderProvisioned, - isWslDockerDesktopRuntime, MIN_RECOMMENDED_DOCKER_CPUS, MIN_RECOMMENDED_DOCKER_MEM_GIB, parseDockerCdiSpecDirs, @@ -840,14 +839,6 @@ describe("getNvidiaCdiSpecPath", () => { }); }); -describe("isWslDockerDesktopRuntime", () => { - it("only matches Docker Desktop-backed WSL hosts", () => { - expect(isWslDockerDesktopRuntime({ isWsl: true, runtime: "docker-desktop" })).toBe(true); - expect(isWslDockerDesktopRuntime({ isWsl: true, runtime: "docker" })).toBe(false); - expect(isWslDockerDesktopRuntime({ isWsl: false, runtime: "docker-desktop" })).toBe(false); - }); -}); - describe("planHostRemediation", () => { it("recommends starting docker when installed but unreachable and service inactive", () => { const actions = planHostRemediation({ @@ -1114,77 +1105,6 @@ describe("planHostRemediation", () => { expect(ctkGenerateIndex).toBeGreaterThan(ctkInstallIndex); }); - it("uses non-blocking Docker Desktop GPU compatibility guidance on WSL Docker Desktop", () => { - const actions = planHostRemediation({ - platform: "linux", - isWsl: true, - runtime: "docker-desktop", - packageManager: "apt", - systemctlAvailable: true, - dockerServiceActive: null, - dockerServiceEnabled: null, - dockerInstalled: true, - dockerRunning: true, - dockerReachable: true, - nodeInstalled: true, - openshellInstalled: true, - dockerCgroupVersion: "v2", - dockerDefaultCgroupnsMode: "unknown", - isContainerRuntimeUnderProvisioned: false, - hasNestedOverlayConflict: false, - requiresHostCgroupnsFix: false, - isUnsupportedRuntime: false, - isHeadlessLikely: false, - hasNvidiaGpu: true, - dockerCdiSpecDirs: ["/etc/cdi", "/var/run/cdi"], - cdiNvidiaGpuSpecMissing: true, - nvidiaContainerToolkitInstalled: false, - notes: ["Running under WSL"], - }); - - expect(actions.find((entry) => entry.id === "install_nvidia_container_toolkit")).toBeUndefined(); - const action = actions.find((entry) => entry.id === "wsl_docker_desktop_gpu_compatibility"); - expect(action).toBeTruthy(); - expect(action?.kind).toBe("info"); - expect(action?.blocking).toBe(false); - expect(action?.title).toContain("Docker Desktop"); - expect(action?.reason).toContain("--gpus"); - expect(action?.commands.join("\n")).not.toContain("nvidia-ctk"); - expect(action?.commands.join("\n")).not.toContain("nvidia-container-toolkit"); - }); - - it("keeps NVIDIA Container Toolkit remediation for native Docker Engine inside WSL", () => { - const actions = planHostRemediation({ - platform: "linux", - isWsl: true, - runtime: "docker", - packageManager: "apt", - systemctlAvailable: true, - dockerServiceActive: true, - dockerServiceEnabled: true, - dockerInstalled: true, - dockerRunning: true, - dockerReachable: true, - nodeInstalled: true, - openshellInstalled: true, - dockerCgroupVersion: "v2", - dockerDefaultCgroupnsMode: "unknown", - isContainerRuntimeUnderProvisioned: false, - hasNestedOverlayConflict: false, - requiresHostCgroupnsFix: false, - isUnsupportedRuntime: false, - isHeadlessLikely: false, - hasNvidiaGpu: true, - dockerCdiSpecDirs: ["/etc/cdi", "/var/run/cdi"], - cdiNvidiaGpuSpecMissing: true, - nvidiaContainerToolkitInstalled: false, - notes: ["Running under WSL"], - }); - - expect(actions.find((entry) => entry.id === "wsl_docker_desktop_gpu_compatibility")).toBeUndefined(); - expect(actions.find((entry) => entry.id === "install_nvidia_container_toolkit")).toBeTruthy(); - }); - it("emits an install_nvidia_container_toolkit action with a docs pointer when nvidia-ctk is missing on unknown package managers", () => { const actions = planHostRemediation({ platform: "linux", diff --git a/src/lib/onboard/preflight.ts b/src/lib/onboard/preflight.ts index 7a1d7b1f2c7..22777d85b98 100644 --- a/src/lib/onboard/preflight.ts +++ b/src/lib/onboard/preflight.ts @@ -16,6 +16,11 @@ import os from "node:os"; import path from "node:path"; import { DASHBOARD_PORT } from "../core/ports"; +import { + isWslDockerDesktopRuntime, + wslDockerDesktopGpuCompatibilityAction, +} from "./wsl-docker-desktop-gpu"; +export { isWslDockerDesktopRuntime } from "./wsl-docker-desktop-gpu"; // runner.ts still uses CommonJS-style exports — use require here. const { runCapture } = require("../runner"); @@ -301,12 +306,6 @@ export function getNvidiaCdiSpecPath( return path.join(normalizeCdiSpecDir(assessment.dockerCdiSpecDirs[0]), "nvidia.yaml"); } -export function isWslDockerDesktopRuntime( - assessment: Pick, -): boolean { - return assessment.isWsl && assessment.runtime === "docker-desktop"; -} - // True when at least one CDI spec under the configured directories declares // `kind: nvidia.com/gpu` (the device class OpenShell injects with `--gpu`). // Specs are typically YAML, but the JSON shape is also accepted because @@ -816,21 +815,7 @@ export function planHostRemediation(assessment: HostAssessment): RemediationActi "nemoclaw onboard # or rerun with --no-gpu to skip GPU passthrough", ]; if (isWslDockerDesktopRuntime(assessment)) { - actions.push({ - id: "wsl_docker_desktop_gpu_compatibility", - title: "Use Docker Desktop WSL GPU compatibility path", - kind: "info", - reason: - "Docker Desktop is configured for CDI device injection (CDISpecDirs is set) but no " + - "nvidia.com/gpu CDI spec is visible from WSL. On Docker Desktop-backed WSL, NemoClaw " + - "uses Docker's `--gpus` compatibility path instead of trying to repair Linux host CDI " + - "from inside the WSL distro.", - commands: [ - "If sandbox GPU setup later fails, verify Docker Desktop GPU support from WSL with `docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark`.", - "Rerun with `--no-gpu` to skip GPU passthrough.", - ], - blocking: false, - }); + actions.push(wslDockerDesktopGpuCompatibilityAction()); } else if (assessment.nvidiaContainerToolkitInstalled) { actions.push({ id: "generate_nvidia_cdi_spec", diff --git a/src/lib/onboard/sandbox-gpu-preflight.test.ts b/src/lib/onboard/sandbox-gpu-preflight.test.ts index f9e49028be1..8dfb7bc6256 100644 --- a/src/lib/onboard/sandbox-gpu-preflight.test.ts +++ b/src/lib/onboard/sandbox-gpu-preflight.test.ts @@ -184,6 +184,31 @@ describe("sandbox GPU preflight", () => { expect(() => verifier("demo")).toThrow("GPU proof failed: fatal proof"); }); + it("uses Docker Desktop WSL guidance when direct sandbox GPU proof fails there", () => { + const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); + const verifier = createDirectSandboxGpuVerifier({ + platform: "linux", + env: { WSL_DISTRO_NAME: "Ubuntu" }, + dockerInfoFormat: vi.fn(() => '"Docker Desktop"'), + runOpenshell: vi.fn(() => ({ status: 1, stdout: "", stderr: "required proof failed" })), + buildDirectSandboxGpuProofCommands: vi.fn(() => [ + { args: ["sandbox", "exec", "demo", "--", "false"], label: "fatal proof" }, + ]), + compactText: (value) => value.trim(), + redact: (value) => String(value), + }); + + try { + expect(() => verifier("demo")).toThrow("GPU proof failed: fatal proof"); + const message = errorSpy.mock.calls.map((call) => call[0]).join("\n"); + expect(message).toContain("Docker Desktop WSL"); + expect(message).toContain("--gpus"); + expect(message).not.toContain("sudo nvidia-ctk"); + } finally { + errorSpy.mockRestore(); + } + }); + it("exits with an explicit Jetson NVIDIA runtime message when runtime support is missing", () => { const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number | string | null) => { diff --git a/src/lib/onboard/sandbox-gpu-preflight.ts b/src/lib/onboard/sandbox-gpu-preflight.ts index d4c7660ad58..d3ea20e3699 100644 --- a/src/lib/onboard/sandbox-gpu-preflight.ts +++ b/src/lib/onboard/sandbox-gpu-preflight.ts @@ -1,24 +1,19 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import fs from "node:fs"; -import os from "node:os"; - import { dockerInfoFormat } from "../adapters/docker"; import { findReadableNvidiaCdiSpecFiles, getDockerCdiSpecDirs } from "./docker-cdi"; import type { SandboxGpuConfig, SandboxGpuFlag } from "./sandbox-gpu-mode"; +import { + detectWslDockerDesktopStatus, + type WslDockerDesktopDetectionDeps, + type WslDockerDesktopStatus, + wslDockerDesktopGpuCompatibilityRemediationLines, +} from "./wsl-docker-desktop-gpu"; const SANDBOX_GPU_PREFLIGHT_TIMEOUT_MS = 30_000; -type WslDockerDesktopStatus = "docker-desktop" | "not-docker-desktop" | "unknown"; - -export type SandboxGpuPreflightDeps = { - platform?: NodeJS.Platform; - env?: NodeJS.ProcessEnv; - release?: string; - procVersion?: string; - readFileImpl?: (filePath: string, encoding: BufferEncoding) => string; - dockerInfoFormat?: (format: string, opts?: Record) => string; +export type SandboxGpuPreflightDeps = WslDockerDesktopDetectionDeps & { getDockerCdiSpecDirs?: () => string[]; findReadableNvidiaCdiSpecFiles?: (dirs: string[]) => string[]; }; @@ -50,77 +45,14 @@ export function resolveSandboxGpuFlagFromOptions(opts: SandboxGpuFlagOptions): S return null; } -function detectWsl( - deps: Pick< - SandboxGpuPreflightDeps, - "env" | "platform" | "procVersion" | "readFileImpl" | "release" - >, -): boolean { - const platform = deps.platform ?? process.platform; - if (platform !== "linux") return false; - const env = deps.env ?? process.env; - if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return true; - const release = deps.release ?? os.release(); - if (/microsoft/i.test(release)) return true; - const procVersion = - deps.procVersion ?? - (() => { - try { - const readFileImpl = - deps.readFileImpl ?? - ((filePath: string, encoding: BufferEncoding) => fs.readFileSync(filePath, encoding)); - return readFileImpl("/proc/version", "utf-8"); - } catch { - return ""; - } - })(); - return /microsoft/i.test(procVersion); -} - -function detectDockerDesktopRuntime(deps: SandboxGpuPreflightDeps): WslDockerDesktopStatus { - const dockerInfo = deps.dockerInfoFormat ?? dockerInfoFormat; - try { - const output = String( - dockerInfo("{{json .OperatingSystem}}", { - ignoreError: true, - timeout: SANDBOX_GPU_PREFLIGHT_TIMEOUT_MS, - }), - ).trim(); - if (!output || output === "") return "unknown"; - return /^"?docker desktop\b/i.test(output) ? "docker-desktop" : "not-docker-desktop"; - } catch { - return "unknown"; - } -} - -function detectWslDockerDesktopStatus(deps: SandboxGpuPreflightDeps): WslDockerDesktopStatus { - if (!detectWsl(deps)) return "not-docker-desktop"; - return detectDockerDesktopRuntime(deps); -} - export function sandboxGpuRemediationLines( options: { wslDockerDesktop?: boolean; wslDockerDesktopStatus?: WslDockerDesktopStatus } = {}, ): string[] { const status = options.wslDockerDesktopStatus ?? (options.wslDockerDesktop ? "docker-desktop" : "not-docker-desktop"); - if (status === "docker-desktop") { - return [ - "Docker Desktop WSL detected; NemoClaw uses Docker --gpus compatibility instead of CDI spec validation.", - "If sandbox GPU setup later fails, verify from WSL:", - " docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark", - "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", - ]; - } - if (status === "unknown") { - return [ - "WSL detected, but NemoClaw could not determine whether Docker is Docker Desktop or native Docker Engine.", - "If using Docker Desktop, confirm Settings > Resources > WSL integration is enabled for this distro, restart Docker Desktop, and verify:", - " docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark", - "If using native Docker Engine inside WSL, install/configure NVIDIA Container Toolkit CDI, then restart Docker.", - "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", - ]; - } + const wslRemediationLines = wslDockerDesktopGpuCompatibilityRemediationLines(status); + if (wslRemediationLines) return wslRemediationLines; return [ "Install/configure NVIDIA Container Toolkit CDI, then restart Docker:", " sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml", @@ -205,7 +137,7 @@ function validateJetsonSandboxGpuPreflight(deps: SandboxGpuPreflightDeps): void console.log(" ✓ Docker NVIDIA runtime detected for Jetson/Tegra sandbox GPU"); } -export interface DirectSandboxGpuVerifierDeps { +export interface DirectSandboxGpuVerifierDeps extends WslDockerDesktopDetectionDeps { runOpenshell( args: string[], opts?: Record, @@ -239,7 +171,9 @@ export function createDirectSandboxGpuVerifier(deps: DirectSandboxGpuVerifierDep const diagnostic = deps.compactText(deps.redact(`${result.stderr || ""} ${result.stdout || ""}`)); console.error(` ✗ GPU proof failed: ${proof.label}`); if (diagnostic) console.error(` ${diagnostic.slice(0, 300)}`); - for (const line of sandboxGpuRemediationLines()) { + for (const line of sandboxGpuRemediationLines({ + wslDockerDesktopStatus: detectWslDockerDesktopStatus(deps), + })) { console.error(` ${line}`); } const statusText = String(result.status || 1); diff --git a/src/lib/onboard/wsl-docker-desktop-gpu.test.ts b/src/lib/onboard/wsl-docker-desktop-gpu.test.ts new file mode 100644 index 00000000000..e0103f978be --- /dev/null +++ b/src/lib/onboard/wsl-docker-desktop-gpu.test.ts @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it, vi } from "vitest"; + +vi.mock("../adapters/docker", () => ({ + dockerInfoFormat: vi.fn(), +})); + +import { + detectWslDockerDesktopStatus, + isWslDockerDesktopRuntime, + WSL_DOCKER_DESKTOP_GPU_COMPATIBILITY_REMOVAL_CONDITION, + wslDockerDesktopGpuCompatibilityAction, + wslDockerDesktopGpuCompatibilityRemediationLines, +} from "./wsl-docker-desktop-gpu"; + +describe("WSL Docker Desktop GPU compatibility helpers", () => { + it("only matches Docker Desktop-backed WSL host assessments", () => { + expect(isWslDockerDesktopRuntime({ isWsl: true, runtime: "docker-desktop" })).toBe(true); + expect(isWslDockerDesktopRuntime({ isWsl: true, runtime: "docker" })).toBe(false); + expect(isWslDockerDesktopRuntime({ isWsl: false, runtime: "docker-desktop" })).toBe(false); + }); + + it("detects Docker Desktop status only after WSL detection succeeds", () => { + const dockerInfoFormat = vi.fn(() => '"Docker Desktop"'); + expect( + detectWslDockerDesktopStatus({ + platform: "linux", + env: { WSL_DISTRO_NAME: "Ubuntu" }, + dockerInfoFormat, + }), + ).toBe("docker-desktop"); + expect(dockerInfoFormat).toHaveBeenCalledWith( + "{{json .OperatingSystem}}", + expect.objectContaining({ ignoreError: true }), + ); + + expect( + detectWslDockerDesktopStatus({ + platform: "linux", + env: {}, + release: "6.8.0-generic", + procVersion: "Linux version 6.8.0-generic", + dockerInfoFormat: vi.fn(() => '"Docker Desktop"'), + }), + ).toBe("not-docker-desktop"); + }); + + it("centralizes non-blocking Docker --gpus remediation and its removal condition", () => { + const action = wslDockerDesktopGpuCompatibilityAction(); + expect(action.kind).toBe("info"); + expect(action.blocking).toBe(false); + expect(action.reason).toContain("--gpus"); + expect(action.commands.join("\n")).not.toContain("nvidia-ctk"); + + expect(wslDockerDesktopGpuCompatibilityRemediationLines("docker-desktop")?.join("\n")).toContain( + "Docker --gpus compatibility", + ); + expect(wslDockerDesktopGpuCompatibilityRemediationLines("unknown")?.join("\n")).toContain( + "could not determine whether Docker is Docker Desktop", + ); + expect(wslDockerDesktopGpuCompatibilityRemediationLines("not-docker-desktop")).toBeNull(); + expect(WSL_DOCKER_DESKTOP_GPU_COMPATIBILITY_REMOVAL_CONDITION).toContain("Remove"); + }); +}); diff --git a/src/lib/onboard/wsl-docker-desktop-gpu.ts b/src/lib/onboard/wsl-docker-desktop-gpu.ts new file mode 100644 index 00000000000..a8870bbac37 --- /dev/null +++ b/src/lib/onboard/wsl-docker-desktop-gpu.ts @@ -0,0 +1,134 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import os from "node:os"; + +import { dockerInfoFormat as defaultDockerInfoFormat } from "../adapters/docker"; + +const WSL_DOCKER_DESKTOP_DETECTION_TIMEOUT_MS = 30_000; +export const WSL_DOCKER_DESKTOP_GPU_PROOF_COMMAND = + "docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark"; + +// Source-of-truth for this compatibility branch: Docker Desktop-backed WSL can +// advertise Docker CDI directories while the WSL distro cannot see a usable +// nvidia.com/gpu CDI spec. Retire this workaround only after Docker Desktop +// exposes usable nvidia.com/gpu CDI specs into WSL, or after OpenShell owns a +// Docker Desktop WSL GPU path that no longer relies on host-visible CDI specs. +export const WSL_DOCKER_DESKTOP_GPU_COMPATIBILITY_REMOVAL_CONDITION = + "Remove this compatibility path when Docker Desktop exposes usable nvidia.com/gpu CDI specs into WSL, or OpenShell no longer requires host-visible CDI specs for Docker Desktop WSL GPU passthrough."; + +export type WslDockerDesktopStatus = "docker-desktop" | "not-docker-desktop" | "unknown"; + +export type WslDockerDesktopHost = { + isWsl: boolean; + runtime?: string | null; +}; + +export type WslDockerDesktopDetectionDeps = { + platform?: NodeJS.Platform; + env?: NodeJS.ProcessEnv; + release?: string; + procVersion?: string; + readFileImpl?: (filePath: string, encoding: BufferEncoding) => string; + dockerInfoFormat?: (format: string, opts?: Record) => string; +}; + +export type WslDockerDesktopGpuCompatibilityAction = { + id: "wsl_docker_desktop_gpu_compatibility"; + title: string; + kind: "info"; + reason: string; + commands: string[]; + blocking: false; +}; + +export function isWslDockerDesktopRuntime(host: WslDockerDesktopHost): boolean { + return host.isWsl && host.runtime === "docker-desktop"; +} + +function detectWsl(deps: WslDockerDesktopDetectionDeps): boolean { + const platform = deps.platform ?? process.platform; + if (platform !== "linux") return false; + const env = deps.env ?? process.env; + if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return true; + const release = deps.release ?? os.release(); + if (/microsoft/i.test(release)) return true; + const procVersion = + deps.procVersion ?? + (() => { + try { + const readFileImpl = + deps.readFileImpl ?? + ((filePath: string, encoding: BufferEncoding) => fs.readFileSync(filePath, encoding)); + return readFileImpl("/proc/version", "utf-8"); + } catch { + return ""; + } + })(); + return /microsoft/i.test(procVersion); +} + +function detectDockerDesktopRuntime(deps: WslDockerDesktopDetectionDeps): WslDockerDesktopStatus { + const dockerInfo = deps.dockerInfoFormat ?? defaultDockerInfoFormat; + try { + const output = String( + dockerInfo("{{json .OperatingSystem}}", { + ignoreError: true, + timeout: WSL_DOCKER_DESKTOP_DETECTION_TIMEOUT_MS, + }), + ).trim(); + if (!output || output === "") return "unknown"; + return /^"?docker desktop\b/i.test(output) ? "docker-desktop" : "not-docker-desktop"; + } catch { + return "unknown"; + } +} + +export function detectWslDockerDesktopStatus( + deps: WslDockerDesktopDetectionDeps = {}, +): WslDockerDesktopStatus { + if (!detectWsl(deps)) return "not-docker-desktop"; + return detectDockerDesktopRuntime(deps); +} + +export function wslDockerDesktopGpuCompatibilityRemediationLines( + status: WslDockerDesktopStatus, +): string[] | null { + if (status === "docker-desktop") { + return [ + "Docker Desktop WSL detected; NemoClaw uses Docker --gpus compatibility instead of CDI spec validation.", + "If sandbox GPU setup later fails, verify from WSL:", + ` ${WSL_DOCKER_DESKTOP_GPU_PROOF_COMMAND}`, + "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", + ]; + } + if (status === "unknown") { + return [ + "WSL detected, but NemoClaw could not determine whether Docker is Docker Desktop or native Docker Engine.", + "If using Docker Desktop, confirm Settings > Resources > WSL integration is enabled for this distro, restart Docker Desktop, and verify:", + ` ${WSL_DOCKER_DESKTOP_GPU_PROOF_COMMAND}`, + "If using native Docker Engine inside WSL, install/configure NVIDIA Container Toolkit CDI, then restart Docker.", + "Or force CPU sandbox behavior with NEMOCLAW_SANDBOX_GPU=0.", + ]; + } + return null; +} + +export function wslDockerDesktopGpuCompatibilityAction(): WslDockerDesktopGpuCompatibilityAction { + return { + id: "wsl_docker_desktop_gpu_compatibility", + title: "Use Docker Desktop WSL GPU compatibility path", + kind: "info", + reason: + "Docker Desktop is configured for CDI device injection (CDISpecDirs is set) but no " + + "nvidia.com/gpu CDI spec is visible from WSL. On Docker Desktop-backed WSL, NemoClaw " + + "uses Docker's `--gpus` compatibility path instead of trying to repair Linux host CDI " + + "from inside the WSL distro.", + commands: [ + `If sandbox GPU setup later fails, verify Docker Desktop GPU support from WSL with \`${WSL_DOCKER_DESKTOP_GPU_PROOF_COMMAND}\`.`, + "Rerun with `--no-gpu` to skip GPU passthrough.", + ], + blocking: false, + }; +}