Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
64e5e67
refactor(openshell): unify CLI exec capture
ericksoa Jul 13, 2026
7115ff2
refactor(snapshot): remove Kubernetes image probe
ericksoa Jul 13, 2026
5a7ad4f
chore(stack): carry snapshot failure diagnostics
ericksoa Jul 14, 2026
8237782
chore(stack): carry snapshot failure diagnostics
ericksoa Jul 14, 2026
e6b48f7
chore(stack): carry snapshot stdin fixture fix
ericksoa Jul 14, 2026
48deddf
chore(stack): carry snapshot stdin fixture fix
ericksoa Jul 14, 2026
0df8262
chore(stack): carry snapshot restore diagnostics
ericksoa Jul 14, 2026
986c284
chore(stack): carry snapshot restore diagnostics
ericksoa Jul 14, 2026
8c9bc0e
chore(stack): carry OpenShell config isolation fix
ericksoa Jul 14, 2026
79c9c5a
chore(stack): carry OpenShell config isolation fix
ericksoa Jul 14, 2026
febe2a6
chore(stack): carry read-only gRPC fallback
ericksoa Jul 14, 2026
6d7fba0
chore(stack): carry read-only gRPC fallback
ericksoa Jul 14, 2026
abbc249
chore(stack): follow reviewed share transport head
ericksoa Jul 15, 2026
19b0a67
feat(openshell): read sandbox descriptors over gRPC
ericksoa Jul 15, 2026
013b6f9
refactor(snapshot): read source image over gRPC
ericksoa Jul 15, 2026
6ebca2c
test(snapshot): bound descriptor preload seam
ericksoa Jul 15, 2026
7a3d3ff
ci: retry PR advisor analysis
ericksoa Jul 15, 2026
2c37978
chore(stack): follow final descriptor preload head
ericksoa Jul 15, 2026
77e6553
refactor(snapshot): pin live restore source descriptors
ericksoa Jul 15, 2026
7d78a80
test(snapshot): keep descriptor checks linear
ericksoa Jul 15, 2026
0b3695e
fix(snapshot): describe source recheck boundary
ericksoa Jul 15, 2026
c821e58
refactor(openshell): remove gateway-stop kubectl path (#6812)
ericksoa Jul 20, 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
2 changes: 0 additions & 2 deletions scripts/checks/legacy-sandbox-transports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const REVIEWED_SITE_TUPLES = [
["src/lib/actions/sandbox/host-aliases.ts", "docker-exec-command", 1],
["src/lib/actions/sandbox/sessions/passthrough.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/actions/sandbox/process-recovery.ts", "privileged-sandbox-exec", 2],
["src/lib/actions/sandbox/snapshot.ts", "docker-exec-command", 1],
["src/lib/adapters/docker/container.ts", "docker-exec-command", 1],
["src/lib/diagnostics/debug.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/onboard.ts", "docker-exec-builder", 1],
Expand All @@ -54,7 +53,6 @@ const REVIEWED_SITE_TUPLES = [
["src/lib/state/openclaw-plugin-restore.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/state/sandbox.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/state/user-managed-files-probe.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/tunnel/sandbox-gateway-stop.ts", "docker-exec-command", 2],
] as const satisfies readonly ReviewedSiteTuple[];

export const REVIEWED_LEGACY_SANDBOX_TRANSPORT_SITES: readonly LegacySandboxTransportSite[] =
Expand Down
6 changes: 3 additions & 3 deletions src/commands/sandbox/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const rootDir = process.cwd();

describe("SandboxStopCommand", () => {
beforeEach(() => {
stopSandbox.mockClear();
stopSandbox.mockReturnValue({ exitCode: 0 });
stopSandbox.mockReset();
stopSandbox.mockResolvedValue({ exitCode: 0 });
});

afterEach(() => {
Expand All @@ -30,7 +30,7 @@ describe("SandboxStopCommand", () => {

it("propagates the action's failure exit code (#6026)", async () => {
const error = vi.spyOn(console, "error").mockImplementation(() => {});
stopSandbox.mockReturnValue({ exitCode: 1, message: " boom" });
stopSandbox.mockResolvedValue({ exitCode: 1, message: " boom" });

await SandboxStopCommand.run(["alpha"], rootDir);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/sandbox/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export default class SandboxStopCommand extends NemoClawCommand {

public async run(): Promise<void> {
const { args } = await this.parse(SandboxStopCommand);
this.applyExitResult(stopSandbox(args.sandboxName));
this.applyExitResult(await stopSandbox(args.sandboxName));
}
}
2 changes: 1 addition & 1 deletion src/commands/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export default class DeprecatedStopCommand extends NemoClawCommand {

public async run(): Promise<void> {
await this.parse(DeprecatedStopCommand);
runStopCommand({ ...serviceDeps(), stopAll, releaseGatewayPort: true });
await runStopCommand({ ...serviceDeps(), stopAll, releaseGatewayPort: true });
}
}
7 changes: 3 additions & 4 deletions src/commands/tunnel/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

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

import { stopAll } from "../../lib/tunnel/services";
import { runStopCommand } from "../../lib/tunnel/service-command";
import { serviceDeps } from "../../lib/tunnel/command-support";
import { runStopCommand } from "../../lib/tunnel/service-command";
import { stopAll } from "../../lib/tunnel/services";

export default class TunnelStopCommand extends NemoClawCommand {
static id = "tunnel:stop";
Expand All @@ -18,6 +17,6 @@ export default class TunnelStopCommand extends NemoClawCommand {

public async run(): Promise<void> {
await this.parse(TunnelStopCommand);
runStopCommand({ ...serviceDeps(), stopAll });
await runStopCommand({ ...serviceDeps(), stopAll });
}
}
2 changes: 1 addition & 1 deletion src/lib/actions/sandbox/destroy-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("destroySandbox flow", () => {
});

it("selects the sandbox gateway, deletes live resources, cleans host state, and removes registry state", async () => {
const harness = createDestroyHarness();
const harness = createDestroyHarness({ registeredSandboxCount: 1 });

await expect(
harness.destroySandbox("alpha", { yes: true, cleanupGateway: true }),
Expand Down
18 changes: 9 additions & 9 deletions src/lib/actions/sandbox/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import { resolveNemoclawStateDir } from "../../state/paths";
import * as registry from "../../state/registry";
import { confirmSandboxDestroy } from "./destroy-confirmation";
import { executeSandboxDestroy } from "./destroy-execution";
import { shouldCleanupGatewayAfterConfirmedFinalDestroy } from "./destroy-gateway-cleanup";
import { cleanupGatewayAfterLastSandbox } from "./destroy-gateway";
import { shouldCleanupGatewayAfterConfirmedFinalDestroy } from "./destroy-gateway-cleanup";
import { prepareSandboxDestroy } from "./destroy-preflight";
import { type WipeSandboxStateDeps, wipeSandboxState } from "./wipe-state";

Expand All @@ -57,7 +57,7 @@ type RunOpenshell = (args: string[], opts?: Record<string, unknown>) => { status

export type CleanupSandboxServicesDeps = {
getSandbox?: typeof registry.getSandbox;
stopAll?: (opts: { sandboxName: string }) => void;
stopAll?: (opts: { sandboxName: string; skipSandboxStop: true }) => Promise<void>;
unloadOllamaModels?: () => void;
runOpenshell?: RunOpenshell;
rmSync?: typeof fs.rmSync;
Expand Down Expand Up @@ -99,11 +99,11 @@ async function resolveCleanupGatewayDecision(options: DestroySandboxOptions): Pr
return trimmed === "y" || trimmed === "yes";
}

export function cleanupSandboxServices(
export async function cleanupSandboxServices(
sandboxName: string,
{ stopHostServices = false }: { stopHostServices?: boolean } = {},
deps: CleanupSandboxServicesDeps = {},
): void {
): Promise<void> {
// Source boundary: this exported helper can be called independently of CLI
// dispatch, including from forced local recovery. Validate once before every
// host and provider cleanup side effect, then derive the PID path from that
Expand All @@ -114,11 +114,11 @@ export function cleanupSandboxServices(
const getSandbox = deps.getSandbox ?? registry.getSandbox;
const stopAll =
deps.stopAll ??
((opts: { sandboxName: string }) => {
((opts: { sandboxName: string; skipSandboxStop: true }) => {
const services = require("../../tunnel/services") as {
stopAll: (opts: { sandboxName: string }) => void;
stopAll: (opts: { sandboxName: string; skipSandboxStop: true }) => Promise<void>;
};
services.stopAll(opts);
return services.stopAll(opts);
});
const unloadOllamaModels =
deps.unloadOllamaModels ??
Expand All @@ -141,7 +141,7 @@ export function cleanupSandboxServices(
if (stopHostServices) {
// `stopAll()` already runs `unloadOllamaModels()` unconditionally —
// see src/lib/tunnel/services.ts. Don't double-call here.
stopAll({ sandboxName: validatedSandboxName });
await stopAll({ sandboxName: validatedSandboxName, skipSandboxStop: true });
} else {
// No global stop, so `stopAll()` did not run; explicitly free Ollama
// models for this sandbox if its provider used Ollama. Without this
Expand Down Expand Up @@ -380,7 +380,7 @@ async function destroySandboxUnlocked(
sandboxStillRegistered: !!registry.getSandbox(sandboxName),
});

cleanupSandboxServices(sandboxName, {
await cleanupSandboxServices(sandboxName, {
stopHostServices: shouldStopHostServices,
});
// The sandbox's gateway was captured before the registry entry is removed —
Expand Down
8 changes: 8 additions & 0 deletions src/lib/actions/sandbox/snapshot-auto-create-failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const getSandboxMock = vi.fn((name?: string) =>
);
const registerSandboxMock = vi.fn();
const restoreSandboxStateMock = vi.fn();
const getOpenShellSandboxDescriptorMock = vi.fn(async (_gateway: string, name: string) => ({
id: `${name}-id`,
name,
image: "nemoclaw-alpha:live",
}));
const streamSandboxCreateMock = vi.fn<SnapshotStreamSandboxCreateMock>(async () => ({
status: 7,
output: "create failed before registry write",
Expand All @@ -33,6 +38,9 @@ vi.mock("../../adapters/openshell/runtime", () => ({
getOpenshellBinary: vi.fn(() => "openshell"),
runOpenshell: vi.fn(() => ({ status: 0, output: "" })),
}));
vi.mock("../../adapters/openshell/sandbox-control-routing", () => ({
getOpenShellSandboxDescriptor: getOpenShellSandboxDescriptorMock,
}));
vi.mock("../../credentials/store", () => ({ prompt: vi.fn() }));
vi.mock("../../domain/sandbox/destroy", () => ({
getSandboxDeleteOutcome: vi.fn(() => ({ alreadyGone: false, gatewayUnreachable: false })),
Expand Down
56 changes: 56 additions & 0 deletions src/lib/actions/sandbox/snapshot-restore-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ describe("runSandboxSnapshot restore: lifecycle and destination safety", () => {
});

it("hardens an active timer window before force-deleting a restore destination", async () => {
f.getOpenShellSandboxDescriptorMock.mockResolvedValue({
id: "alpha-id",
name: "alpha",
image: "nemoclaw-alpha:live-descriptor",
});
f.lifecycleMock.readTimerMarkerMock.mockReturnValue({
pid: 4242,
sandboxName: "beta",
Expand Down Expand Up @@ -246,9 +251,60 @@ describe("runSandboxSnapshot restore: lifecycle and destination safety", () => {
f.lifecycleMock.events.indexOf("cleanup-shields"),
);
expect(f.streamSandboxCreateMock).toHaveBeenCalled();
expect(f.getOpenShellSandboxDescriptorMock).toHaveBeenNthCalledWith(1, "nemoclaw", "alpha");
expect(f.getOpenShellSandboxDescriptorMock).toHaveBeenNthCalledWith(2, "nemoclaw", "alpha");
expect(f.getOpenShellSandboxDescriptorMock).toHaveBeenCalledTimes(2);
expect(f.streamSandboxCreateMock.mock.calls[0]?.[1]).toContain(
"nemoclaw-alpha:live-descriptor",
);
expect(f.streamSandboxCreateMock).toHaveBeenCalledOnce();
const destinationDeleteCalls = f.runOpenshellMock.mock.calls.filter(
([args]) => args.join("\0") === "sandbox\0delete\0beta",
);
expect(destinationDeleteCalls).toHaveLength(1);
const deleteCallIndex = f.runOpenshellMock.mock.calls.indexOf(destinationDeleteCalls[0]);
const [firstReadOrder, secondReadOrder] =
f.getOpenShellSandboxDescriptorMock.mock.invocationCallOrder;
const deleteOrder = f.runOpenshellMock.mock.invocationCallOrder[deleteCallIndex];
const [createOrder] = f.streamSandboxCreateMock.mock.invocationCallOrder;
expect(firstReadOrder).toBeLessThan(secondReadOrder);
expect(secondReadOrder).toBeLessThan(deleteOrder);
expect(deleteOrder).toBeLessThan(createOrder);
expect(f.restoreSandboxStateMock).toHaveBeenCalledWith("beta", "/tmp/backup-alpha");
});

it("does not delete or create when a descriptor difference is observed between samples", async () => {
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
f.getSandboxMock.mockImplementation((name) => ({
name: name ?? "alpha",
agent: "openclaw",
provider: "nvidia-nim",
model: "nvidia/model-a",
}));
f.parseLiveSandboxNamesMock.mockReturnValue(new Set(["alpha", "beta"]));
f.getLatestBackupMock.mockReturnValue({ ...f.latestBackupFixture });
f.getOpenShellSandboxDescriptorMock
.mockResolvedValueOnce({ id: "alpha-id", name: "alpha", image: "alpha:v1" })
.mockResolvedValueOnce({ id: "alpha-id", name: "alpha", image: "alpha:v2" });
const { runSandboxSnapshot } = await import("./snapshot");

await expect(
runSandboxSnapshot("alpha", {
kind: "restore",
to: "beta",
force: true,
yes: true,
}),
).rejects.toMatchObject({ exitCode: 1 });

expect(consoleError.mock.calls.flat().join("\n")).toContain(
"Source sandbox image differed between pre-mutation descriptor samples",
);
expect(f.lifecycleMock.events).not.toContain("delete");
expect(f.streamSandboxCreateMock).not.toHaveBeenCalled();
expect(f.registerSandboxMock).not.toHaveBeenCalled();
});

it("blocks auto-create before deleting a destination when a gateway peer conflicts", async () => {
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
f.getSandboxMock.mockImplementation((name) => ({
Expand Down
Loading
Loading