Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
116111c
refactor(cli): harden oclif bridge
cv Apr 30, 2026
5e997cb
test(cli): relax uninstall helper timeouts
cv Apr 30, 2026
88cd958
refactor(cli): migrate status and tunnel commands to oclif
cv Apr 30, 2026
3f748d6
refactor(cli): migrate debug uninstall and gateway-token to oclif
cv Apr 30, 2026
0bc877a
refactor(cli): migrate credentials commands to oclif
cv Apr 30, 2026
3fd15fc
refactor(cli): migrate sandbox inspection commands to oclif
cv Apr 30, 2026
81c62bb
refactor(cli): migrate maintenance commands to oclif
cv Apr 30, 2026
7d6a6fb
refactor(cli): migrate sandbox logs command to oclif
cv May 1, 2026
3f17a4f
refactor(cli): migrate skill install command to oclif
cv May 1, 2026
0fb3c41
refactor(cli): migrate snapshot list and create to oclif
cv May 1, 2026
d11eeee
refactor(cli): migrate shields commands to oclif
cv May 1, 2026
74806ce
refactor(cli): migrate channels mutation commands to oclif
cv May 1, 2026
e637e84
refactor(cli): migrate policy mutation commands to oclif
cv May 1, 2026
ee20dfb
refactor(cli): migrate snapshot restore command to oclif
cv May 1, 2026
8d3a568
refactor(cli): migrate destroy command to oclif
cv May 1, 2026
b447f36
refactor(cli): migrate rebuild command to oclif
cv May 1, 2026
02431db
refactor(cli): migrate connect command to oclif
cv May 1, 2026
37ce2ff
refactor(cli): migrate deploy command to oclif
cv May 1, 2026
d3e218e
refactor(cli): migrate onboard aliases to oclif
cv May 1, 2026
df05a3e
refactor(cli): migrate help and version commands to oclif
cv May 1, 2026
3edcf2e
refactor(cli): centralize legacy oclif dispatch
cv May 1, 2026
47df3b5
refactor(cli): drop trivial oclif wrapper helpers
cv May 1, 2026
460173c
refactor(cli): centralize sandbox runtime bridge
cv May 1, 2026
31c0195
test(cli): keep dispatch table out of coverage ratchet
cv May 1, 2026
bad424d
refactor(cli): centralize policy and channels runtime bridge
cv May 1, 2026
5214142
refactor(cli): centralize global runtime bridge
cv May 1, 2026
5fca48f
refactor(cli): collapse runtime bridge exports
cv May 1, 2026
9616295
refactor(cli): introduce sandbox runtime action facade
cv May 1, 2026
c3a4906
refactor(cli): introduce policy and channels action facade
cv May 1, 2026
35288d8
refactor(cli): introduce global command action facade
cv May 1, 2026
58e71de
refactor(cli): extract root help action
cv May 1, 2026
66a1673
refactor(cli): extract deploy action
cv May 1, 2026
e60ba8e
refactor(cli): extract onboard actions
cv May 1, 2026
7d29288
refactor(cli): extract openshell runtime helpers
cv May 1, 2026
81780c5
refactor(cli): extract sandbox logs action
cv May 1, 2026
278ecc5
test(cli): keep extracted action facades out of coverage
cv May 1, 2026
99f5cff
refactor(cli): extract maintenance actions
cv May 1, 2026
56fa588
test(cli): keep maintenance actions out of coverage ratchet
cv May 1, 2026
6e30cfc
refactor(cli): extract snapshot actions
cv May 1, 2026
f5feac4
refactor(cli): extract policy and channels actions
cv May 1, 2026
ee9c7d2
refactor(cli): extract credentials and list runtime bits
cv May 1, 2026
4f677d4
merge(main): resolve credentials list runtime conflicts
cv May 2, 2026
1e69962
test(cli): preserve credentials runtime bridge injection
cv May 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/lib/gateway-runtime-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

const { startGatewayForRecovery } = require("./onboard") as {
startGatewayForRecovery: () => Promise<void>;
};
import { OPENSHELL_OPERATION_TIMEOUT_MS, OPENSHELL_PROBE_TIMEOUT_MS } from "./openshell-timeouts";
import { stripAnsi } from "./openshell";
import { captureOpenshell, runOpenshell } from "./openshell-runtime";

function hasNamedGateway(output = ""): boolean {
return stripAnsi(output).includes("Gateway: nemoclaw");
}

function getActiveGatewayName(output = ""): string | null {
const match = stripAnsi(output).match(/^\s*Gateway:\s+(.+?)\s*$/m);
return match ? match[1].trim() : null;
}

export function getNamedGatewayLifecycleState() {
const status = captureOpenshell(["status"], { timeout: OPENSHELL_PROBE_TIMEOUT_MS });
const gatewayInfo = captureOpenshell(["gateway", "info", "-g", "nemoclaw"], {
timeout: OPENSHELL_PROBE_TIMEOUT_MS,
});
Comment on lines +21 to +24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make the lifecycle probes non-fatal.

getNamedGatewayLifecycleState() is supposed to classify missing/unhealthy gateway states, but both probes currently use the default captureOpenshell() behavior. If either command exits non-zero, the CLI can terminate before this function ever returns missing_named / named_unreachable, which means the recovery path never gets a chance to run.

Suggested fix
-  const status = captureOpenshell(["status"], { timeout: OPENSHELL_PROBE_TIMEOUT_MS });
+  const status = captureOpenshell(["status"], {
+    ignoreError: true,
+    timeout: OPENSHELL_PROBE_TIMEOUT_MS,
+  });
   const gatewayInfo = captureOpenshell(["gateway", "info", "-g", "nemoclaw"], {
+    ignoreError: true,
     timeout: OPENSHELL_PROBE_TIMEOUT_MS,
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const status = captureOpenshell(["status"], { timeout: OPENSHELL_PROBE_TIMEOUT_MS });
const gatewayInfo = captureOpenshell(["gateway", "info", "-g", "nemoclaw"], {
timeout: OPENSHELL_PROBE_TIMEOUT_MS,
});
const status = captureOpenshell(["status"], {
ignoreError: true,
timeout: OPENSHELL_PROBE_TIMEOUT_MS,
});
const gatewayInfo = captureOpenshell(["gateway", "info", "-g", "nemoclaw"], {
ignoreError: true,
timeout: OPENSHELL_PROBE_TIMEOUT_MS,
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/gateway-runtime-action.ts` around lines 21 - 24, The lifecycle probes
currently call captureOpenshell([...], { timeout: OPENSHELL_PROBE_TIMEOUT_MS })
which will throw on non-zero exits and can abort getNamedGatewayLifecycleState;
wrap each probe call (the status and gatewayInfo assignments) in try/catch and
on error set the variable to null/undefined (or a safe sentinel) instead of
letting the exception propagate so getNamedGatewayLifecycleState can inspect the
null/missing result and return "missing_named" / "named_unreachable" as
intended; ensure you keep the timeout option (OPENSHELL_PROBE_TIMEOUT_MS) when
invoking captureOpenshell inside the try blocks.

const cleanStatus = stripAnsi(status.output);
const activeGateway = getActiveGatewayName(status.output);
const connected = /^\s*Status:\s*Connected\b/im.test(cleanStatus);
const named = hasNamedGateway(gatewayInfo.output);
const refusing = /Connection refused|client error \(Connect\)|tcp connect error/i.test(
cleanStatus,
);
if (connected && activeGateway === "nemoclaw" && named) {
return {
state: "healthy_named",
status: status.output,
gatewayInfo: gatewayInfo.output,
activeGateway,
};
}
if (activeGateway === "nemoclaw" && named && refusing) {
return {
state: "named_unreachable",
status: status.output,
gatewayInfo: gatewayInfo.output,
activeGateway,
};
}
if (activeGateway === "nemoclaw" && named) {
return {
state: "named_unhealthy",
status: status.output,
gatewayInfo: gatewayInfo.output,
activeGateway,
};
}
if (connected) {
return {
state: "connected_other",
status: status.output,
gatewayInfo: gatewayInfo.output,
activeGateway,
};
}
return {
state: "missing_named",
status: status.output,
gatewayInfo: gatewayInfo.output,
activeGateway,
};
}

/** Attempt to recover the named NemoClaw gateway after a restart or connectivity loss. */
export async function recoverNamedGatewayRuntime() {
const before = getNamedGatewayLifecycleState();
if (before.state === "healthy_named") {
return { recovered: true, before, after: before, attempted: false };
}

runOpenshell(["gateway", "select", "nemoclaw"], {
ignoreError: true,
timeout: OPENSHELL_OPERATION_TIMEOUT_MS,
});
let after = getNamedGatewayLifecycleState();
if (after.state === "healthy_named") {
process.env.OPENSHELL_GATEWAY = "nemoclaw";
return { recovered: true, before, after, attempted: true, via: "select" };
}

const shouldStartGateway = [before.state, after.state].some((state) =>
["missing_named", "named_unhealthy", "named_unreachable", "connected_other"].includes(state),
);

if (shouldStartGateway) {
try {
await startGatewayForRecovery();
} catch {
// Fall through to the lifecycle re-check below so we preserve the
// existing recovery result shape and emit the correct classification.
}
runOpenshell(["gateway", "select", "nemoclaw"], {
ignoreError: true,
timeout: OPENSHELL_OPERATION_TIMEOUT_MS,
});
after = getNamedGatewayLifecycleState();
if (after.state === "healthy_named") {
process.env.OPENSHELL_GATEWAY = "nemoclaw";
return { recovered: true, before, after, attempted: true, via: "start" };
}
}

return { recovered: false, before, after, attempted: true };
}
9 changes: 8 additions & 1 deletion src/lib/global-cli-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
runSetupAction as executeSetupAction,
runSetupSparkAction as executeSetupSparkAction,
} from "./onboard-action";
import { recoverNamedGatewayRuntime as recoverNamedGatewayRuntimeAction } from "./gateway-runtime-action";
import { getNemoClawRuntimeBridge } from "./nemoclaw-runtime-bridge";
import { help, version } from "./root-help-action";

Expand Down Expand Up @@ -53,7 +54,13 @@ export function showVersion(): void {
}

export async function recoverNamedGatewayRuntime(): Promise<{ recovered: boolean }> {
return getNemoClawRuntimeBridge().recoverNamedGatewayRuntime();
const runtime = getNemoClawRuntimeBridge() as {
recoverNamedGatewayRuntime?: () => Promise<{ recovered: boolean }>;
};
if (typeof runtime.recoverNamedGatewayRuntime === "function") {
return runtime.recoverNamedGatewayRuntime();
}
return recoverNamedGatewayRuntimeAction();
}

export function runOpenshellProviderCommand(
Expand Down
9 changes: 4 additions & 5 deletions src/lib/list-command-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import { parseGatewayInference } from "./inference-config";
import { OPENSHELL_PROBE_TIMEOUT_MS } from "./openshell-timeouts";
import { parseSshProcesses, createSystemDeps } from "./sandbox-session-state";
import { resolveOpenshell } from "./resolve-openshell";

import { getNemoClawRuntimeBridge } from "./nemoclaw-runtime-bridge";
import { captureOpenshell } from "./openshell-runtime";
import { recoverRegistryEntries } from "./registry-recovery-action";

export function buildListCommandDeps(): ListSandboxesCommandDeps {
const opsBinList = resolveOpenshell();
const sessionDeps = opsBinList ? createSystemDeps(opsBinList) : null;
const runtime = getNemoClawRuntimeBridge();

// Cache the SSH process probe once for all sandboxes — avoids spawning ps
// per sandbox row. The getSshProcesses() call is the expensive part (5s timeout).
Expand All @@ -32,10 +31,10 @@ export function buildListCommandDeps(): ListSandboxesCommandDeps {
};

return {
recoverRegistryEntries: () => runtime.recoverRegistryEntries(),
recoverRegistryEntries: () => recoverRegistryEntries(),
getLiveInference: () =>
parseGatewayInference(
runtime.captureOpenshell(["inference", "get"], {
captureOpenshell(["inference", "get"], {
ignoreError: true,
timeout: OPENSHELL_PROBE_TIMEOUT_MS,
}).output,
Expand Down
14 changes: 0 additions & 14 deletions src/lib/nemoclaw-runtime-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,17 @@

/* v8 ignore start -- transitional bridge until command actions are extracted from src/nemoclaw.ts. */

import type { RecoveryResult } from "./inventory-commands";

export interface SpawnLikeResult {
status: number | null;
stdout?: string | Buffer;
stderr?: string | Buffer;
}

export interface GatewayRecoveryResult {
recovered: boolean;
}

export interface SandboxConnectOptions {
probeOnly?: boolean;
}

export interface NemoClawRuntimeBridge {
captureOpenshell: (
args: string[],
opts?: { ignoreError?: boolean; timeout?: number },
) => { status: number | null; output: string };
recoverNamedGatewayRuntime: () => Promise<GatewayRecoveryResult>;
recoverRegistryEntries: (options?: {
requestedSandboxName?: string | null;
}) => Promise<RecoveryResult>;
runOpenshell: (
args: string[],
opts?: {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/policy-channel-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from "node:path";

import { CLI_DISPLAY_NAME, CLI_NAME } from "./branding";
import { getCredential, prompt as askPrompt } from "./credentials";
import { getNemoClawRuntimeBridge } from "./nemoclaw-runtime-bridge";
import { recoverNamedGatewayRuntime } from "./gateway-runtime-action";
const { isNonInteractive } = require("./onboard") as { isNonInteractive: () => boolean };
const onboardProviders = require("./onboard-providers");
import * as policies from "./policies";
Expand Down Expand Up @@ -284,7 +284,7 @@ async function applyChannelAddToGatewayAndRegistry(
channelName: string,
acquired: Record<string, string>,
): Promise<void> {
const recovery = await getNemoClawRuntimeBridge().recoverNamedGatewayRuntime();
const recovery = await recoverNamedGatewayRuntime();
if (!recovery.recovered) {
console.error(
` Could not reach the ${CLI_DISPLAY_NAME} OpenShell gateway. Tokens were staged`,
Expand Down Expand Up @@ -324,7 +324,7 @@ async function applyChannelRemoveToGatewayAndRegistry(
channelName: string,
channelTokenKeys: string[],
): Promise<void> {
const recovery = await getNemoClawRuntimeBridge().recoverNamedGatewayRuntime();
const recovery = await recoverNamedGatewayRuntime();
if (!recovery.recovered) {
console.error(
` Could not reach the ${CLI_DISPLAY_NAME} OpenShell gateway to delete the bridge.`,
Expand Down
Loading
Loading