fix: follow active OpenShell gateway (#46)

Co-authored-by: mmckeen-nv <mmckeen-nv@users.noreply.github.com>
This commit is contained in:
mmckeen-nv
2026-09-08 23:11:14 -07:00
committed by GitHub
co-authored by mmckeen-nv
parent cbbdd1b4d2
commit 270eb109f1
17 changed files with 33 additions and 23 deletions
+2
View File
@@ -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:
+1 -1
View File
@@ -36,7 +36,7 @@ async function runOpenShell(args: string[], extraEnv: Record<string, string> = {
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,
+1 -1
View File
@@ -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,
+5 -5
View File
@@ -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, [
+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -98,7 +98,7 @@ async function runNemoClaw(args: string[], timeout = 30000): Promise<NemoClawRun
try {
const { stdout, stderr } = await execFileAsync(invocation.file, invocation.args, {
env: hostCommandEnv({
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
NO_COLOR: "1",
CLICOLOR: "0",
CLICOLOR_FORCE: "0",
+4 -1
View File
@@ -397,13 +397,16 @@ function resolveSandboxInstanceId(instanceId: string) {
}
function buildSandboxSshArgs(sandboxName: string, extraArgs: string[]) {
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 nemoclaw --name ${sandboxName}`,
"-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy${gatewayOption} --name ${sandboxName}`,
`sandbox@openshell-${sandboxName}`,
...extraArgs,
]
+1 -1
View File
@@ -59,7 +59,7 @@ function runSandboxExec(sandboxName: string, script: string, input?: Buffer, tim
return new Promise<{ stdout: Buffer; 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"],
})
+1 -1
View File
@@ -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"],
})
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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"],
})
@@ -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,
]
@@ -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')
+3 -3
View File
@@ -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')