Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c690f07
refactor(openshell): remove diagnostic SSH transport
ericksoa Jul 13, 2026
f36fc05
chore(stack): carry rebuild probe updates
ericksoa Jul 13, 2026
811f02f
chore(stack): carry automated review fixes
ericksoa Jul 14, 2026
01c643e
chore(stack): carry formatted review fixture
ericksoa Jul 14, 2026
cbf5071
chore(stack): carry current main
ericksoa Jul 14, 2026
88d54da
chore(stack): pair protocol with its first consumer
ericksoa Jul 14, 2026
6f135a2
chore(stack): carry IPv6 loopback coverage
ericksoa Jul 14, 2026
db66f65
chore(stack): align with externally advanced base
ericksoa Jul 14, 2026
a689db3
chore(stack): follow consolidated gRPC foundation
ericksoa Jul 14, 2026
9e45995
chore(stack): follow current main
ericksoa Jul 14, 2026
7545c04
chore(stack): follow stdin regression coverage
ericksoa Jul 14, 2026
bba0200
chore(stack): follow documented fallback boundary
ericksoa Jul 14, 2026
ca5a311
chore(stack): follow reviewed read-only boundary
ericksoa Jul 14, 2026
069eec9
chore(stack): follow skill retry guardrail fix
ericksoa Jul 14, 2026
3c4055d
chore(stack): follow fail-closed skill probe
ericksoa Jul 14, 2026
e4f1bc0
docs(openshell): include debug fallback caller
ericksoa Jul 14, 2026
d171233
test(debug): cover async command completion
ericksoa Jul 14, 2026
9c1abfc
fix(debug): preserve sandbox transport failures
ericksoa Jul 14, 2026
3d6d055
chore(stack): follow guarded rebuild transport
ericksoa Jul 14, 2026
d071ed4
fix(debug): redact combined sandbox streams
ericksoa Jul 14, 2026
3c6239d
chore(stack): follow endpoint-safe rebuild transport
ericksoa Jul 14, 2026
a9297cb
test(checks): review debug gRPC fallback
ericksoa Jul 14, 2026
82ce753
chore(stack): follow hardened rebuild transport
ericksoa Jul 14, 2026
e722d26
Merge commit '39ce3ec491f29c0eedf0844e4836c410b3eb548c' into refactor…
ericksoa Jul 14, 2026
57b096e
fix(cli): redact debug gateway resolution errors
ericksoa Jul 14, 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
3 changes: 1 addition & 2 deletions scripts/checks/legacy-sandbox-transports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ const REVIEWED_SITE_TUPLES = [
["src/lib/adapters/docker/container.ts", "docker-exec-command", 1],
["src/lib/adapters/openshell/client.ts", "openshell-ssh-config", 1],
["src/lib/adapters/openshell/runtime.ts", "openshell-ssh-config", 1],
["src/lib/diagnostics/debug.ts", "openshell-ssh-config", 1],
["src/lib/diagnostics/debug.ts", "ssh-command", 4],
["src/lib/diagnostics/debug.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/onboard.ts", "docker-exec-builder", 1],
["src/lib/resources-cmd.ts", "docker-exec-command", 1],
["src/lib/sandbox/config.ts", "privileged-sandbox-exec", 2],
Expand Down
17 changes: 8 additions & 9 deletions src/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// SPDX-License-Identifier: Apache-2.0

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

import type { CaptureOpenshellResult } from "../lib/adapters/openshell/client";
import { captureOpenshellCommand } from "../lib/adapters/openshell/client";
import { resolveOpenshell } from "../lib/adapters/openshell/resolve";
import { OPENSHELL_PROBE_TIMEOUT_MS } from "../lib/adapters/openshell/timeouts";
import { CLI_NAME } from "../lib/cli/branding";
import { runDebug } from "../lib/diagnostics/debug";
import { NemoClawCommand } from "../lib/cli/nemoclaw-oclif-command";
import type { DebugOptions } from "../lib/diagnostics/debug";
import { runDebug } from "../lib/diagnostics/debug";
import type { RunDebugCommandDeps } from "../lib/diagnostics/debug-command";
import { runDebugCommandWithOptions } from "../lib/diagnostics/debug-command";
import type { CaptureOpenshellResult } from "../lib/adapters/openshell/client";
import { captureOpenshellCommand } from "../lib/adapters/openshell/client";
import { OPENSHELL_PROBE_TIMEOUT_MS } from "../lib/adapters/openshell/timeouts";
import * as registry from "../lib/state/registry";
import { resolveOpenshell } from "../lib/adapters/openshell/resolve";
import { parseLiveSandboxNames } from "../lib/runtime-recovery";
import * as registry from "../lib/state/registry";

const useColor = !process.env.NO_COLOR && !!process.stderr.isTTY;
const B = useColor ? "\x1b[1m" : "";
Expand Down Expand Up @@ -99,6 +98,6 @@ export default class DebugCliCommand extends NemoClawCommand {
if (flags.quick) options.quick = true;
if (flags.output) options.output = flags.output;
if (flags.sandbox) options.sandboxName = flags.sandbox;
runDebugCommandWithOptions(options, buildDebugCommandDeps(this.config.root));
await runDebugCommandWithOptions(options, buildDebugCommandDeps(this.config.root));
}
}
9 changes: 8 additions & 1 deletion src/commands/simple-global-oclif-adapters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const mocks = vi.hoisted(() => {
captureOpenshellCommand: vi.fn(() => ({ status: 0, output: "alpha\n" })),
listSandboxes: vi.fn(() => ({ sandboxes: [] })),
resolveOpenshell: vi.fn(() => "/usr/bin/openshell"),
runDebugCommandWithOptions: vi.fn(),
runDebugCommandWithOptions: vi.fn().mockResolvedValue(undefined),
runDeployAction: vi.fn().mockResolvedValue(undefined),
runDashboardUrlCommand: vi.fn(() => undefined),
runGatewayTokenCommand: vi.fn(() => undefined),
Expand Down Expand Up @@ -145,6 +145,13 @@ describe("simple global oclif adapters", () => {
expect(configure).not.toHaveBeenCalledWith({ debug: false, quiet: true });
});

it("propagates a rejected debug action through the CLI boundary", async () => {
const failure = new Error("diagnostic collection failed");
mocks.runDebugCommandWithOptions.mockRejectedValueOnce(failure);

await expect(DebugCliCommand.run(["--quick"], rootDir)).rejects.toBe(failure);
});

it("builds debug defaults from the sandbox registry and OpenShell liveness", async () => {
mocks.listSandboxes.mockReturnValue({
defaultSandbox: "alpha",
Expand Down
11 changes: 6 additions & 5 deletions src/lib/adapters/openshell/sandbox-control-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ export function selectOpenShellSandboxControlForMutation(
* so NemoClaw cannot replace that path here.
*
* This migration contract is limited to the reviewed read-only callers (the
* session list and rebuild file probe at this slice), not a general routing
* policy. Remove the CLI fallback when OpenShell's public client or bindings
* support the edge-tunnel auth and credential-refresh lifecycle. Every added
* caller requires a replay-semantics review; mutations must select one
* transport before dispatch and must never be replayed automatically.
* session list, rebuild file probe, and debug diagnostic probes at this
* slice), not a general routing policy. Remove the CLI fallback when
* OpenShell's public client or bindings support the edge-tunnel auth and
* credential-refresh lifecycle. Every added caller requires a replay-semantics
* review; mutations must select one transport before dispatch and must never
* be replayed automatically.
*/
export async function execSandboxReadOnlyWithGrpcFallback(
gatewayName: string,
Expand Down
67 changes: 52 additions & 15 deletions src/lib/diagnostics/debug-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { describe, expect, it, vi } from "vitest";
import { runDebugCommandWithOptions } from "./debug-command";

describe("debug command", () => {
it("runs parsed debug options and falls back to the default sandbox", () => {
const runDebug = vi.fn();
runDebugCommandWithOptions(
it("runs parsed debug options and falls back to the default sandbox", async () => {
const runDebug = vi.fn().mockResolvedValue(undefined);
await runDebugCommandWithOptions(
{ quick: true, output: "/tmp/out.tgz" },
{
getDefaultSandbox: () => "alpha",
Expand All @@ -23,10 +23,10 @@ describe("debug command", () => {
});
});

it("accepts an explicit --sandbox name that is registered", () => {
const runDebug = vi.fn();
it("accepts an explicit --sandbox name that is registered", async () => {
const runDebug = vi.fn().mockResolvedValue(undefined);
const isSandboxKnown = vi.fn().mockReturnValue(true);
runDebugCommandWithOptions(
await runDebugCommandWithOptions(
{ sandboxName: "alpha" },
{
getDefaultSandbox: () => undefined,
Expand All @@ -38,6 +38,43 @@ describe("debug command", () => {
expect(runDebug).toHaveBeenCalledWith({ sandboxName: "alpha" });
});

it("returns the debug operation completion promise", async () => {
let resolveDebug!: () => void;
const debugCompletion = new Promise<void>((resolve) => {
resolveDebug = resolve;
});
const runDebug = vi.fn(() => debugCompletion);

const completion = runDebugCommandWithOptions(
{ quick: true },
{
getDefaultSandbox: () => "alpha",
isSandboxKnown: () => true,
runDebug,
},
);

expect(completion).toBe(debugCompletion);
resolveDebug();
await expect(completion).resolves.toBeUndefined();
});

it("propagates a rejected debug operation", async () => {
const failure = new Error("diagnostic collection failed");
const runDebug = vi.fn().mockRejectedValue(failure);

await expect(
runDebugCommandWithOptions(
{ quick: true },
{
getDefaultSandbox: () => "alpha",
isSandboxKnown: () => true,
runDebug,
},
),
).rejects.toBe(failure);
});

it("rejects an explicit --sandbox name that is not registered, exits non-zero, skips runDebug", () => {
const runDebug = vi.fn();
const errorLines: string[] = [];
Expand Down Expand Up @@ -88,10 +125,10 @@ describe("debug command", () => {
expect(errorLines[0]).toContain("NEMOCLAW_SANDBOX_NAME");
});

it("prefers NEMOCLAW_SANDBOX_NAME over NEMOCLAW_SANDBOX and SANDBOX_NAME", () => {
const runDebug = vi.fn();
it("prefers NEMOCLAW_SANDBOX_NAME over NEMOCLAW_SANDBOX and SANDBOX_NAME", async () => {
const runDebug = vi.fn().mockResolvedValue(undefined);
const isSandboxKnown = vi.fn().mockReturnValue(true);
runDebugCommandWithOptions(
await runDebugCommandWithOptions(
{},
{
env: {
Expand All @@ -108,10 +145,10 @@ describe("debug command", () => {
expect(runDebug).toHaveBeenCalledWith({ sandboxName: "primary" });
});

it("flag overrides env vars when both are present", () => {
const runDebug = vi.fn();
it("flag overrides env vars when both are present", async () => {
const runDebug = vi.fn().mockResolvedValue(undefined);
const isSandboxKnown = vi.fn().mockReturnValue(true);
runDebugCommandWithOptions(
await runDebugCommandWithOptions(
{ sandboxName: "alpha" },
{
env: { NEMOCLAW_SANDBOX: "beta" } as NodeJS.ProcessEnv,
Expand All @@ -125,10 +162,10 @@ describe("debug command", () => {
expect(runDebug).toHaveBeenCalledWith({ sandboxName: "alpha" });
});

it("falls back to getDefaultSandbox when neither flag nor env is set", () => {
const runDebug = vi.fn();
it("falls back to getDefaultSandbox when neither flag nor env is set", async () => {
const runDebug = vi.fn().mockResolvedValue(undefined);
const isSandboxKnown = vi.fn();
runDebugCommandWithOptions(
await runDebugCommandWithOptions(
{},
{
env: {} as NodeJS.ProcessEnv,
Expand Down
11 changes: 7 additions & 4 deletions src/lib/diagnostics/debug-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { DebugOptions } from "./debug";
export interface RunDebugCommandDeps {
getDefaultSandbox: () => string | undefined;
isSandboxKnown: (name: string) => boolean;
runDebug: (options: DebugOptions) => void;
runDebug: (options: DebugOptions) => Promise<void>;
env?: NodeJS.ProcessEnv;
errorLine?: (message: string) => void;
exit?: (code: number) => never;
Expand All @@ -31,7 +31,10 @@ function resolveExplicitName(
return null;
}

export function runDebugCommandWithOptions(options: DebugOptions, deps: RunDebugCommandDeps): void {
export function runDebugCommandWithOptions(
options: DebugOptions,
deps: RunDebugCommandDeps,
): Promise<void> {
const opts = { ...options };
const env = deps.env ?? process.env;
const errorLine = deps.errorLine ?? ((msg: string) => console.error(msg));
Expand All @@ -49,12 +52,12 @@ export function runDebugCommandWithOptions(options: DebugOptions, deps: RunDebug
errorLine(`Error: Sandbox '${explicit.name}'${sourceLabel} is not registered.`);
errorLine(" Run `nemoclaw list` to see available sandboxes.");
exit(1);
return;
return Promise.resolve();
}
opts.sandboxName = explicit.name;
} else {
opts.sandboxName = deps.getDefaultSandbox();
}

deps.runDebug(opts);
return deps.runDebug(opts);
}
155 changes: 155 additions & 0 deletions src/lib/diagnostics/debug-sandbox-internals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

const { execSandbox, getSandbox, listSandboxes } = vi.hoisted(() => ({
execSandbox: vi.fn(),
getSandbox: vi.fn(),
listSandboxes: vi.fn(),
}));

const { execFileSync } = vi.hoisted(() => ({ execFileSync: vi.fn() }));

vi.mock("../adapters/openshell/sandbox-control-routing", () => ({
execSandboxReadOnlyWithGrpcFallback: execSandbox,
}));
vi.mock("../state/registry", () => ({ getSandbox, listSandboxes }));
vi.mock("node:child_process", async (importOriginal) => ({
...(await importOriginal<typeof import("node:child_process")>()),
execFileSync,
}));

import { collectSandboxInternals } from "./debug";

describe("collectSandboxInternals", () => {
let collectDir: string;

beforeEach(() => {
collectDir = mkdtempSync(join(tmpdir(), "nemoclaw-debug-sandbox-"));
execFileSync.mockReturnValue(Buffer.alloc(0));
getSandbox.mockReturnValue({ gatewayPort: 19080 });
execSandbox.mockResolvedValue({ status: 0, stdout: "ok", stderr: "" });
});

afterEach(() => {
rmSync(collectDir, { force: true, recursive: true });
vi.clearAllMocks();
});

it("collects the quick command set through the sandbox's named gateway", async () => {
await collectSandboxInternals(collectDir, "alpha", true);

expect(execSandbox.mock.calls).toEqual([
["nemoclaw-19080", { sandboxName: "alpha", command: ["ps", "-ef"], timeoutMs: 30_000 }],
["nemoclaw-19080", { sandboxName: "alpha", command: ["free", "-m"], timeoutMs: 30_000 }],
]);
expect(readFileSync(join(collectDir, "sandbox-ps.txt"), "utf8")).toBe("ok\n");
});

it("adds top and gateway-log collection outside quick mode and redacts output", async () => {
execSandbox.mockResolvedValue({
status: 0,
stdout: "API_KEY=secret-value",
stderr: "",
});

await collectSandboxInternals(collectDir, "alpha", false);

expect(execSandbox.mock.calls.map((call) => call[1].command)).toEqual([
["ps", "-ef"],
["free", "-m"],
["top", "-b", "-n", "1"],
["tail", "-200", "/tmp/gateway.log"],
]);
expect(readFileSync(join(collectDir, "sandbox-gateway-log.txt"), "utf8")).toBe(
"API_KEY=<REDACTED>\n",
);
});

it("keeps missing CLI and unregistered targets nonfatal", async () => {
execFileSync.mockImplementationOnce(() => {
throw new Error("not found");
});
await expect(collectSandboxInternals(collectDir, "alpha", true)).resolves.toBeUndefined();
expect(execSandbox).not.toHaveBeenCalled();

execFileSync.mockReturnValue(Buffer.alloc(0));
getSandbox.mockReturnValue(undefined);
await expect(collectSandboxInternals(collectDir, "alpha", true)).resolves.toBeUndefined();
expect(execSandbox).not.toHaveBeenCalled();
});

it("redacts credential-shaped invalid gateway bindings from terminal warnings", async () => {
const secret = ["sk-proj", "debugregistrycredential"].join("-");
getSandbox.mockReturnValue({ gatewayName: secret });
const consoleLog = vi.spyOn(console, "log").mockImplementation(() => undefined);

try {
await collectSandboxInternals(collectDir, "alpha", true);

const terminalOutput = consoleLog.mock.calls.flat().join("\n");
expect(terminalOutput).not.toContain(secret);
expect(terminalOutput).toContain("<REDACTED>");
expect(execSandbox).not.toHaveBeenCalled();
} finally {
consoleLog.mockRestore();
}
});

it("records one routing failure and continues collecting", async () => {
execSandbox
.mockRejectedValueOnce(new Error("API_KEY=secret-value"))
.mockResolvedValue({ status: 0, stdout: "free-ok", stderr: "" });

await collectSandboxInternals(collectDir, "alpha", true);

expect(execSandbox).toHaveBeenCalledTimes(2);
expect(readFileSync(join(collectDir, "sandbox-ps.txt"), "utf8")).toBe(
" (sandbox command failed: API_KEY=<REDACTED>)\n",
);
expect(readFileSync(join(collectDir, "sandbox-free.txt"), "utf8")).toBe("free-ok\n");
});

it("records resolved transport errors with partial output and continues collecting", async () => {
execSandbox
.mockResolvedValueOnce({
status: null,
stdout: "partial output",
stderr: "partial warning",
error: new Error("API_KEY=secret-value"),
})
.mockResolvedValue({ status: 0, stdout: "free-ok", stderr: "" });

await collectSandboxInternals(collectDir, "alpha", true);

expect(execSandbox).toHaveBeenCalledTimes(2);
expect(readFileSync(join(collectDir, "sandbox-ps.txt"), "utf8")).toBe(
[
"partial output",
"partial warning",
" (sandbox command failed; detail follows)",
"API_KEY=<REDACTED>",
"",
].join("\n"),
);
expect(readFileSync(join(collectDir, "sandbox-free.txt"), "utf8")).toBe("free-ok\n");
});

it("redacts credentials split across stdout and stderr as one stream", async () => {
execSandbox.mockResolvedValue({
status: 0,
stdout: "Authorization: Bearer",
stderr: " secret-value",
});

await collectSandboxInternals(collectDir, "alpha", true);

expect(readFileSync(join(collectDir, "sandbox-ps.txt"), "utf8")).toBe(
"Authorization: <REDACTED>",
);
});
});
Loading