From 43099f3dfd2ab1918be8c338e1f63828681f646b Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 21 Jul 2026 21:54:05 -0500 Subject: [PATCH 1/2] fix(sandbox): classify gateway failures against the sandbox's owning gateway classifyGatewayFailure accepted the sandbox name but probed only the hardcoded openshell-cluster-nemoclaw container and GATEWAY_PORT. For a sandbox registered against a per-port gateway (nemoclaw-), an exited gateway container was misclassified as container_missing (advising a sandbox recreate), a running default gateway on the same host was misattributed as gateway_unreachable, and the port-conflict probe checked the wrong port. Resolve the owning gateway via getSandboxTargetGatewayName and derive the container (openshell-cluster-) and probe port from it, matching snapshot, destroy, and uninstall. Closes #7348 Signed-off-by: Andrew White --- .../gateway-failure-classifier.test.ts | 95 +++++++++++++++++++ .../sandbox/gateway-failure-classifier.ts | 32 ++++--- 2 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 src/lib/actions/sandbox/gateway-failure-classifier.test.ts diff --git a/src/lib/actions/sandbox/gateway-failure-classifier.test.ts b/src/lib/actions/sandbox/gateway-failure-classifier.test.ts new file mode 100644 index 00000000000..e1023640170 --- /dev/null +++ b/src/lib/actions/sandbox/gateway-failure-classifier.test.ts @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const getSandboxMock = vi.fn(); + +vi.mock("../../state/registry", () => ({ + getSandbox: (...args: unknown[]) => getSandboxMock(...args), + listSandboxes: vi.fn(() => ({ sandboxes: [] })), +})); + +import { classifyGatewayFailure, type GatewayFailureRunners } from "./gateway-failure-classifier"; + +function runners(overrides: Partial = {}): GatewayFailureRunners { + return { + dockerInfo: () => true, + dockerIsRunning: () => false, + dockerExists: () => false, + portProbe: async () => false, + ...overrides, + }; +} + +describe("classifyGatewayFailure (#7348)", () => { + beforeEach(() => { + getSandboxMock.mockReset(); + }); + it("classifies an exited per-port gateway container as container_exited, not container_missing", async () => { + getSandboxMock.mockReturnValue({ name: "sb-1", gatewayPort: 8081 }); + const portProbe = vi.fn(async () => false); + + const result = await classifyGatewayFailure("sb-1", { + runners: runners({ + dockerExists: (container) => container === "openshell-cluster-nemoclaw-8081", + portProbe, + }), + }); + + expect(result.layer).toBe("container_exited"); + expect(result.detail).toContain("openshell-cluster-nemoclaw-8081"); + expect(portProbe).toHaveBeenCalledWith(8081); + }); + + it("reports the per-port gateway port on a port conflict", async () => { + getSandboxMock.mockReturnValue({ name: "sb-1", gatewayPort: 8081 }); + + const result = await classifyGatewayFailure("sb-1", { + runners: runners({ + dockerExists: (container) => container === "openshell-cluster-nemoclaw-8081", + portProbe: async (port) => port === 8081, + }), + }); + + expect(result.layer).toBe("container_exited_port_conflict"); + expect(result.detail).toContain("port 8081"); + expect(result.detail).toContain("openshell-cluster-nemoclaw-8081"); + }); + + it("does not attribute a running default gateway container to a per-port sandbox", async () => { + getSandboxMock.mockReturnValue({ name: "sb-1", gatewayPort: 8081 }); + + const result = await classifyGatewayFailure("sb-1", { + runners: runners({ + dockerIsRunning: (container) => container === "openshell-cluster-nemoclaw", + dockerExists: (container) => container.startsWith("openshell-cluster-nemoclaw"), + }), + }); + + expect(result.layer).toBe("container_exited"); + expect(result.detail).toContain("openshell-cluster-nemoclaw-8081"); + }); + + it("keeps probing the default gateway container for sandboxes without a registered gateway", async () => { + getSandboxMock.mockReturnValue(null); + + const result = await classifyGatewayFailure("legacy-sb", { + runners: runners({ + dockerIsRunning: (container) => container === "openshell-cluster-nemoclaw", + }), + }); + + expect(result.layer).toBe("gateway_unreachable"); + expect(result.detail).toContain("'openshell-cluster-nemoclaw'"); + }); + + it("short-circuits on an unreachable Docker daemon before resolving the gateway", async () => { + const result = await classifyGatewayFailure("sb-1", { + runners: runners({ dockerInfo: () => false }), + }); + + expect(result.layer).toBe("docker_unreachable"); + expect(getSandboxMock).not.toHaveBeenCalled(); + }); +}); diff --git a/src/lib/actions/sandbox/gateway-failure-classifier.ts b/src/lib/actions/sandbox/gateway-failure-classifier.ts index 3fde72475e5..e6124db4c33 100644 --- a/src/lib/actions/sandbox/gateway-failure-classifier.ts +++ b/src/lib/actions/sandbox/gateway-failure-classifier.ts @@ -7,10 +7,11 @@ import { dockerInfo } from "../../adapters/docker/info"; import { dockerCapture } from "../../adapters/docker/run"; import { CLI_NAME } from "../../cli/branding"; import { GATEWAY_PORT } from "../../core/ports"; +import { resolveGatewayPortFromName } from "../../onboard/gateway-binding"; import * as registry from "../../state/registry"; +import { getSandboxTargetGatewayName } from "./gateway-target"; import { resolveSandboxContainerOwner } from "./sandbox-container-owner"; -const DEFAULT_CONTAINER = "openshell-cluster-nemoclaw"; const DOCKER_TIMEOUT_MS = 3000; const PORT_PROBE_TIMEOUT_MS = 2000; @@ -100,7 +101,7 @@ const defaultRunners: GatewayFailureRunners = { }; export async function classifyGatewayFailure( - _sandboxName: string, + sandboxName: string, opts?: { runners?: GatewayFailureRunners }, ): Promise { const runners = opts?.runners ?? defaultRunners; @@ -112,10 +113,19 @@ export async function classifyGatewayFailure( }; } - if (runners.dockerIsRunning(DEFAULT_CONTAINER)) { + // Probe the gateway container and port that the sandbox actually belongs + // to: a sandbox onboarded with a non-default NEMOCLAW_GATEWAY_PORT runs as + // `openshell-cluster-nemoclaw-`, and classifying against the bare + // default container reports container_missing for a gateway that merely + // exited (or blames an unrelated default gateway). + const gatewayName = getSandboxTargetGatewayName(sandboxName); + const gatewayContainer = `openshell-cluster-${gatewayName}`; + const gatewayPort = resolveGatewayPortFromName(gatewayName) ?? GATEWAY_PORT; + + if (runners.dockerIsRunning(gatewayContainer)) { return { layer: "gateway_unreachable", - detail: `Container '${DEFAULT_CONTAINER}' is running but the gateway API is not responding.`, + detail: `Container '${gatewayContainer}' is running but the gateway API is not responding.`, }; } @@ -123,23 +133,23 @@ export async function classifyGatewayFailure( // "removed/never created" — only the former can hit container_exited*. Per // issue #3271 AC: container_exited_port_conflict requires `docker ps -a` to // confirm the container exited rather than being absent. - if (!runners.dockerExists(DEFAULT_CONTAINER)) { + if (!runners.dockerExists(gatewayContainer)) { return { layer: "container_missing", - detail: `Container '${DEFAULT_CONTAINER}' is not present (never created or removed).`, + detail: `Container '${gatewayContainer}' is not present (never created or removed).`, }; } - const portInUse = await runners.portProbe(GATEWAY_PORT); + const portInUse = await runners.portProbe(gatewayPort); if (portInUse) { return { layer: "container_exited_port_conflict", - detail: `Container '${DEFAULT_CONTAINER}' exited, and port ${GATEWAY_PORT} is held by another process.`, + detail: `Container '${gatewayContainer}' exited, and port ${gatewayPort} is held by another process.`, }; } return { layer: "container_exited", - detail: `Container '${DEFAULT_CONTAINER}' exited.`, + detail: `Container '${gatewayContainer}' exited.`, }; } @@ -232,8 +242,8 @@ export async function classifySandboxContainerFailure( type SandboxDriverLookup = (name: string) => { openshellDriver?: string | null } | null | undefined; // Drivers whose sandbox runtime does NOT live in the local Docker daemon. Only -// `vm` qualifies: the NemoClaw gateway always runs as the local Docker -// container `openshell-cluster-nemoclaw` (see classifyGatewayFailure), so the +// `vm` qualifies: the NemoClaw gateway always runs as a local Docker +// `openshell-cluster-` container (see classifyGatewayFailure), so the // `docker` driver and the `kubernetes`/k3s driver (k3s-in-Docker, or Docker // Desktop's Kubernetes — selected by `isLinuxDockerDriverGatewayEnabled()` for // non-Linux/non-arm64 hosts) both depend on a reachable local Docker daemon. A From 45f1f3ea78811f5ea9ba41e1e430c7ce93ba6e7c Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Thu, 23 Jul 2026 14:43:54 -0700 Subject: [PATCH 2/2] test(sandbox): bind gateway fixture to selected port Signed-off-by: Charan Jagwani --- test/repro-2666-silent-list-status.test.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/repro-2666-silent-list-status.test.ts b/test/repro-2666-silent-list-status.test.ts index 217443d3bfc..e092f9a5f3c 100644 --- a/test/repro-2666-silent-list-status.test.ts +++ b/test/repro-2666-silent-list-status.test.ts @@ -30,6 +30,7 @@ import { renderSandboxInventoryText, } from "../src/lib/inventory/index.js"; import { recoverRegistryEntriesWithFallback } from "../src/lib/list-command-deps.js"; +import { resolveGatewayName } from "../src/lib/onboard/gateway-binding.js"; import { nemoclawStateRoot } from "../src/lib/state/state-root.js"; import { testTimeoutOptions } from "./helpers/timeouts"; @@ -248,7 +249,7 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress fs.writeFileSync(path.join(binDir, "openshell"), lines.join("\n"), { mode: 0o755 }); } - function seedRegistry(stateDir: string, model = "test-model"): void { + function seedRegistry(stateDir: string, model = "test-model", gatewayPort?: number): void { fs.mkdirSync(stateDir, { recursive: true }); fs.writeFileSync( path.join(stateDir, "sandboxes.json"), @@ -260,6 +261,9 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress provider: "nvidia-prod", gpuEnabled: false, policies: [], + ...(gatewayPort === undefined + ? {} + : { gatewayName: resolveGatewayName(gatewayPort), gatewayPort }), }, }, defaultSandbox: "my-assist", @@ -292,7 +296,7 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress it("nemoclaw list reads the registry scoped to a non-default gateway port (#3053)", () => { const port = 9123; seedRegistry(path.join(home, ".nemoclaw"), "default-root-model"); - seedRegistry(nemoclawStateRoot(home, port), "selected-port-model"); + seedRegistry(nemoclawStateRoot(home, port), "selected-port-model", port); const { code, stdout, stderr } = runCli(["list"], { NEMOCLAW_GATEWAY_PORT: String(port), @@ -311,7 +315,7 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress () => { const port = 9123; seedRegistry(path.join(home, ".nemoclaw"), "default-root-model"); - seedRegistry(nemoclawStateRoot(home, port), "selected-port-model"); + seedRegistry(nemoclawStateRoot(home, port), "selected-port-model", port); const { code, stdout, stderr } = runCli(["my-assist", "status"], { NEMOCLAW_GATEWAY_PORT: String(port), @@ -433,7 +437,7 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress await new Promise((resolve) => listener.listen(0, "127.0.0.1", resolve)); const port = (listener.address() as { port: number }).port; fs.rmSync(path.join(home, ".nemoclaw", "sandboxes.json"), { force: true }); - seedRegistry(nemoclawStateRoot(home, port)); + seedRegistry(nemoclawStateRoot(home, port), "test-model", port); try { // Fake docker: info OK, ps shows nothing running, ps -a shows the @@ -441,7 +445,7 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress writeFakeDocker([ "#!/usr/bin/env bash", "if [ \"$1\" = info ]; then echo 'Server Version: 24.0.0'; exit 0; fi", - 'if [ "$1" = ps ] && [ "$2" = -a ]; then echo \'openshell-cluster-nemoclaw\'; exit 0; fi', + `if [ "$1" = ps ] && [ "$2" = -a ]; then echo 'openshell-cluster-nemoclaw-${port}'; exit 0; fi`, 'if [ "$1" = ps ]; then exit 0; fi', "exit 0", ]); @@ -452,7 +456,7 @@ describe("simulated container-stopped and foreign-port-holder subprocess regress writeFakeOpenshell([ "#!/usr/bin/env bash", 'case "$*" in', - ' "sandbox get my-assist"|"sandbox get -g nemoclaw my-assist")', + ` "sandbox get my-assist"|"sandbox get -g nemoclaw-${port} my-assist")`, " echo 'transport error: unexpected EOF' >&2", " exit 1", " ;;",