From 270eb109f1e90fd60f1e36464883cb6f6130b316 Mon Sep 17 00:00:00 2001 From: mmckeen-nv <108093260+mmckeen-nv@users.noreply.github.com> Date: Tue, 8 Sep 2026 23:11:14 -0700 Subject: [PATCH] fix: follow active OpenShell gateway (#46) Co-authored-by: mmckeen-nv --- README.md | 2 ++ app/api/inference/route.ts | 2 +- app/api/sandbox/[sandboxId]/restart/route.ts | 2 +- app/api/sandbox/create/route.ts | 10 +++++----- app/api/sandbox/delete/route.ts | 4 ++-- app/api/support-bundle/route.ts | 2 +- app/api/telemetry/real/route.ts | 2 +- app/lib/inferenceModel.ts | 2 +- app/lib/nemoclawCli.ts | 2 +- app/lib/openshellHost.ts | 5 ++++- app/lib/sandboxFiles.ts | 2 +- app/lib/sandboxOpenClawMcpConfig.ts | 2 +- app/lib/sandboxPermissions.ts | 2 +- app/lib/sandboxPrivilegedFiles.ts | 2 +- scripts/inter-sandbox-chat-openclaw-dispatch.mjs | 7 +++++-- tests/runtime-authority-resolution-check.mjs | 2 ++ tests/sandbox-lifecycle-check.mjs | 6 +++--- 17 files changed, 33 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2f282de..ab15fe2 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ OpenShell must already be installed and able to reach its gateway. On this host The installer does not create an OpenShell gateway for you. Start or connect OpenShell first, then install this dashboard. +Controller commands follow OpenShell's active gateway by default. Set `OPENSHELL_GATEWAY` only for an intentional override; leaving it unset also allows current NemoClaw to restore a port-qualified gateway such as `nemoclaw-8990` when its installer selected an alternate gateway port. + ## Installer Install or refresh the locked OpenShell/NemoClaw pair first: diff --git a/app/api/inference/route.ts b/app/api/inference/route.ts index 72d091f..987633c 100644 --- a/app/api/inference/route.ts +++ b/app/api/inference/route.ts @@ -36,7 +36,7 @@ async function runOpenShell(args: string[], extraEnv: Record = { const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, { env: hostCommandEnv({ ...extraEnv, - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), timeout: 60000, maxBuffer: 20 * 1024 * 1024, diff --git a/app/api/sandbox/[sandboxId]/restart/route.ts b/app/api/sandbox/[sandboxId]/restart/route.ts index ef1d4aa..542e112 100644 --- a/app/api/sandbox/[sandboxId]/restart/route.ts +++ b/app/api/sandbox/[sandboxId]/restart/route.ts @@ -21,7 +21,7 @@ function validateSandboxName(value: string) { async function runOpenShell(args: string[], timeout = 30000) { const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), timeout, maxBuffer: 4 * 1024 * 1024, diff --git a/app/api/sandbox/create/route.ts b/app/api/sandbox/create/route.ts index a169e05..94501c9 100644 --- a/app/api/sandbox/create/route.ts +++ b/app/api/sandbox/create/route.ts @@ -284,7 +284,7 @@ async function listOpenShellSandboxNames() { try { const { stdout } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "list"], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), timeout: 10000, maxBuffer: 1024 * 1024, @@ -648,7 +648,7 @@ async function approveOpenClawDeviceRequests(sandboxName: string) { "-lc", "openclaw devices approve --latest --json --timeout 10000", ], hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), 15000) const combinedOutput = `${result.stdout}\n${result.stderr}`.trim() @@ -783,7 +783,7 @@ export async function POST(request: Request) { NEMOCLAW_NON_INTERACTIVE: "1", NEMOCLAW_RECREATE_SANDBOX: "1", NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }) if (!enableTailscale) { @@ -893,7 +893,7 @@ export async function POST(request: Request) { if (blueprint === "custom-sandbox") { const env: NodeJS.ProcessEnv = hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, NO_COLOR: "1", CLICOLOR: "0", CLICOLOR_FORCE: "0", @@ -995,7 +995,7 @@ export async function POST(request: Request) { const sourceImage = source.image const basePolicyPath = resolveNemoClawBasePolicyPath() const env: NodeJS.ProcessEnv = hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }) const createAttempt = await runCreateCommandUntilReady(OPENSHELL_BIN, [ diff --git a/app/api/sandbox/delete/route.ts b/app/api/sandbox/delete/route.ts index 95b9f62..6152b19 100644 --- a/app/api/sandbox/delete/route.ts +++ b/app/api/sandbox/delete/route.ts @@ -113,7 +113,7 @@ async function deleteSandbox(sandboxName: string) { try { const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "delete", sandboxName], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), timeout: 60000, maxBuffer: 20 * 1024 * 1024, @@ -154,7 +154,7 @@ async function wipePersistentSandboxState(sandboxName: string, agent: string | n try { const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), timeout: 30000, maxBuffer: 1024 * 1024, diff --git a/app/api/support-bundle/route.ts b/app/api/support-bundle/route.ts index 1458e0c..9f5cf7d 100644 --- a/app/api/support-bundle/route.ts +++ b/app/api/support-bundle/route.ts @@ -12,7 +12,7 @@ export const dynamic = "force-dynamic" async function run(command: string, args: string[]) { try { const env = command === OPENSHELL_BIN - ? hostCommandEnv({ OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw" }) + ? hostCommandEnv({ OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined }) : { ...process.env, PATH: HOST_PATH, NO_COLOR: "1", CLICOLOR: "0", CLICOLOR_FORCE: "0" } const { stdout, stderr } = await execFileAsync(command, args, { timeout: 10000, diff --git a/app/api/telemetry/real/route.ts b/app/api/telemetry/real/route.ts index 67507e7..7ace1e6 100644 --- a/app/api/telemetry/real/route.ts +++ b/app/api/telemetry/real/route.ts @@ -157,7 +157,7 @@ function readNemoClawRegistry(): NemoClawRegistryData { async function execNemoclaw(args: string[]) { const env = hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }) const command = /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN) diff --git a/app/lib/inferenceModel.ts b/app/lib/inferenceModel.ts index 2663fe2..f43818b 100644 --- a/app/lib/inferenceModel.ts +++ b/app/lib/inferenceModel.ts @@ -24,7 +24,7 @@ function parseRouteModel(output: string, label: "Gateway inference" | "System in async function readOpenShellInferenceModel() { const { stdout } = await execFileAsync(OPENSHELL_BIN, ["inference", "get"], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), timeout: 30000, maxBuffer: 5 * 1024 * 1024, diff --git a/app/lib/nemoclawCli.ts b/app/lib/nemoclawCli.ts index bc174cc..5c50392 100644 --- a/app/lib/nemoclawCli.ts +++ b/app/lib/nemoclawCli.ts @@ -98,7 +98,7 @@ async function runNemoClaw(args: string[], timeout = 30000): Promise((resolve, reject) => { const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), stdio: ["pipe", "pipe", "pipe"], }) diff --git a/app/lib/sandboxOpenClawMcpConfig.ts b/app/lib/sandboxOpenClawMcpConfig.ts index d82ccba..69548c3 100644 --- a/app/lib/sandboxOpenClawMcpConfig.ts +++ b/app/lib/sandboxOpenClawMcpConfig.ts @@ -17,7 +17,7 @@ function runSandboxShell(sandboxName: string, script: string, input?: string, ti return new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => { const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), stdio: ["pipe", "pipe", "pipe"], }) diff --git a/app/lib/sandboxPermissions.ts b/app/lib/sandboxPermissions.ts index d9134c4..b0540a2 100644 --- a/app/lib/sandboxPermissions.ts +++ b/app/lib/sandboxPermissions.ts @@ -26,7 +26,7 @@ type BrokerNetworkAction = { function runOpenShell(args: string[], timeout = 60000) { return execFileAsync(OPENSHELL_BIN, args, { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, TERM: "dumb", }), timeout, diff --git a/app/lib/sandboxPrivilegedFiles.ts b/app/lib/sandboxPrivilegedFiles.ts index 8ef2664..46edc8c 100644 --- a/app/lib/sandboxPrivilegedFiles.ts +++ b/app/lib/sandboxPrivilegedFiles.ts @@ -9,7 +9,7 @@ function runSandboxShell(sandboxName: string, script: string, input?: Buffer | s return new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => { const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, }), stdio: ["pipe", "pipe", "pipe"], }) diff --git a/scripts/inter-sandbox-chat-openclaw-dispatch.mjs b/scripts/inter-sandbox-chat-openclaw-dispatch.mjs index d2f7419..be404db 100644 --- a/scripts/inter-sandbox-chat-openclaw-dispatch.mjs +++ b/scripts/inter-sandbox-chat-openclaw-dispatch.mjs @@ -12,7 +12,7 @@ const execFileAsync = promisify(execFile) const DASHBOARD_PORT_BASE = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_PORT_BASE || "19000", 10) const DASHBOARD_PORT_RANGE = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_PORT_RANGE || "2000", 10) const REMOTE_DASHBOARD_PORT = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_REMOTE_PORT || "18789", 10) -const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY || "nemoclaw" +const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY?.trim() || undefined const CONTROL_UI_ORIGIN = process.env.OPENCLAW_SANDBOX_CONTROL_UI_ORIGIN || "http://127.0.0.1:18789" const CONNECT_TIMEOUT_MS = Number.parseInt(process.env.INTER_SANDBOX_CHAT_OPENCLAW_CONNECT_TIMEOUT_MS || "15000", 10) const SEND_TIMEOUT_MS = Number.parseInt(process.env.INTER_SANDBOX_CHAT_OPENCLAW_SEND_TIMEOUT_MS || "120000", 10) @@ -54,13 +54,16 @@ function getDashboardPort(sandboxName) { } function buildSandboxSshArgs(sandboxName, extraArgs) { + const gatewayOption = OPENSHELL_GATEWAY + ? ` --gateway-name ${JSON.stringify(OPENSHELL_GATEWAY)}` + : "" return [ "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "GlobalKnownHostsFile=/dev/null", "-o", "LogLevel=ERROR", - "-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy --gateway-name ${OPENSHELL_GATEWAY} --name ${sandboxName}`, + "-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy${gatewayOption} --name ${sandboxName}`, `sandbox@openshell-${sandboxName}`, ...extraArgs, ] diff --git a/tests/runtime-authority-resolution-check.mjs b/tests/runtime-authority-resolution-check.mjs index d0b4c1b..880d72a 100644 --- a/tests/runtime-authority-resolution-check.mjs +++ b/tests/runtime-authority-resolution-check.mjs @@ -57,6 +57,8 @@ assert.match(terminalReadinessSource, /const authority = resolveRuntimeAuthority assert.match(telemetrySource, /authoritySource: "runtimeAuthority"/, 'inventory route must declare shared authority source') assert.match(telemetrySource, /authorities: authorities\.map\(/, 'inventory route must expose per-sandbox authority metadata') assert.match(openshellHostSource, /const OPENSHELL_GATEWAY = process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'OpenShell host commands must not force the legacy openshell gateway when NemoClaw has selected the nemoclaw gateway') +assert.match(openshellHostSource, /ssh-proxy\$\{gatewayOption\}/, 'sandbox SSH proxy commands must make the explicit gateway option conditional') +assert.doesNotMatch(openshellHostSource, /ssh-proxy --gateway-name nemoclaw/, 'sandbox SSH proxy commands must not force the legacy unqualified NemoClaw gateway') assert.match(sandboxHealthSource, /stripAnsi/, 'sandbox health must strip OpenShell ANSI styling before parsing fields such as Phase') assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id === defaultInstance\.id/, 'bootstrap minting should only use CLI for the default OpenClaw instance') assert.match(openshellHostSource, /readSandboxOpenClawDashboardToken/, 'sandbox dashboard bootstrap must fall back to the sandbox OpenClaw token when CLI output is bare') diff --git a/tests/sandbox-lifecycle-check.mjs b/tests/sandbox-lifecycle-check.mjs index 54839c5..fc71de1 100644 --- a/tests/sandbox-lifecycle-check.mjs +++ b/tests/sandbox-lifecycle-check.mjs @@ -168,7 +168,7 @@ assert.match(deleteRouteSource, /workspace-\*/, 'persistent state wipe must incl assert.match(pageSource, /JSON\.stringify\(\{ sandboxName, agent: sandbox\?\.agent \|\| 'openclaw' \}\)/, 'destroy workflow must pass the selected NemoClaw agent to delete state cleanup') assert.match(deleteRouteSource, /validateSandboxName/, 'delete route must validate sandbox names before execution') assert.match(deleteRouteSource, /resolveSandboxRef/, 'delete route must resolve sandbox ids to names before deleting') -assert.match(deleteRouteSource, /OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY \|\| "nemoclaw"/, 'delete route must use the NemoClaw gateway context') +assert.match(deleteRouteSource, /OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'delete route must preserve an explicit gateway without forcing the legacy NemoClaw name') assert.match(hostCommandsSource, /export function hostCommandEnv/, 'host commands must provide a shared environment for OpenShell child processes') assert.match(hostCommandsSource, /XDG_CONFIG_HOME/, 'shared host command environment must preserve the OpenShell config home') assert.match(hostCommandsSource, /export function openshellGatewayAddressEnv/, 'shared host command environment must expose gateway address override variables') @@ -179,9 +179,9 @@ assert.match(hostCommandsSource, /gateway\.json/, 'shared host command environme assert.match(hostCommandsSource, /config\.json/, 'shared host command environment must also support the general OpenShell config file') assert.match(hostCommandsSource, /gatewayHost/, 'OpenShell gateway address config must support a top-level gatewayHost key') assert.match(hostCommandsSource, /gateway\.host/, 'OpenShell gateway address config must support a nested gateway host key') -assert.match(createRouteSource, /const env: NodeJS\.ProcessEnv = hostCommandEnv\(\{[\s\S]*NEMOCLAW_SANDBOX_NAME: sandboxName[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY \|\| "nemoclaw"/, 'NemoClaw onboard must receive the shared host command environment') +assert.match(createRouteSource, /const env: NodeJS\.ProcessEnv = hostCommandEnv\(\{[\s\S]*NEMOCLAW_SANDBOX_NAME: sandboxName[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'NemoClaw onboard must preserve an explicit gateway while allowing NemoClaw to select its port-qualified gateway') assert.match(createRouteSource, /NEMOCLAW_AGENT: agent/, 'NemoClaw onboard must receive the selected dashboard agent') -assert.match(deleteRouteSource, /env: hostCommandEnv\(\{[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY \|\| "nemoclaw"/, 'delete route must pass the shared host command environment to OpenShell') +assert.match(deleteRouteSource, /env: hostCommandEnv\(\{[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'delete route must pass the shared host command environment without forcing a gateway') assert.match(deleteRouteSource, /waitForSandboxDeleted/, 'delete route must poll authoritative inventory until the sandbox is gone') assert.doesNotMatch(deleteRouteSource, /cleanupNemoClawSandbox/, 'delete route must not run NemoClaw destroy cleanup after OpenShell deletion') assert.doesNotMatch(deleteRouteSource, /isNemoClawSandboxNotRegistered/, 'delete route must not keep NemoClaw registry cleanup helpers')