Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ $ nemoclaw my-assistant recover

Show sandbox status, health, and inference configuration.

Pass `--json` to emit a structured per-sandbox report instead of the text renderer.
The JSON output includes at least `schemaVersion`, `name`, `found`, `model`, `provider`, `phase`, `gatewayState`, `inferenceHealth`, `rpcIssue`, `hostGpuDetected`, `sandboxGpuEnabled`, `sandboxGpuMode`, `sandboxGpuDevice`, `openshellDriver`, `openshellVersion`, and `policies`.
`openshellDriver` and `openshellVersion` are always strings (falling back to `"unknown"` when the registry has no value), so consumers can rely on `typeof` checks.
The command exits non-zero when the sandbox is missing locally, the gateway state is not `present`, or the gateway reports a schema/protobuf mismatch (mirrored as `rpcIssue`).
The alias form `nemoclaw <name> status --json` requires the sandbox to be registered locally; the canonical form `nemoclaw sandbox status <name> --json` is the one to use from automation that may run against an unknown sandbox name, since it still emits a JSON document with `found: false` instead of a text error.

```console
$ nemoclaw my-assistant status
$ nemoclaw my-assistant status --json
$ nemoclaw sandbox status my-assistant --json
```

The command probes every inference provider and reports one of three states on the `Inference` line:

| State | Meaning |
Expand Down
24 changes: 20 additions & 4 deletions src/commands/sandbox/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,40 @@

import { NemoClawCommand } from "../../lib/cli/nemoclaw-oclif-command";

import { showSandboxStatus } from "../../lib/actions/sandbox/status";
import { getSandboxStatusReport, showSandboxStatus } from "../../lib/actions/sandbox/status";
import { sandboxNameArg } from "../../lib/sandbox/command-support";
import { redactForLog } from "../../lib/security/redact";

export default class SandboxStatusCommand extends NemoClawCommand {
static id = "sandbox:status";
static strict = true;
static enableJsonFlag = true;
static summary = "Sandbox health and NIM status";
static description = "Show sandbox health, OpenShell gateway state, and local NIM status.";
static usage = ["<name>"];
static examples = ["<%= config.bin %> sandbox status alpha"];
static usage = ["<name> [--json]"];
static examples = [
"<%= config.bin %> sandbox status alpha",
"<%= config.bin %> sandbox status alpha --json",
];
static args = {
sandboxName: sandboxNameArg,
};
static flags = {
};

public async run(): Promise<void> {
public async run(): Promise<unknown> {
const { args } = await this.parse(SandboxStatusCommand);
if (this.jsonEnabled()) {
const report = await getSandboxStatusReport(args.sandboxName);
if (!report.found || report.gatewayState !== "present" || report.rpcIssue) {
process.exitCode = 1;
}
// #4310: route the machine-readable report through the centralized
// redactForLog source of truth so health diagnostics (inferenceHealth
// endpoint/detail/subprobes) cannot leak token-shaped values into
// automation that persists CLI JSON output.
return redactForLog(report);
}
await showSandboxStatus(args.sandboxName);
}
}
197 changes: 136 additions & 61 deletions src/lib/actions/sandbox/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,134 @@ export function getSandboxStatusInferenceHealth(
});
}

export interface SandboxStatusReport {
schemaVersion: 1;
name: string;
found: boolean;
model: string;
provider: string;
phase: string | null;
gatewayState: string;
inferenceHealth: ProviderHealthStatus | null;
rpcIssue: { kind: "image_drift" | "protobuf_mismatch" } | null;
hostGpuDetected: boolean;
sandboxGpuEnabled: boolean;
sandboxGpuMode: string | null;
sandboxGpuDevice: string | null;
openshellDriver: string;
openshellVersion: string;
policies: string[];
}

interface SandboxStatusSnapshot {
sb: registry.SandboxEntry | null;
lookup: SandboxGatewayState;
rpcIssue: ReturnType<typeof detectOpenShellStateRpcResultIssue>;
currentModel: string;
currentProvider: string;
inferenceHealth: ProviderHealthStatus | null;
}

async function collectSandboxStatusSnapshot(
sandboxName: string,
): Promise<SandboxStatusSnapshot> {
const sb = registry.getSandbox(sandboxName);
let lookup: SandboxGatewayState;
try {
lookup = await getReconciledSandboxGatewayState(sandboxName, {
getState: getSandboxGatewayStateForStatus,
});
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
lookup = {
state: "gateway_error",
output: ` Could not probe live gateway state: ${message}`,
};
}
let liveResult: Awaited<ReturnType<typeof captureOpenshellForStatus>> | null = null;
if (lookup.state === "present") {
try {
liveResult = await captureOpenshellForStatus(["inference", "get"]);
} catch {
liveResult = null;
}
}
const rpcIssue = liveResult ? detectOpenShellStateRpcResultIssue(liveResult) : null;
if (rpcIssue) {
return {
sb,
lookup,
rpcIssue,
currentModel: "unknown",
currentProvider: "unknown",
inferenceHealth: null,
};
}
const live =
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";
const inferenceHealth = getSandboxStatusInferenceHealth(
lookup.state === "present",
currentProvider,
currentModel,
);
if (
inferenceHealth &&
lookup.state === "present" &&
(currentProvider === "ollama-local" || currentProvider === "vllm-local")
) {
const gatewayChain = await probeSandboxInferenceGatewayHealth(sandboxName);
if (gatewayChain) {
const gatewaySubprobe: ProviderHealthStatus = {
ok: gatewayChain.ok,
probed: true,
providerLabel: "Inference gateway chain",
endpoint: gatewayChain.endpoint,
detail: gatewayChain.detail,
probeLabel: "gateway",
...(gatewayChain.ok ? {} : { failureLabel: "unreachable" as const }),
};
inferenceHealth.subprobes = [...(inferenceHealth.subprobes ?? []), gatewaySubprobe];
}
}
return { sb, lookup, rpcIssue, currentModel, currentProvider, inferenceHealth };
}

export async function getSandboxStatusReport(
sandboxName: string,
): Promise<SandboxStatusReport> {
const snapshot = await collectSandboxStatusSnapshot(sandboxName);
const { sb, lookup, rpcIssue, currentModel, currentProvider, inferenceHealth } = snapshot;
const phase =
lookup.state === "present" ? parseSandboxPhase(lookup.output || "") : null;
const sandboxGpuEnabled = sb
? (sb.sandboxGpuEnabled ?? (sb.gpuEnabled === true))
: false;
const policies =
sb && Array.isArray(sb.policies)
? sb.policies.filter((policy): policy is string => typeof policy === "string")
: [];
return {
schemaVersion: 1,
name: sandboxName,
found: !!sb,
model: currentModel,
provider: currentProvider,
phase,
gatewayState: lookup.state,
inferenceHealth,
rpcIssue: rpcIssue ? { kind: rpcIssue.kind } : null,
hostGpuDetected: !!(sb && sb.hostGpuDetected),
sandboxGpuEnabled,
sandboxGpuMode: (sb && sb.sandboxGpuMode) || null,
sandboxGpuDevice: (sb && sb.sandboxGpuDevice) || null,
openshellDriver: (sb && sb.openshellDriver) || "unknown",
openshellVersion: (sb && sb.openshellVersion) || "unknown",
policies,
};
}

/**
* Render one Inference status line. The main probe and each subprobe go
* through this helper so multi-hop providers (e.g. ollama-local backend +
Expand Down Expand Up @@ -113,73 +241,20 @@ async function printGatewayFailureLayerHeader(sandboxName: string): Promise<void

// eslint-disable-next-line complexity
export async function showSandboxStatus(sandboxName: string): Promise<void> {
const sb = registry.getSandbox(sandboxName);
maybeEnsureHermesToolGatewayBroker(sb);
// #2666: never let an unexpected throw from the gateway probe (e.g. openshell
// hanging when its container is stopped and the published port is held by a
// foreign listener) suppress the sandbox header. The downstream switch
// handles `gateway_error` by printing an actionable block + exit(1), so a
// synthesized fallback keeps the user-visible contract intact.
let lookup: SandboxGatewayState;
try {
lookup = await getReconciledSandboxGatewayState(sandboxName, {
getState: getSandboxGatewayStateForStatus,
const snapshot = await collectSandboxStatusSnapshot(sandboxName);
const { sb, lookup, rpcIssue, currentModel, currentProvider, inferenceHealth } = snapshot;
maybeEnsureHermesToolGatewayBroker(sb);
if (rpcIssue) {
printOpenShellStateRpcIssue(rpcIssue, {
action: `checking inference status for sandbox '${sandboxName}'`,
command: `${CLI_NAME} ${sandboxName} status`,
});
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
lookup = {
state: "gateway_error",
output: ` Could not probe live gateway state: ${message}`,
};
}
let liveResult: Awaited<ReturnType<typeof captureOpenshellForStatus>> | null = null;
if (lookup.state === "present") {
try {
liveResult = await captureOpenshellForStatus(["inference", "get"]);
} catch {
liveResult = null;
}
}
if (liveResult) {
const inferenceIssue = detectOpenShellStateRpcResultIssue(liveResult);
if (inferenceIssue) {
printOpenShellStateRpcIssue(inferenceIssue, {
action: `checking inference status for sandbox '${sandboxName}'`,
command: `${CLI_NAME} ${sandboxName} status`,
});
process.exit(1);
}
}
const live =
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";
const inferenceHealth = getSandboxStatusInferenceHealth(
lookup.state === "present",
currentProvider,
currentModel,
);
// #3265 optional 3rd line: probe the full inference chain (openclaw gateway
// → auth proxy → backend) from inside the sandbox so a broken hop the
// host-side probes can't see still surfaces in `status`.
if (
inferenceHealth &&
lookup.state === "present" &&
(currentProvider === "ollama-local" || currentProvider === "vllm-local")
) {
const gatewayChain = await probeSandboxInferenceGatewayHealth(sandboxName);
if (gatewayChain) {
const gatewaySubprobe: ProviderHealthStatus = {
ok: gatewayChain.ok,
probed: true,
providerLabel: "Inference gateway chain",
endpoint: gatewayChain.endpoint,
detail: gatewayChain.detail,
probeLabel: "gateway",
...(gatewayChain.ok ? {} : { failureLabel: "unreachable" as const }),
};
inferenceHealth.subprobes = [...(inferenceHealth.subprobes ?? []), gatewaySubprobe];
}
process.exit(1);
}
if (sb) {
console.log("");
Expand Down
Loading
Loading