Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ec39f9f
fix(sandbox): retain llama.cpp cleanup authority
harjothkhara Aug 22, 2026
ad15540
refactor(sandbox): remove unused lifecycle parameter
harjothkhara Aug 22, 2026
81c81ea
refactor(sandbox): tighten lifecycle helper signatures
harjothkhara Aug 22, 2026
a6e8b69
test(sandbox): cover delayed engine outage
harjothkhara Aug 22, 2026
e63451d
docs(inference): clarify Docker authority recovery
harjothkhara Aug 22, 2026
aa3a36a
fix(inference): harden legacy cleanup preflight
harjothkhara Aug 22, 2026
102eac6
fix(inference): pin legacy cleanup state
harjothkhara Aug 22, 2026
1527acc
test(inference): prove cleanup boundaries
harjothkhara Aug 22, 2026
92db661
fix(inference): reject mixed cleanup journals
harjothkhara Aug 22, 2026
7560fad
fix(inference): bind cleanup private state
harjothkhara Aug 22, 2026
f4aac92
fix(inference): retain cleanup execution lease
harjothkhara Aug 22, 2026
36c26ec
docs(inference): remove unsupported recovery claim
harjothkhara Aug 22, 2026
e96bbcd
fix(inference): settle cleanup on destroy errors
harjothkhara Aug 22, 2026
5daf425
merge: refresh PR branch from main
jyaunches Aug 23, 2026
3cf8b8a
fix(inference): retain cleanup lease through state removal
jyaunches Aug 23, 2026
f57957a
merge: refresh PR branch from main
prekshivyas Aug 23, 2026
0a8a07c
merge: refresh PR branch from main
prekshivyas Aug 23, 2026
6f79bd5
merge: refresh PR branch from main
prekshivyas Aug 23, 2026
330c31b
Merge branch 'main' into codex/nemoclaw-9888-2026-08-21
prekshivyas Aug 23, 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
44 changes: 44 additions & 0 deletions docs/inference/set-up-llama-cpp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,50 @@ Run:
$$nemoclaw my-assistant destroy
```

Although the setup steps above target DGX Spark, this removal and recovery behavior also applies to other experimental managed llama.cpp profiles on Linux.
Before sandbox deletion, NemoClaw qualifies the Docker operation authority recorded during managed llama.cpp onboarding.
This authority includes Docker endpoint selection and identity, Docker executable identity, and command environment.
If qualification fails, NemoClaw leaves the sandbox in place and reports the Docker operation authority error.

If the reported Docker operation authority mismatch involves endpoint selection, inspect the current Docker configuration and selectors:

```bash
docker context show
printf 'DOCKER_CONFIG=%s\n' "${DOCKER_CONFIG:-<unset>}"
printf 'DOCKER_CONTEXT=%s\n' "${DOCKER_CONTEXT:-<unset>}"
printf 'DOCKER_HOST=%s\n' "${DOCKER_HOST:-<unset>}"
```

Compare this output with the shell or automation that ran onboarding.
Restore the configuration and selection used during onboarding with the matching path:

- If onboarding used a custom `DOCKER_CONFIG` directory, restore it first:

```bash
export DOCKER_CONFIG="<onboarding-docker-config>"
```

If onboarding used Docker's default configuration directory, unset `DOCKER_CONFIG`.

- If onboarding used `DOCKER_CONTEXT` or Docker's persisted current context, select the original context explicitly:

```bash
unset DOCKER_HOST
export DOCKER_CONTEXT="<onboarding-context>"
```

- If onboarding used `DOCKER_HOST`, restore that selection:

```bash
unset DOCKER_CONTEXT
export DOCKER_HOST="<onboarding-docker-host>"
```

After restoring the recorded Docker configuration and selector, run `docker info`.
Confirm that it reports the Docker daemon used during onboarding.
Other Docker operation authority mismatches can involve Docker executable identity or command environment.
Restore the reported Docker executable or command environment to the value used during onboarding.
Rerun the earlier `destroy` command.
After OpenShell confirms sandbox deletion, the command removes the exact managed llama.cpp container, internal network, API key, and gateway-scoped ownership state.
It preserves `~/.cache/huggingface/` because other applications can use that cache.
If exact cleanup fails, NemoClaw preserves the sandbox registry entry and ownership state for a retry.
Expand Down
156 changes: 156 additions & 0 deletions src/lib/actions/sandbox/destroy-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
resetDestroyModuleCache,
traceDestroyBoundaryCalls,
} from "../../../../test/helpers/destroy-flow-test-harness";
import { serializedLlamaCppHostLocalInferenceReceipt } from "../../../../test/helpers/host-local-inference-receipt";
import { createSandboxHostLocalInferenceProvenance } from "../../state/registry/host-local-inference";
import type { SandboxWorkloadReceipt } from "../../state/registry";

const managedHermesWorkload = {
Expand Down Expand Up @@ -81,6 +83,160 @@ describe("destroySandbox flow", () => {
);
});

it.each([
["--yes", false],
["--yes --force", true],
] as const)(
"keeps managed llama.cpp cleanup authority across the sandbox delete boundary with %s (#9888)",
async (_flags, force) => {
const trace: string[] = [];
const cleanup = vi.fn(() => {
trace.push("cleanup");
return { ok: true as const, removed: [], preserved: [] };
});
const harness = createDestroyHarness({
provider: "llama-cpp-local",
hostLocalInferenceReceipt: serializedLlamaCppHostLocalInferenceReceipt(),
preparedManagedLlamaCppRuntimeCleanup: { cleanup },
onPrepareManagedLlamaCppRuntimeCleanup: () => trace.push("prepare"),
});
harness.runOpenshellSpy.mockImplementation((args: unknown) => {
const argv = Array.isArray(args) ? args : [];
switch (`${String(argv[0])}:${String(argv[1])}`) {
case "sandbox:delete":
trace.push("delete");
return { status: 0, stdout: "", stderr: "" };
case "sandbox:list":
return { status: 0, stdout: '[{"name":"alpha","phase":"Ready"}]', stderr: "" };
default:
return { status: 0, stdout: "", stderr: "" };
}
});

await expect(harness.destroySandbox("alpha", { yes: true, force })).resolves.toBeUndefined();

expect(harness.prepareManagedLlamaCppRuntimeCleanupSpy).toHaveBeenCalledWith("alpha", {
gatewayPort: 19080,
});
expect(cleanup).toHaveBeenCalledOnce();
expect(trace).toEqual(["prepare", "delete", "cleanup"]);
expect(harness.removeSandboxSpy).toHaveBeenCalledWith("alpha");
expect(harness.retirePortableLifecycleReceiptSpy).toHaveBeenCalledWith("alpha");
expect(exitSpy).not.toHaveBeenCalled();
},
);

it.each([
["--yes", false],
["--yes --force", true],
] as const)(
"refuses sandbox deletion when managed llama.cpp cleanup authority cannot be qualified with %s (#9888)",
async (_flags, force) => {
const harness = createDestroyHarness({
provider: "llama-cpp-local",
hostLocalInferenceReceipt: serializedLlamaCppHostLocalInferenceReceipt(),
onPrepareManagedLlamaCppRuntimeCleanup: () => {
throw new Error("qualified container endpoint does not match persisted authority");
},
});

await expect(harness.destroySandbox("alpha", { yes: true, force })).rejects.toThrow(
"process.exit(1)",
);

expect(
harness.runOpenshellSpy.mock.calls.map(([args]) => (args as string[]).slice(0, 2)),
).not.toContainEqual(["sandbox", "delete"]);
expect(harness.errorSpy.mock.calls.map(([message]) => String(message)).join("\n")).toContain(
"The sandbox was not deleted. Fix the reported authority and retry destroy.",
);
expect(harness.removeSandboxSpy).not.toHaveBeenCalled();
},
);

it("preserves the registry when prepared managed llama.cpp cleanup fails after deletion (#9888)", async () => {
const harness = createDestroyHarness({
provider: "llama-cpp-local",
hostLocalInferenceReceipt: serializedLlamaCppHostLocalInferenceReceipt(),
preparedManagedLlamaCppRuntimeCleanup: {
cleanup: () => ({
ok: false,
reason: "qualified cleanup failed",
removed: [],
preserved: ["managed llama.cpp runtime"],
}),
},
});

await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow("process.exit(1)");

expect(harness.removeSandboxSpy).not.toHaveBeenCalled();
expect(harness.errorSpy.mock.calls.map(([message]) => String(message)).join("\n")).toContain(
"qualified cleanup failed",
);
});

it("does not run prepared managed llama.cpp cleanup when OpenShell deletion fails (#9888)", async () => {
const cleanup = vi.fn(() => ({ ok: true as const, removed: [], preserved: [] }));
const harness = createDestroyHarness({
deleteStatus: 7,
provider: "llama-cpp-local",
hostLocalInferenceReceipt: serializedLlamaCppHostLocalInferenceReceipt(),
preparedManagedLlamaCppRuntimeCleanup: { cleanup },
});

await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow("process.exit(7)");

expect(cleanup).not.toHaveBeenCalled();
expect(harness.removeSandboxSpy).not.toHaveBeenCalled();
});

it("reconciles prepared managed llama.cpp cleanup after OpenShell already deleted the sandbox (#9888)", async () => {
const cleanup = vi.fn(() => ({ ok: true as const, removed: [], preserved: [] }));
const harness = createDestroyHarness({
sandboxPresent: false,
provider: "llama-cpp-local",
hostLocalInferenceReceipt: serializedLlamaCppHostLocalInferenceReceipt(),
preparedManagedLlamaCppRuntimeCleanup: { cleanup },
});

await expect(harness.destroySandbox("alpha", { yes: true })).resolves.toBeUndefined();

expect(cleanup).toHaveBeenCalledOnce();
expect(harness.removeSandboxSpy).toHaveBeenCalledWith("alpha");
expect(harness.retirePortableLifecycleReceiptSpy).toHaveBeenCalledWith("alpha");
expect(exitSpy).not.toHaveBeenCalled();
});

it("completes destroy through common cleanup for provenance-tracked llama.cpp (#9888)", async () => {
const receipt = serializedLlamaCppHostLocalInferenceReceipt();
const harness = createDestroyHarness({
provider: "llama-cpp-local",
hostLocalInferenceReceipt: receipt,
hostLocalInferenceProvenance: createSandboxHostLocalInferenceProvenance("alpha", receipt),
executeSandboxDestroyResult: {
ok: true,
alreadyGone: false,
deleteOutput: "",
deleteResult: { status: 0, stdout: "", stderr: "" },
detachOutcome: { detached: [], failures: [] },
forcedLocalCleanup: false,
commonLlamaCppAuthorityRetired: true,
},
});

await expect(harness.destroySandbox("alpha", { yes: true })).resolves.toBeUndefined();

expect(harness.prepareManagedLlamaCppRuntimeCleanupSpy).not.toHaveBeenCalled();
expect(harness.executeSandboxDestroySpy).toHaveBeenCalledWith(
expect.objectContaining({
sandbox: expect.objectContaining({ hostLocalInferenceProvenance: expect.any(Object) }),
}),
);
expect(harness.removeSandboxSpy).toHaveBeenCalledWith("alpha");
expect(exitSpy).not.toHaveBeenCalled();
});

it("rejects schema-5 inside the destroy lifecycle fence before Docker or OpenShell (#9203)", async () => {
const harness = createDestroyHarness({ portableCommandError: "schema-5 rejected" });

Expand Down
32 changes: 28 additions & 4 deletions src/lib/actions/sandbox/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
parseHttpsPinRouteId,
revokeHttpsPinRuntimeAdapterRoute,
} from "../../inference/https-pin-runtime-adapter";
import { cleanupManagedLlamaCppRuntimeForSandbox } from "../../inference/local-model-profile/cleanup";
import {
cleanupManagedLlamaCppRuntimeForSandbox,
prepareManagedLlamaCppRuntimeCleanupForSandbox,
} from "../../inference/local-model-profile/cleanup";
import {
CURRENT_RUNTIME_PROVIDER_BUNDLES,
normalizeRuntimeProviderIdentity,
Expand Down Expand Up @@ -496,6 +499,25 @@ async function destroySandboxUnlocked(

const { cleanupGatewayName, runOpenshell, sandbox, sandboxConfirmedAbsent } =
prepareSandboxDestroy(sandboxName);
let preparedManagedLlamaCppCleanup: ReturnType<
typeof prepareManagedLlamaCppRuntimeCleanupForSandbox
> = null;
if (!sandbox?.hostLocalInferenceProvenance) {
try {
// Fresh Docker qualification reads ambient DOCKER_CONTEXT, DOCKER_HOST,
// or Docker's persisted currentContext. Pin that selection before the
// OpenShell delete boundary so legacy cleanup cannot switch daemons.
preparedManagedLlamaCppCleanup = prepareManagedLlamaCppRuntimeCleanupForSandbox(sandboxName, {
...(typeof sandbox?.gatewayPort === "number" ? { gatewayPort: sandbox.gatewayPort } : {}),
});
} catch (error) {
console.error(
` Refusing to destroy sandbox '${sandboxName}': Managed llama.cpp cleanup preflight failed: ${redactDestroyError(error)}`,
);
console.error(` The sandbox was not deleted. Fix the reported authority and retry destroy.`);
process.exit(1);
}
}
// Recheck identity after read-only preflight and before local mutation.
const preMutationIdentity = inspectContainerIdentity();
if (
Expand Down Expand Up @@ -651,9 +673,11 @@ async function destroySandboxUnlocked(
stopHostServices: shouldStopHostServices,
});
if (deleteSucceededOrAlreadyGone && commonLlamaCppAuthorityRetired !== true) {
const managedLlamaCppCleanup = cleanupManagedLlamaCppRuntimeForSandbox(sandboxName, {
...(typeof sandbox?.gatewayPort === "number" ? { gatewayPort: sandbox.gatewayPort } : {}),
});
const managedLlamaCppCleanup =
preparedManagedLlamaCppCleanup?.cleanup() ??
cleanupManagedLlamaCppRuntimeForSandbox(sandboxName, {
...(typeof sandbox?.gatewayPort === "number" ? { gatewayPort: sandbox.gatewayPort } : {}),
});
if (!managedLlamaCppCleanup.ok) {
console.error(
` Managed llama.cpp cleanup failed for '${sandboxName}': ${managedLlamaCppCleanup.reason}`,
Expand Down
Loading
Loading