Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -1249,9 +1249,9 @@ If you do not need GPU access inside the sandbox, rerun with `--no-sandbox-gpu`.
Set `NEMOCLAW_DOCKER_GPU_PATCH=0` only when you need to bypass this compatibility path during troubleshooting.

If onboarding reports `OpenShell supervisor did not reconnect to the GPU-enabled container.` even though the diagnostic bundle shows the patched container is running and healthy, the supervisor-reconnect wait is treating a transient Error phase (reported while the OpenShell host re-registers the new container) as fatal.
The reconnect wait debounces consecutive Error-phase polls before fast-failing, defaulting to five consecutive polls of about 10 seconds in total.
The reconnect wait debounces consecutive Error-phase polls before fast-failing, defaulting to fifteen consecutive polls of about 30 seconds in total.
Increase the debounce window with `NEMOCLAW_DOCKER_GPU_SUPERVISOR_RECONNECT_ERROR_DEBOUNCE` if your host needs more time to re-register the patched container, for example slow WSL2 + Docker Desktop setups.
Set it to a higher integer such as `15` (about 30 seconds) and rerun onboarding; the value is clamped to a minimum of `1`.
Set it to a higher integer such as `30` (about 60 seconds) and rerun onboarding; the value is clamped to a minimum of `1`.

### `pip install` fails with a system-packages error

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,9 @@ If you do not need GPU access inside the sandbox, rerun with `--no-sandbox-gpu`.
Set `NEMOCLAW_DOCKER_GPU_PATCH=0` only when you need to bypass this compatibility path during troubleshooting.

If onboarding reports `OpenShell supervisor did not reconnect to the GPU-enabled container.` even though the diagnostic bundle shows the patched container is running and healthy, the supervisor-reconnect wait is treating a transient Error phase (reported while the OpenShell host re-registers the new container) as fatal.
The reconnect wait debounces consecutive Error-phase polls before fast-failing, defaulting to five consecutive polls of about 10 seconds in total.
The reconnect wait debounces consecutive Error-phase polls before fast-failing, defaulting to fifteen consecutive polls of about 30 seconds in total.
Increase the debounce window with `NEMOCLAW_DOCKER_GPU_SUPERVISOR_RECONNECT_ERROR_DEBOUNCE` if your host needs more time to re-register the patched container, for example slow WSL2 + Docker Desktop setups.
Set it to a higher integer such as `15` (about 30 seconds) and rerun onboarding; the value is clamped to a minimum of `1`.
Set it to a higher integer such as `30` (about 60 seconds) and rerun onboarding; the value is clamped to a minimum of `1`.

### `pip install` fails with a system-packages error

Expand Down
15 changes: 15 additions & 0 deletions scripts/nemoclaw-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,21 @@ try:
if cleaned == lines:
sys.exit(0)

# When the rc file is not owned by us (and we are not root) we cannot
# safely rewrite it: fchmod would raise EPERM without CAP_FOWNER, and
# the in-place reopen via /proc/self/fd would fail anyway. The legacy
# shim line we would have removed is functionally inert (it sources
# /tmp/nemoclaw-proxy-env.sh only if that file exists), so leaving it
# in place is safer than crashing the container under errexit. A later
# root-mode boot can finish the cleanup.
if uid != 0 and st.st_uid != uid:
print(
f"[SECURITY] skipping rc cleanup for {rc_path}: not owned by uid={uid} "
f"(file uid={st.st_uid}); legacy shim left in place",
file=sys.stderr,
)
sys.exit(0)

try:
rewrite_open_rc_file(fd, st, cleaned)
except OSError as exc:
Expand Down
4 changes: 2 additions & 2 deletions skills/nemoclaw-user-reference/references/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,9 @@ If you do not need GPU access inside the sandbox, rerun with `--no-sandbox-gpu`.
Set `NEMOCLAW_DOCKER_GPU_PATCH=0` only when you need to bypass this compatibility path during troubleshooting.

If onboarding reports `OpenShell supervisor did not reconnect to the GPU-enabled container.` even though the diagnostic bundle shows the patched container is running and healthy, the supervisor-reconnect wait is treating a transient Error phase (reported while the OpenShell host re-registers the new container) as fatal.
The reconnect wait debounces consecutive Error-phase polls before fast-failing, defaulting to five consecutive polls of about 10 seconds in total.
The reconnect wait debounces consecutive Error-phase polls before fast-failing, defaulting to fifteen consecutive polls of about 30 seconds in total.
Increase the debounce window with `NEMOCLAW_DOCKER_GPU_SUPERVISOR_RECONNECT_ERROR_DEBOUNCE` if your host needs more time to re-register the patched container, for example slow WSL2 + Docker Desktop setups.
Set it to a higher integer such as `15` (about 30 seconds) and rerun onboarding; the value is clamped to a minimum of `1`.
Set it to a higher integer such as `30` (about 60 seconds) and rerun onboarding; the value is clamped to a minimum of `1`.

### `pip install` fails with a system-packages error

Expand Down
4 changes: 4 additions & 0 deletions src/lib/adapters/docker/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function dockerStop(containerName: string, opts: DockerRunOptions = {}):
return dockerRun(["stop", containerName], opts);
}

export function dockerStart(containerName: string, opts: DockerRunOptions = {}): DockerRunResult {
return dockerRun(["start", containerName], opts);
}

// NIM (and most Python services) write errors to stderr, so a stdout-only
// capture would silently lose the auth-error tail. Use dockerRun so we can
// read both streams from the SpawnResult and concatenate them. Bounded by a
Expand Down
250 changes: 248 additions & 2 deletions src/lib/onboard/docker-gpu-patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import {
classifyDockerGpuPatchFailure,
collectDockerGpuPatchDiagnostics,
type DockerContainerInspect,
type DockerGpuPatchResult,
detectSandboxFallbackDns,
dockerReportsNvidiaCdiDevices,
finalizeDockerGpuPatchBackup,
formatDockerInspectNetworkSummary,
getDockerGpuPatchNetworkMode,
getDockerGpuSupervisorReconnectTimeoutSecs,
Expand Down Expand Up @@ -579,11 +581,154 @@ describe("docker-gpu-patch", () => {
String(call[0]).includes("nemoclaw-gpu-backup"),
);
expect(backupRmCall).toBeGreaterThanOrEqual(0);
expect(dockerRm.mock.invocationCallOrder[backupRmCall]).toBeLessThan(
// Backup container is removed only AFTER supervisor reconnect confirms
// the GPU container is reachable. If reconnect fails the rollback path
// restores the backup under the original name (see the rollback test
// below), so the backup must outlive the supervisor probe.
expect(dockerRm.mock.invocationCallOrder[backupRmCall]).toBeGreaterThan(
runOpenshell.mock.invocationCallOrder[0],
);
});

it("rolls back to the backup container when supervisor reconnect fails", () => {
const dockerCapture = vi.fn((args: readonly string[]) => {
if (args[0] === "ps") return "old-container-id\n";
if (args[0] === "inspect") return JSON.stringify([inspectFixture()]);
if (args[0] === "info") return "";
return "";
});
const dockerRun = vi.fn(() => ({ status: 0, stdout: "probe-id\n" }));
const dockerRunDetached = vi.fn(() => ({ status: 0, stdout: "new-container-id\n" }));
const dockerRename = vi.fn((_old: string, _next: string) => ({ status: 0 }));
const dockerStop = vi.fn(() => ({ status: 0 }));
const dockerStart = vi.fn(() => ({ status: 0 }));
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const runOpenshell = vi.fn(() => ({ status: 1, stderr: "supervisor unreachable" }));
const runCaptureOpenshell = vi.fn(() => "");

expect(() =>
recreateOpenShellDockerSandboxWithGpu(
{ sandboxName: "alpha", timeoutSecs: 1 },
{
dockerCapture,
dockerRun,
dockerRunDetached,
dockerRename,
dockerStop,
dockerStart,
dockerRm,
runOpenshell,
runCaptureOpenshell,
sleep: vi.fn(),
now: () => new Date("2026-05-12T00:00:00Z"),
errorPhaseDebouncePolls: 1,
},
),
).toThrow(/pre-patch sandbox restored/);

const restoreRename = dockerRename.mock.calls.find(
(call) =>
String(call[0]).includes("nemoclaw-gpu-backup") && call[1] === "openshell-alpha",
);
expect(restoreRename).toBeDefined();
expect(dockerStart).toHaveBeenCalledWith(
"openshell-alpha",
expect.objectContaining({ ignoreError: true }),
);
expect(
dockerRm.mock.calls.some((call) => String(call[0]).includes("nemoclaw-gpu-backup")),
).toBe(false);
});

it("reports rollback failure when restoring the backup container fails", () => {
const dockerCapture = vi.fn((args: readonly string[]) => {
if (args[0] === "ps") return "old-container-id\n";
if (args[0] === "inspect") return JSON.stringify([inspectFixture()]);
if (args[0] === "info") return "";
return "";
});
const dockerRun = vi.fn(() => ({ status: 0, stdout: "probe-id\n" }));
const dockerRunDetached = vi.fn(() => ({ status: 0, stdout: "new-container-id\n" }));
const dockerRename = vi.fn((oldName: string) => {
if (String(oldName).includes("nemoclaw-gpu-backup")) {
return { status: 1, stderr: "no such container" };
}
return { status: 0 };
});
const dockerStop = vi.fn(() => ({ status: 0 }));
const dockerStart = vi.fn(() => ({ status: 0 }));
const dockerRm = vi.fn(() => ({ status: 0 }));
const runOpenshell = vi.fn(() => ({ status: 1, stderr: "supervisor unreachable" }));
const runCaptureOpenshell = vi.fn(() => "");

expect(() =>
recreateOpenShellDockerSandboxWithGpu(
{ sandboxName: "alpha", timeoutSecs: 1 },
{
dockerCapture,
dockerRun,
dockerRunDetached,
dockerRename,
dockerStop,
dockerStart,
dockerRm,
runOpenshell,
runCaptureOpenshell,
sleep: vi.fn(),
now: () => new Date("2026-05-12T00:00:00Z"),
errorPhaseDebouncePolls: 1,
},
),
).toThrow(/rollback to backup container failed/);

expect(dockerStart).not.toHaveBeenCalled();
});

it("reports rollback failure when restarting the backup container fails", () => {
const dockerCapture = vi.fn((args: readonly string[]) => {
if (args[0] === "ps") return "old-container-id\n";
if (args[0] === "inspect") return JSON.stringify([inspectFixture()]);
if (args[0] === "info") return "";
return "";
});
const dockerRun = vi.fn(() => ({ status: 0, stdout: "probe-id\n" }));
const dockerRunDetached = vi.fn(() => ({ status: 0, stdout: "new-container-id\n" }));
const dockerRename = vi.fn((_old: string, _next: string) => ({ status: 0 }));
const dockerStop = vi.fn(() => ({ status: 0 }));
const dockerStart = vi.fn(() => ({ status: 1, stderr: "container start failed" }));
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const runOpenshell = vi.fn(() => ({ status: 1, stderr: "supervisor unreachable" }));
const runCaptureOpenshell = vi.fn(() => "");

expect(() =>
recreateOpenShellDockerSandboxWithGpu(
{ sandboxName: "alpha", timeoutSecs: 1 },
{
dockerCapture,
dockerRun,
dockerRunDetached,
dockerRename,
dockerStop,
dockerStart,
dockerRm,
runOpenshell,
runCaptureOpenshell,
sleep: vi.fn(),
now: () => new Date("2026-05-12T00:00:00Z"),
errorPhaseDebouncePolls: 1,
},
),
).toThrow(/rollback to backup container failed/);

expect(dockerStart).toHaveBeenCalledWith(
"openshell-alpha",
expect.objectContaining({ ignoreError: true }),
);
expect(
dockerRm.mock.calls.some((call) => String(call[0]).includes("nemoclaw-gpu-backup")),
).toBe(false);
});

it("can recreate during sandbox create before supervisor exec is allowed", () => {
const dockerCapture = vi.fn((args: readonly string[]) => {
if (args[0] === "ps") return "old-container-id\n";
Expand All @@ -592,6 +737,7 @@ describe("docker-gpu-patch", () => {
return "";
});
const dockerRunDetached = vi.fn(() => ({ status: 0, stdout: "new-container-id\n" }));
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const runOpenshell = vi.fn(() => ({ status: 1, stderr: "phase: Provisioning" }));

const result = recreateOpenShellDockerSandboxWithGpu(
Expand All @@ -607,15 +753,24 @@ describe("docker-gpu-patch", () => {
dockerRunDetached,
dockerRename: vi.fn(() => ({ status: 0 })),
dockerStop: vi.fn(() => ({ status: 0 })),
dockerRm: vi.fn(() => ({ status: 0 })),
dockerRm,
runOpenshell,
sleep: vi.fn(),
now: () => new Date("2026-05-12T00:00:00Z"),
},
);

expect(result.newContainerId).toBe("new-container-id");
expect(result.backupRemoved).toBe(false);
expect(result.originalName).toBe("openshell-alpha");
expect(result.backupContainerName).toContain("nemoclaw-gpu-backup");
expect(runOpenshell).not.toHaveBeenCalled();
// The create path takes the supervisor wait into its own hands later in
// the flow. The patch helper must NOT remove the backup yet — that would
// re-introduce the deleted-backup / failed-new state #4664 fixes.
expect(
dockerRm.mock.calls.some((call) => String(call[0]).includes("nemoclaw-gpu-backup")),
).toBe(false);
expect(dockerRunDetached).toHaveBeenCalledWith(
expect.arrayContaining([
"--env",
Expand All @@ -630,6 +785,97 @@ describe("docker-gpu-patch", () => {
});
});

describe("finalizeDockerGpuPatchBackup", () => {
function deferredCreateResult(): DockerGpuPatchResult {
return {
applied: true,
oldContainerId: "old-container-id",
newContainerId: "new-container-id",
originalName: "openshell-alpha",
backupContainerName:
"openshell-alpha-nemoclaw-gpu-backup-1780491860342",
mode: {
kind: "gpus",
label: "--gpus all",
device: "all",
args: ["--gpus", "all"],
},
backupRemoved: false,
};
}

it("removes the backup container when supervisor reconnect succeeded", () => {
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const outcome = finalizeDockerGpuPatchBackup(
{ result: deferredCreateResult(), supervisorReady: true },
{ dockerRm },
);
expect(outcome).toEqual({ backupRemoved: true, rolledBack: false });
expect(dockerRm).toHaveBeenCalledWith(
"openshell-alpha-nemoclaw-gpu-backup-1780491860342",
expect.objectContaining({ ignoreError: true }),
);
});

it("rolls back to the backup container when supervisor reconnect failed", () => {
const dockerStop = vi.fn(() => ({ status: 0 }));
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const dockerRename = vi.fn((_old: string, _next: string) => ({ status: 0 }));
const dockerStart = vi.fn(() => ({ status: 0 }));
const outcome = finalizeDockerGpuPatchBackup(
{ result: deferredCreateResult(), supervisorReady: false },
{ dockerStop, dockerRm, dockerRename, dockerStart },
);
expect(outcome).toEqual({ backupRemoved: false, rolledBack: true });
expect(dockerStop).toHaveBeenCalledWith(
"new-container-id",
expect.objectContaining({ ignoreError: true }),
);
expect(dockerRename).toHaveBeenCalledWith(
"openshell-alpha-nemoclaw-gpu-backup-1780491860342",
"openshell-alpha",
expect.objectContaining({ ignoreError: true }),
);
expect(dockerStart).toHaveBeenCalledWith(
"openshell-alpha",
expect.objectContaining({ ignoreError: true }),
);
// The backup itself must NOT be removed when we're restoring it.
expect(
dockerRm.mock.calls.some((call) =>
String(call[0]).includes("nemoclaw-gpu-backup"),
),
).toBe(false);
});

it("reports rolledBack=false when restoring the backup fails", () => {
const dockerStop = vi.fn(() => ({ status: 0 }));
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const dockerRename = vi.fn((_old: string, _next: string) => ({
status: 1,
stderr: "no such container",
}));
const dockerStart = vi.fn(() => ({ status: 0 }));
const outcome = finalizeDockerGpuPatchBackup(
{ result: deferredCreateResult(), supervisorReady: false },
{ dockerStop, dockerRm, dockerRename, dockerStart },
);
expect(outcome).toEqual({ backupRemoved: false, rolledBack: false });
expect(dockerStart).not.toHaveBeenCalled();
});

it("is a no-op when the backup was already removed by the patch helper", () => {
const dockerRm = vi.fn((_name: string) => ({ status: 0 }));
const result = { ...deferredCreateResult(), backupRemoved: true };
const outcome = finalizeDockerGpuPatchBackup(
{ result, supervisorReady: true },
{ dockerRm },
);
expect(outcome).toEqual({ backupRemoved: true, rolledBack: false });
expect(dockerRm).not.toHaveBeenCalled();
});
});

describe("docker-gpu-patch sandbox DNS fallback (#3579)", () => {
it("returns the systemd-resolved upstream when /etc/resolv.conf is loopback-only", () => {
const readFile = (p: string): string | null => {
Expand Down
Loading
Loading