From 0f75a2a444a5bd07f62b10e0de55eedff2271530 Mon Sep 17 00:00:00 2001 From: Hokonoken <41166525+Hokonoken@users.noreply.github.com> Date: Wed, 8 Jul 2026 13:48:26 +0200 Subject: [PATCH 1/7] feat(status): warn when the gateway route drifts from the recorded route The shared per-gateway OpenShell route lets an onboard, a connect, or a direct 'openshell inference set' move the live route from under a registered sandbox (#6315). Status displayed the live gateway route as if it were the sandbox's own, so the drift was invisible: the sandbox silently showed another sandbox's provider/model with no hint that its recorded route differed. Compare the live route against the sandbox's registry entry in the status snapshot (planInferenceRouteReconcile, the #3726 connect-time precedent) and print a warning naming both routes, how connect would realign, and the supported command to adopt the live route instead. Refs #6315 Signed-off-by: Hokonoken <41166525+Hokonoken@users.noreply.github.com> --- src/lib/actions/sandbox/status-flow.test.ts | 31 +++++++ .../status-snapshot-route-drift.test.ts | 92 +++++++++++++++++++ src/lib/actions/sandbox/status-snapshot.ts | 27 +++++- src/lib/actions/sandbox/status-text.ts | 33 ++++++- src/lib/actions/sandbox/status.ts | 2 + test/support/status-flow-test-harness.ts | 3 + 6 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 src/lib/actions/sandbox/status-snapshot-route-drift.test.ts diff --git a/src/lib/actions/sandbox/status-flow.test.ts b/src/lib/actions/sandbox/status-flow.test.ts index 5d0b663d2d9..ac698012e4c 100644 --- a/src/lib/actions/sandbox/status-flow.test.ts +++ b/src/lib/actions/sandbox/status-flow.test.ts @@ -24,6 +24,37 @@ describe("showSandboxStatus flow", () => { resetStatusFlowModuleCache(); }); + it("warns when the live gateway route differs from the sandbox's recorded route (#6315)", async () => { + const harness = createStatusFlowHarness({ + currentProvider: "openai", + currentModel: "gpt-5.2", + routeDrift: { + live: { provider: "openai", model: "gpt-5.2" }, + recorded: { provider: "nvidia", model: "nvidia/nemotron" }, + }, + }); + + await expect(harness.showSandboxStatus("alpha")).resolves.toBeUndefined(); + + const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n"); + expect(output).toContain( + "Warning: gateway inference route (openai/gpt-5.2) differs from the recorded route for this sandbox (nvidia/nvidia/nemotron).", + ); + expect(output).toContain( + "'nemoclaw alpha connect' realigns the gateway to nvidia/nvidia/nemotron", + ); + expect(output).toContain("inference set --provider openai --model gpt-5.2 --sandbox alpha"); + }); + + it("prints no route drift warning when the live route matches the recorded route (#6315)", async () => { + const harness = createStatusFlowHarness(); + + await expect(harness.showSandboxStatus("alpha")).resolves.toBeUndefined(); + + const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n"); + expect(output).not.toContain("differs from the recorded route"); + }); + it("prints the live sandbox, inference, runtime, session, version, and recovery signals", async () => { const harness = createStatusFlowHarness(); diff --git a/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts b/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts new file mode 100644 index 00000000000..20e3d7775ce --- /dev/null +++ b/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { afterEach, describe, expect, it, vi } from "vitest"; + +vi.mock("../../adapters/openshell/runtime", async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, captureOpenshellForStatus: vi.fn() }; +}); + +import { captureOpenshellForStatus } from "../../adapters/openshell/runtime"; +import type { SandboxEntry } from "../../state/registry"; +import { collectSandboxStatusSnapshot } from "./status-snapshot"; + +const capture = vi.mocked(captureOpenshellForStatus); + +function liveGatewayInference(provider: string, model: string): void { + capture.mockResolvedValue({ + status: 0, + output: `Gateway inference:\n Provider: ${provider}\n Model: ${model}\n`, + } as Awaited>); +} + +function snapshotDeps(entry: Partial | null) { + return { + suppressInferenceProbe: true, + deps: { + getSandbox: () => + entry + ? ({ name: "alpha", agent: "openclaw", policies: [], ...entry } as SandboxEntry) + : null, + reconcile: async () => ({ state: "present", output: "Phase: Ready" }), + }, + }; +} + +describe("collectSandboxStatusSnapshot route drift", () => { + afterEach(() => { + vi.clearAllMocks(); + }); + + it("reports drift when the live gateway route differs from the recorded route (#6315)", async () => { + liveGatewayInference("openai", "gpt-5.2"); + + const snapshot = await collectSandboxStatusSnapshot( + "alpha", + snapshotDeps({ provider: "nvidia", model: "nvidia/nemotron" }), + ); + + expect(snapshot.routeDrift).toEqual({ + live: { provider: "openai", model: "gpt-5.2" }, + recorded: { provider: "nvidia", model: "nvidia/nemotron" }, + }); + expect(snapshot.currentProvider).toBe("openai"); + expect(snapshot.currentModel).toBe("gpt-5.2"); + }); + + it("reports no drift when the live route matches the recorded route (#6315)", async () => { + liveGatewayInference("nvidia", "nvidia/nemotron"); + + const snapshot = await collectSandboxStatusSnapshot( + "alpha", + snapshotDeps({ provider: "nvidia", model: "nvidia/nemotron" }), + ); + + expect(snapshot.routeDrift).toBeNull(); + }); + + it("reports no drift when the live route is unreadable — repair, not divergence (#6315)", async () => { + capture.mockResolvedValue({ + status: 1, + output: "", + } as Awaited>); + + const snapshot = await collectSandboxStatusSnapshot( + "alpha", + snapshotDeps({ provider: "nvidia", model: "nvidia/nemotron" }), + ); + + expect(snapshot.routeDrift).toBeNull(); + expect(snapshot.currentProvider).toBe("nvidia"); + expect(snapshot.currentModel).toBe("nvidia/nemotron"); + }); + + it("reports no drift when the registry entry has no recorded route (#6315)", async () => { + liveGatewayInference("openai", "gpt-5.2"); + + const snapshot = await collectSandboxStatusSnapshot("alpha", snapshotDeps({})); + + expect(snapshot.routeDrift).toBeNull(); + }); +}); diff --git a/src/lib/actions/sandbox/status-snapshot.ts b/src/lib/actions/sandbox/status-snapshot.ts index dbef4db2fb4..7ec8ae7bed6 100644 --- a/src/lib/actions/sandbox/status-snapshot.ts +++ b/src/lib/actions/sandbox/status-snapshot.ts @@ -8,7 +8,12 @@ import { import { captureOpenshellForStatus, isCommandTimeout } from "../../adapters/openshell/runtime"; import { type AgentDefinition, getAgentRuntimeKind, loadAgent } from "../../agent/defs"; import { withStdoutRedirectedToStderr } from "../../cli/stdout-guard"; -import { parseGatewayInference } from "../../inference/config"; +import { + type GatewayInference, + parseGatewayInference, + planInferenceRouteReconcile, + type RecordedInferenceRoute, +} from "../../inference/config"; import { type ProviderHealthProbeOptions, type ProviderHealthStatus, @@ -105,12 +110,18 @@ export interface SandboxStatusReport { dockerPaused: boolean; } +export interface SandboxStatusRouteDrift { + live: GatewayInference; + recorded: RecordedInferenceRoute; +} + export interface SandboxStatusSnapshot { sb: registry.SandboxEntry | null; lookup: SandboxGatewayState; rpcIssue: OpenShellStateRpcIssue | null; currentModel: string; currentProvider: string; + routeDrift: SandboxStatusRouteDrift | null; inferenceHealth: ProviderHealthStatus | null; terminalRuntimeHealth: TerminalRuntimeOomProbeResult | null; } @@ -199,6 +210,7 @@ export async function collectSandboxStatusSnapshot( rpcIssue, currentModel: "unknown", currentProvider: "unknown", + routeDrift: null, inferenceHealth: null, terminalRuntimeHealth: null, }; @@ -207,6 +219,18 @@ export async function collectSandboxStatusSnapshot( liveResult && !isCommandTimeout(liveResult) ? parseGatewayInference(liveResult.output) : null; const currentModel = (live && live.model) || (sb && sb.model) || "unknown"; const currentProvider = (live && live.provider) || (sb && sb.provider) || "unknown"; + // Status shows the live gateway route when one is readable, which silently + // masks a route another sandbox (or a direct `openshell inference set`) + // moved from under this one — the shared-route trap of #6315. Surface the + // divergence instead of letting the live value pass as this sandbox's own. + const routeDriftPlan = + sb && sb.provider && sb.model + ? planInferenceRouteReconcile(live, { provider: sb.provider, model: sb.model }) + : null; + const routeDrift = + routeDriftPlan && routeDriftPlan.kind === "diverged" + ? { live: routeDriftPlan.live, recorded: routeDriftPlan.recorded } + : null; // When the caller has already determined that the local stack is failed // (docker daemon down, sandbox container stopped, dashboard port held), // skip the provider probe entirely. Without this gate @@ -250,6 +274,7 @@ export async function collectSandboxStatusSnapshot( rpcIssue, currentModel, currentProvider, + routeDrift, inferenceHealth, terminalRuntimeHealth, }; diff --git a/src/lib/actions/sandbox/status-text.ts b/src/lib/actions/sandbox/status-text.ts index d792251032a..4b88b998ee6 100644 --- a/src/lib/actions/sandbox/status-text.ts +++ b/src/lib/actions/sandbox/status-text.ts @@ -5,6 +5,7 @@ import { resolveOpenshell } from "../../adapters/openshell/resolve"; import * as agentRuntime from "../../agent/runtime"; import { CLI_NAME } from "../../cli/branding"; import { D, G, R, RD, YW } from "../../cli/terminal-style"; +import { sanitizeRouteValueForDisplay } from "../../inference/config"; import type { ProviderHealthStatus } from "../../inference/health"; import * as nim from "../../inference/nim"; import * as sandboxVersion from "../../sandbox/version"; @@ -17,7 +18,11 @@ import { import type { SandboxDockerRuntime } from "./docker-health"; import type { SandboxGatewayState } from "./gateway-state"; import { isSandboxGatewayRunningForStatus } from "./process-recovery"; -import type { SandboxStatusAgentInfo, SandboxStatusSnapshot } from "./status-snapshot"; +import type { + SandboxStatusAgentInfo, + SandboxStatusRouteDrift, + SandboxStatusSnapshot, +} from "./status-snapshot"; export interface SandboxStatusTextContext extends Pick< @@ -26,6 +31,7 @@ export interface SandboxStatusTextContext | "lookup" | "currentModel" | "currentProvider" + | "routeDrift" | "inferenceHealth" | "terminalRuntimeHealth" > { @@ -232,6 +238,30 @@ function printAgentVersion(context: SandboxStatusTextContext, sandbox: SandboxEn } } +// The Model/Provider lines above show the live gateway route, which the +// shared per-gateway route lets another sandbox move (#6315). When it no +// longer matches this sandbox's recorded route, say so instead of presenting +// the live value as this sandbox's own; wording mirrors the connect-time +// divergence warning (#3726). +function printInferenceRouteDrift( + drift: SandboxStatusRouteDrift | null, + sandboxName: string, +): void { + if (!drift) return; + const liveProvider = sanitizeRouteValueForDisplay(drift.live.provider); + const liveModel = sanitizeRouteValueForDisplay(drift.live.model); + const recordedRoute = `${sanitizeRouteValueForDisplay(drift.recorded.provider)}/${sanitizeRouteValueForDisplay(drift.recorded.model)}`; + console.log( + ` ${YW}Warning: gateway inference route (${liveProvider}/${liveModel}) differs from the recorded route for this sandbox (${recordedRoute}).${R}`, + ); + console.log( + ` ${YW}'${CLI_NAME} ${sandboxName} connect' realigns the gateway to ${recordedRoute}; to adopt the live route instead:${R}`, + ); + console.log( + ` ${CLI_NAME} inference set --provider ${liveProvider} --model ${liveModel} --sandbox ${sandboxName}`, + ); +} + /** Render registry-backed sandbox details and return any non-fatal degraded outcome. */ export function printSandboxDetails(context: SandboxStatusTextContext): SandboxStatusTextOutcome { const { sb, currentModel, currentProvider, sandboxName } = context; @@ -242,6 +272,7 @@ export function printSandboxDetails(context: SandboxStatusTextContext): SandboxS console.log(` Sandbox: ${sb.name}`); console.log(` Model: ${currentModel}`); console.log(` Provider: ${currentProvider}`); + printInferenceRouteDrift(context.routeDrift, sb.name); printInferenceStatus(context); printSandboxGpuStatus(sb); console.log( diff --git a/src/lib/actions/sandbox/status.ts b/src/lib/actions/sandbox/status.ts index c5520ea089e..9539acf69ac 100644 --- a/src/lib/actions/sandbox/status.ts +++ b/src/lib/actions/sandbox/status.ts @@ -76,6 +76,7 @@ export async function showSandboxStatus(sandboxName: string): Promise { rpcIssue, currentModel, currentProvider, + routeDrift, inferenceHealth, terminalRuntimeHealth, } = snapshot; @@ -103,6 +104,7 @@ export async function showSandboxStatus(sandboxName: string): Promise { lookup, currentModel, currentProvider, + routeDrift, inferenceHealth, terminalRuntimeHealth, statusAgent, diff --git a/test/support/status-flow-test-harness.ts b/test/support/status-flow-test-harness.ts index bffc4b58240..b40068b4622 100644 --- a/test/support/status-flow-test-harness.ts +++ b/test/support/status-flow-test-harness.ts @@ -7,6 +7,7 @@ import { type MockInstance, vi } from "vitest"; import type { SandboxGatewayState } from "../../src/lib/actions/sandbox/gateway-state"; import type { SandboxStatusPreflightResult } from "../../src/lib/actions/sandbox/status-preflight"; +import type { SandboxStatusRouteDrift } from "../../src/lib/actions/sandbox/status-snapshot"; import type { ProviderHealthStatus } from "../../src/lib/inference/health"; type ShowSandboxStatus = typeof import("../../src/lib/actions/sandbox/status")["showSandboxStatus"]; @@ -53,6 +54,7 @@ const baseSandboxEntry = { export type StatusFlowHarnessOptions = { currentModel?: string; currentProvider?: string; + routeDrift?: SandboxStatusRouteDrift | null; inferenceHealth?: ProviderHealthStatus | null; lookup?: SandboxGatewayState; lookupState?: "present" | "missing"; @@ -135,6 +137,7 @@ export function createStatusFlowHarness(options: StatusFlowHarnessOptions = {}): rpcIssue: null, currentModel: options.currentModel ?? "nvidia/nemotron-live", currentProvider: options.currentProvider ?? "ollama-local", + routeDrift: options.routeDrift ?? null, inferenceHealth: options.inferenceHealth === undefined ? { From 69671e2dcc3fb49e63db57df5e99e31e52b5aaf3 Mon Sep 17 00:00:00 2001 From: Hokonoken <41166525+Hokonoken@users.noreply.github.com> Date: Wed, 8 Jul 2026 13:48:46 +0200 Subject: [PATCH 2/7] docs(inference): note the status route-drift warning in the shared-route contract Refs #6315 Signed-off-by: Hokonoken <41166525+Hokonoken@users.noreply.github.com> --- docs/inference/switch-inference-providers.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/inference/switch-inference-providers.mdx b/docs/inference/switch-inference-providers.mdx index 9410a71cbd4..269fc6d349f 100644 --- a/docs/inference/switch-inference-providers.mdx +++ b/docs/inference/switch-inference-providers.mdx @@ -49,6 +49,7 @@ An OpenClaw native-Anthropic route and a Hermes OpenAI-frontend route therefore NemoClaw checks stopped sandboxes because they depend on that route when restarted. If a registered same-gateway sandbox lacks durable provider or model metadata, or a custom route lacks durable endpoint or API-family metadata, NemoClaw fails closed until you remove and re-onboard that sandbox with complete route metadata. When a route conflicts, onboarding, runtime switching, and connect-time repair exit non-zero before changing the gateway and name the affected sandboxes. +If the live gateway route still ends up differing from a sandbox's recorded route, for example after a direct `openshell inference set`, `$$nemoclaw status` prints a warning naming both routes and the supported command to realign or adopt the live route. Align the routes, remove the conflicting sandbox, or onboard it with another `NEMOCLAW_GATEWAY_PORT`. From 3d4bf8f85fc01df3513d925ecc757516e62cb598 Mon Sep 17 00:00:00 2001 From: Apurv Kumaria Date: Wed, 8 Jul 2026 15:38:27 -0700 Subject: [PATCH 3/7] refactor(inference): share route drift warning Keep status and connect on one sanitized route-drift message contract. Co-authored-by: Hokonoken <41166525+Hokonoken@users.noreply.github.com> Signed-off-by: Apurv Kumaria --- src/lib/actions/sandbox/connect.ts | 12 +++++++----- src/lib/actions/sandbox/status-text.ts | 13 +++++++------ src/lib/inference/config.test.ts | 19 +++++++++++++++++++ src/lib/inference/config.ts | 24 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/lib/actions/sandbox/connect.ts b/src/lib/actions/sandbox/connect.ts index d82e99a6c8b..a761322969d 100644 --- a/src/lib/actions/sandbox/connect.ts +++ b/src/lib/actions/sandbox/connect.ts @@ -19,6 +19,7 @@ import { D, G, R, YW } from "../../cli/terminal-style"; import { spawnExitCode } from "../../core/process-exit"; import { getNamedGatewayLifecycleState } from "../../gateway-runtime-action"; import { + formatInferenceRouteDriftForDisplay, parseGatewayInference, planInferenceRouteReconcile, sanitizeRouteValueForDisplay, @@ -733,12 +734,13 @@ function ensureSandboxInferenceRouteUnlocked( if (plan.kind === "diverged") { // Shared gateway: re-point loudly (even when quiet) — silent revert was // #3726. Values sanitized: registry/gateway strings are untrusted. - const liveProvider = sanitizeRouteValueForDisplay(plan.live.provider); - const liveModel = sanitizeRouteValueForDisplay(plan.live.model); - console.error( - ` ${YW}Warning: gateway inference route (${liveProvider}/${liveModel}) ` + - `differs from the recorded route for sandbox '${sandboxName}' (${recordedRoute}).${R}`, + const display = formatInferenceRouteDriftForDisplay( + plan.live, + plan.recorded, + `for sandbox '${sandboxName}'`, ); + const { liveProvider, liveModel } = display; + console.error(` ${YW}Warning: ${display.warning}${R}`); console.error( ` ${YW}Aligning the gateway to ${recordedRoute}. To keep ` + `${liveProvider}/${liveModel}, set it the supported way:${R}`, diff --git a/src/lib/actions/sandbox/status-text.ts b/src/lib/actions/sandbox/status-text.ts index ba987b1a580..11254b3e831 100644 --- a/src/lib/actions/sandbox/status-text.ts +++ b/src/lib/actions/sandbox/status-text.ts @@ -5,7 +5,7 @@ import { resolveOpenshell } from "../../adapters/openshell/resolve"; import * as agentRuntime from "../../agent/runtime"; import { CLI_NAME } from "../../cli/branding"; import { D, G, R, RD, YW } from "../../cli/terminal-style"; -import { sanitizeRouteValueForDisplay } from "../../inference/config"; +import { formatInferenceRouteDriftForDisplay } from "../../inference/config"; import type { ProviderHealthStatus } from "../../inference/health"; import * as nim from "../../inference/nim"; import * as sandboxVersion from "../../sandbox/version"; @@ -258,12 +258,13 @@ function printInferenceRouteDrift( sandboxName: string, ): void { if (!drift) return; - const liveProvider = sanitizeRouteValueForDisplay(drift.live.provider); - const liveModel = sanitizeRouteValueForDisplay(drift.live.model); - const recordedRoute = `${sanitizeRouteValueForDisplay(drift.recorded.provider)}/${sanitizeRouteValueForDisplay(drift.recorded.model)}`; - console.log( - ` ${YW}Warning: gateway inference route (${liveProvider}/${liveModel}) differs from the recorded route for this sandbox (${recordedRoute}).${R}`, + const display = formatInferenceRouteDriftForDisplay( + drift.live, + drift.recorded, + "for this sandbox", ); + const { liveProvider, liveModel, recordedRoute } = display; + console.log(` ${YW}Warning: ${display.warning}${R}`); console.log( ` ${YW}'${CLI_NAME} ${sandboxName} connect' realigns the gateway to ${recordedRoute}; to adopt the live route instead:${R}`, ); diff --git a/src/lib/inference/config.test.ts b/src/lib/inference/config.test.ts index e5e0c950c2b..9a215195d17 100644 --- a/src/lib/inference/config.test.ts +++ b/src/lib/inference/config.test.ts @@ -12,6 +12,7 @@ import { DEFAULT_OLLAMA_MODEL, DEFAULT_ROUTE_CREDENTIAL_ENV, DEFAULT_ROUTE_PROFILE, + formatInferenceRouteDriftForDisplay, getCompatibleAnthropicOpenAiSurfaceBaseUrl, getOpenClawPrimaryModel, getProviderSelectionConfig, @@ -602,3 +603,21 @@ describe("sanitizeRouteValueForDisplay", () => { expect(sanitizeRouteValueForDisplay("nvidia-prod")).toBe("nvidia-prod"); }); }); + +describe("formatInferenceRouteDriftForDisplay", () => { + it("shares one sanitized warning contract across status and connect", () => { + expect( + formatInferenceRouteDriftForDisplay( + { provider: "openai\u001b[2J", model: "gpt-5.2\n" }, + { provider: "nvidia", model: "nvidia/nemotron" }, + "for sandbox 'alpha'\r", + ), + ).toEqual({ + liveProvider: "openai[2J", + liveModel: "gpt-5.2", + recordedRoute: "nvidia/nvidia/nemotron", + warning: + "gateway inference route (openai[2J/gpt-5.2) differs from the recorded route for sandbox 'alpha' (nvidia/nvidia/nemotron).", + }); + }); +}); diff --git a/src/lib/inference/config.ts b/src/lib/inference/config.ts index dc4cb93d4dd..a3353fb47b8 100644 --- a/src/lib/inference/config.ts +++ b/src/lib/inference/config.ts @@ -393,3 +393,27 @@ export function planInferenceRouteReconcile( export function sanitizeRouteValueForDisplay(value: string | null | undefined): string { return (value ?? "").replace(/[\u0000-\u001f\u007f-\u009f]/g, ""); } + +export interface InferenceRouteDriftDisplay { + liveProvider: string; + liveModel: string; + recordedRoute: string; + warning: string; +} + +export function formatInferenceRouteDriftForDisplay( + live: GatewayInference, + recorded: RecordedInferenceRoute, + recordedRouteOwner: string, +): InferenceRouteDriftDisplay { + const liveProvider = sanitizeRouteValueForDisplay(live.provider); + const liveModel = sanitizeRouteValueForDisplay(live.model); + const recordedRoute = `${sanitizeRouteValueForDisplay(recorded.provider)}/${sanitizeRouteValueForDisplay(recorded.model)}`; + const owner = sanitizeRouteValueForDisplay(recordedRouteOwner); + return { + liveProvider, + liveModel, + recordedRoute, + warning: `gateway inference route (${liveProvider}/${liveModel}) differs from the recorded route ${owner} (${recordedRoute}).`, + }; +} From 5db5f67fcdc2671908cd8f557b66577105b3be06 Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 8 Jul 2026 22:07:54 -0700 Subject: [PATCH 4/7] fix(cli): quote route drift recovery commands Signed-off-by: Charan Jagwani --- .../sandbox/connect-route-lifecycle.test.ts | 23 ++++++++++++++++ src/lib/actions/sandbox/connect.ts | 3 ++- src/lib/actions/sandbox/status-flow.test.ts | 27 +++++++++++++++++-- src/lib/actions/sandbox/status-text.ts | 5 ++-- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/lib/actions/sandbox/connect-route-lifecycle.test.ts b/src/lib/actions/sandbox/connect-route-lifecycle.test.ts index e7ceb276e08..5c03518db13 100644 --- a/src/lib/actions/sandbox/connect-route-lifecycle.test.ts +++ b/src/lib/actions/sandbox/connect-route-lifecycle.test.ts @@ -60,6 +60,9 @@ describe("connectSandbox route lifecycle", () => { expect(errorOutput).toContain( "Aligning the gateway to anthropic-prod/claude-sonnet-4-20250514", ); + expect(errorOutput).toContain( + "nemoclaw inference set --provider 'nvidia-prod' --model 'nvidia/nemotron-3-super-120b-a12b' --sandbox 'alpha'", + ); expect(harness.runOpenshellSpy).toHaveBeenCalledWith( [ "inference", @@ -81,6 +84,26 @@ describe("connectSandbox route lifecycle", () => { ); }); + it("shell-quotes hostile route values in drift recovery commands (#3726)", async () => { + const sandboxName = "alpha's box"; + const harness = createConnectHarness({ + inferenceGetOutput: + "Gateway inference:\n Provider: openai; touch /tmp/pwn\n Model: $(id) model\n", + registryEntry: { + name: sandboxName, + model: "claude-sonnet-4-20250514", + provider: "anthropic-prod", + }, + }); + + await expect(harness.connectSandbox(sandboxName, { probeOnly: true })).resolves.toBeUndefined(); + + const errorOutput = harness.errorSpy.mock.calls.map((call) => String(call[0] ?? "")).join("\n"); + expect(errorOutput).toContain( + "nemoclaw inference set --provider 'openai; touch /tmp/pwn' --model '$(id) model' --sandbox 'alpha'\\''s box'", + ); + }); + it("wires the forced VM DNS monkeypatch into connect route repair", async () => { vi.stubEnv("NEMOCLAW_FORCE_VM_DNS_MONKEYPATCH", "1"); try { diff --git a/src/lib/actions/sandbox/connect.ts b/src/lib/actions/sandbox/connect.ts index a761322969d..00023b29784 100644 --- a/src/lib/actions/sandbox/connect.ts +++ b/src/lib/actions/sandbox/connect.ts @@ -17,6 +17,7 @@ import * as agentRuntime from "../../agent/runtime"; import { CLI_NAME } from "../../cli/branding"; import { D, G, R, YW } from "../../cli/terminal-style"; import { spawnExitCode } from "../../core/process-exit"; +import { shellQuote } from "../../core/shell-quote"; import { getNamedGatewayLifecycleState } from "../../gateway-runtime-action"; import { formatInferenceRouteDriftForDisplay, @@ -746,7 +747,7 @@ function ensureSandboxInferenceRouteUnlocked( `${liveProvider}/${liveModel}, set it the supported way:${R}`, ); console.error( - ` ${CLI_NAME} inference set --provider ${liveProvider} --model ${liveModel} --sandbox ${sandboxName}`, + ` ${CLI_NAME} inference set --provider ${shellQuote(liveProvider)} --model ${shellQuote(liveModel)} --sandbox ${shellQuote(sandboxName)}`, ); } else if (!quiet) { // plan.kind === "repair": empty gateway, genuine repair — quiet-aware. diff --git a/src/lib/actions/sandbox/status-flow.test.ts b/src/lib/actions/sandbox/status-flow.test.ts index 48ae297a321..ccabc1c5826 100644 --- a/src/lib/actions/sandbox/status-flow.test.ts +++ b/src/lib/actions/sandbox/status-flow.test.ts @@ -41,9 +41,32 @@ describe("showSandboxStatus flow", () => { "Warning: gateway inference route (openai/gpt-5.2) differs from the recorded route for this sandbox (nvidia/nvidia/nemotron).", ); expect(output).toContain( - "'nemoclaw alpha connect' realigns the gateway to nvidia/nvidia/nemotron", + "nemoclaw 'alpha' connect realigns the gateway to nvidia/nvidia/nemotron", + ); + expect(output).toContain( + "inference set --provider 'openai' --model 'gpt-5.2' --sandbox 'alpha'", + ); + }); + + it("shell-quotes hostile route values in drift recovery commands (#6315)", async () => { + const sandboxName = "alpha's box"; + const harness = createStatusFlowHarness({ + currentProvider: "openai; touch /tmp/pwn", + currentModel: "$(id) model", + routeDrift: { + live: { provider: "openai; touch /tmp/pwn", model: "$(id) model" }, + recorded: { provider: "nvidia", model: "nvidia/nemotron" }, + }, + sandboxEntry: { name: sandboxName }, + }); + + await expect(harness.showSandboxStatus(sandboxName)).resolves.toBeUndefined(); + + const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n"); + expect(output).toContain("nemoclaw 'alpha'\\''s box' connect realigns the gateway"); + expect(output).toContain( + "nemoclaw inference set --provider 'openai; touch /tmp/pwn' --model '$(id) model' --sandbox 'alpha'\\''s box'", ); - expect(output).toContain("inference set --provider openai --model gpt-5.2 --sandbox alpha"); }); it("prints no route drift warning when the live route matches the recorded route (#6315)", async () => { diff --git a/src/lib/actions/sandbox/status-text.ts b/src/lib/actions/sandbox/status-text.ts index 11254b3e831..68307b0b40e 100644 --- a/src/lib/actions/sandbox/status-text.ts +++ b/src/lib/actions/sandbox/status-text.ts @@ -5,6 +5,7 @@ import { resolveOpenshell } from "../../adapters/openshell/resolve"; import * as agentRuntime from "../../agent/runtime"; import { CLI_NAME } from "../../cli/branding"; import { D, G, R, RD, YW } from "../../cli/terminal-style"; +import { shellQuote } from "../../core/shell-quote"; import { formatInferenceRouteDriftForDisplay } from "../../inference/config"; import type { ProviderHealthStatus } from "../../inference/health"; import * as nim from "../../inference/nim"; @@ -266,10 +267,10 @@ function printInferenceRouteDrift( const { liveProvider, liveModel, recordedRoute } = display; console.log(` ${YW}Warning: ${display.warning}${R}`); console.log( - ` ${YW}'${CLI_NAME} ${sandboxName} connect' realigns the gateway to ${recordedRoute}; to adopt the live route instead:${R}`, + ` ${YW}${CLI_NAME} ${shellQuote(sandboxName)} connect realigns the gateway to ${recordedRoute}; to adopt the live route instead:${R}`, ); console.log( - ` ${CLI_NAME} inference set --provider ${liveProvider} --model ${liveModel} --sandbox ${sandboxName}`, + ` ${CLI_NAME} inference set --provider ${shellQuote(liveProvider)} --model ${shellQuote(liveModel)} --sandbox ${shellQuote(sandboxName)}`, ); } From f8ee55e49c34fa1ae06ce3e339dfedc2a8d7a1e0 Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 8 Jul 2026 22:15:15 -0700 Subject: [PATCH 5/7] fix(status): read sandbox-bound gateway route Signed-off-by: Charan Jagwani --- .../status-snapshot-route-drift.test.ts | 39 +++++++++++++++++++ src/lib/actions/sandbox/status-snapshot.ts | 12 ++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts b/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts index 20e3d7775ce..76c5ea14915 100644 --- a/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts +++ b/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts @@ -55,6 +55,45 @@ describe("collectSandboxStatusSnapshot route drift", () => { expect(snapshot.currentModel).toBe("gpt-5.2"); }); + it("reads the sandbox's non-default gateway before computing drift (#6315)", async () => { + liveGatewayInference("openai", "gpt-5.2"); + + const snapshot = await collectSandboxStatusSnapshot( + "alpha", + snapshotDeps({ + gatewayPort: 9090, + provider: "nvidia", + model: "nvidia/nemotron", + }), + ); + + expect(capture).toHaveBeenCalledWith(["inference", "get", "-g", "nemoclaw-9090"]); + expect(snapshot.routeDrift).toEqual({ + live: { provider: "openai", model: "gpt-5.2" }, + recorded: { provider: "nvidia", model: "nvidia/nemotron" }, + }); + expect(snapshot.currentProvider).toBe("openai"); + expect(snapshot.currentModel).toBe("gpt-5.2"); + }); + + it("does not fall back to the default gateway for an invalid persisted binding (#6315)", async () => { + liveGatewayInference("openai", "gpt-5.2"); + + const snapshot = await collectSandboxStatusSnapshot( + "alpha", + snapshotDeps({ + gatewayPort: 0, + provider: "nvidia", + model: "nvidia/nemotron", + }), + ); + + expect(capture).not.toHaveBeenCalled(); + expect(snapshot.routeDrift).toBeNull(); + expect(snapshot.currentProvider).toBe("nvidia"); + expect(snapshot.currentModel).toBe("nvidia/nemotron"); + }); + it("reports no drift when the live route matches the recorded route (#6315)", async () => { liveGatewayInference("nvidia", "nvidia/nemotron"); diff --git a/src/lib/actions/sandbox/status-snapshot.ts b/src/lib/actions/sandbox/status-snapshot.ts index f202d6270c8..3bfa975091b 100644 --- a/src/lib/actions/sandbox/status-snapshot.ts +++ b/src/lib/actions/sandbox/status-snapshot.ts @@ -23,9 +23,11 @@ import { type DcodeAutoApprovalMode, normalizeDcodeAutoApprovalMode, } from "../../onboard/dcode-auto-approval"; +import { resolveSandboxGatewayName } from "../../onboard/gateway-binding"; import { redact } from "../../security/redact"; import { parseSandboxPhase } from "../../state/gateway"; import * as registry from "../../state/registry"; +import { buildGatewayInferenceGetArgs } from "./connect-inference-gateway"; import { classifyInferenceRouteFailureLabel } from "./connect-inference-route-probe"; import { getSandboxDockerRuntime } from "./docker-health"; import type { SandboxGatewayState } from "./gateway-state"; @@ -269,11 +271,13 @@ export async function collectSandboxStatusSnapshot( let liveResult: Awaited> | null = null; if (lookup.state === "present") { try { - liveResult = await (opts.deps?.captureOpenshellForStatusImpl ?? captureOpenshellForStatus)([ - "inference", - "get", - ]); + const gatewayName = resolveSandboxGatewayName(sb); + liveResult = await (opts.deps?.captureOpenshellForStatusImpl ?? captureOpenshellForStatus)( + buildGatewayInferenceGetArgs(gatewayName), + ); } catch { + // Invalid persisted gateway bindings and failed reads stay fail-closed: + // never substitute the selected/default gateway's inference route. liveResult = null; } } From a2e05b5ec362c22ce7a4a95fcf2ead7bd9c75769 Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 8 Jul 2026 22:25:58 -0700 Subject: [PATCH 6/7] test(status): expect gateway-qualified route read Signed-off-by: Charan Jagwani --- test/cli/status-gateway-lifecycle.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/status-gateway-lifecycle.test.ts b/test/cli/status-gateway-lifecycle.test.ts index 0d9528a68e9..ea60c474d1f 100644 --- a/test/cli/status-gateway-lifecycle.test.ts +++ b/test/cli/status-gateway-lifecycle.test.ts @@ -141,7 +141,7 @@ describe("CLI status gateway lifecycle process contracts", () => { expect(result.out).not.toContain("not verified"); const calls = fs.readFileSync(markerFile, "utf8").trim().split("\n").filter(Boolean); const sandboxGetIndex = calls.indexOf("sandbox get alpha"); - const inferenceGetIndex = calls.indexOf("inference get"); + const inferenceGetIndex = calls.indexOf("inference get -g nemoclaw"); expect(sandboxGetIndex).toBeGreaterThanOrEqual(0); expect(inferenceGetIndex).toBeGreaterThan(sandboxGetIndex); }); From 99a541096115c637f15ebef22287c772902865bb Mon Sep 17 00:00:00 2001 From: Apurv Kumaria Date: Thu, 9 Jul 2026 00:30:09 -0700 Subject: [PATCH 7/7] test(sandbox): assert route drift outcomes Co-authored-by: Hoko <41166525+Hokonoken@users.noreply.github.com> Signed-off-by: Apurv Kumaria --- .../status-snapshot-route-drift.test.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts b/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts index 76c5ea14915..a720a9d3fa3 100644 --- a/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts +++ b/src/lib/actions/sandbox/status-snapshot-route-drift.test.ts @@ -14,11 +14,15 @@ import { collectSandboxStatusSnapshot } from "./status-snapshot"; const capture = vi.mocked(captureOpenshellForStatus); -function liveGatewayInference(provider: string, model: string): void { - capture.mockResolvedValue({ - status: 0, - output: `Gateway inference:\n Provider: ${provider}\n Model: ${model}\n`, - } as Awaited>); +function liveGatewayInference(provider: string, model: string, gatewayName = "nemoclaw"): void { + capture.mockImplementation(async (args) => + args.join("\0") === ["inference", "get", "-g", gatewayName].join("\0") + ? ({ + status: 0, + output: `Gateway inference:\n Provider: ${provider}\n Model: ${model}\n`, + } as Awaited>) + : ({ status: 1, output: "" } as Awaited>), + ); } function snapshotDeps(entry: Partial | null) { @@ -56,7 +60,7 @@ describe("collectSandboxStatusSnapshot route drift", () => { }); it("reads the sandbox's non-default gateway before computing drift (#6315)", async () => { - liveGatewayInference("openai", "gpt-5.2"); + liveGatewayInference("openai", "gpt-5.2", "nemoclaw-9090"); const snapshot = await collectSandboxStatusSnapshot( "alpha", @@ -67,7 +71,6 @@ describe("collectSandboxStatusSnapshot route drift", () => { }), ); - expect(capture).toHaveBeenCalledWith(["inference", "get", "-g", "nemoclaw-9090"]); expect(snapshot.routeDrift).toEqual({ live: { provider: "openai", model: "gpt-5.2" }, recorded: { provider: "nvidia", model: "nvidia/nemotron" }, @@ -88,7 +91,6 @@ describe("collectSandboxStatusSnapshot route drift", () => { }), ); - expect(capture).not.toHaveBeenCalled(); expect(snapshot.routeDrift).toBeNull(); expect(snapshot.currentProvider).toBe("nvidia"); expect(snapshot.currentModel).toBe("nvidia/nemotron");