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
22 changes: 20 additions & 2 deletions docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ Use the result from `destroy` to choose the next action:

- If OpenShell reports the sandbox present and its durable identity matches the recovery record, `destroy` checks that identity during cleanup and immediately before deletion. It can delete the retained sandbox. A failed check or deletion preserves the recovery record. If you cannot prevent another gateway client from replacing the sandbox name during cleanup, use a different explicit name instead.
- If OpenShell cannot determine whether the sandbox is present, `destroy` reports unknown presence, removes no resources, and preserves the recovery record. Correct the OpenShell gateway or list failure, then rerun `destroy`.
- If OpenShell confirms the sandbox is absent, `destroy` selects one retained record from its registry generation, gateway, create-attempt evidence, and available identity fingerprint.
- For the existing residual-cleanup path, `destroy` selects one retained record from its registry generation, gateway, create-attempt evidence, and available identity fingerprint.
Cleanup requires the owning OpenShell gateway to confirm sandbox absence.
Before pending identity publication, it can instead select one record with a durable identity fingerprint when the pending reservation belongs to the recorded onboarding session, the saved session recovery evidence matches the record, and the registry has no lifecycle identity evidence.
Provider and Docker cleanup then apply their own immutable identity checks.
`destroy` removes only qualified residual resources and clears the matching recovery record only after verified cleanup.
Expand All @@ -562,7 +563,24 @@ Only then rerun the owning provider setup workflow to restore those attachments.
If you cannot prevent replacement or verify attachment ownership, leave the attachments untouched and use a different sandbox name.
Keep the recovery record and retry `destroy` only after resolving the identity drift.

If OpenShell did not return a durable identity fingerprint, `destroy` cannot authorize deletion of a live sandbox. It can still select one recovery record that matches the immutable registry generation, gateway, and create-attempt evidence. It clears that record only after the owning gateway reports absence and verified residual cleanup succeeds. If the sandbox is present or presence is unknown, preserve the record and do not delete by mutable name. If NemoClaw could not save recovery evidence, preserve the registry entry and terminal output.
If OpenShell did not return a durable identity fingerprint, `destroy` cannot authorize deletion of a live sandbox.

For an unpublished reservation without lifecycle identity, `destroy` can clear local recovery metadata on native Linux with the default Docker daemon.
It requires exactly one matching retained record, a recorded Docker ownership marker, and sandbox absence confirmed by the owning gateway.
Docker must report no matching containers or managed state volumes.
Any reservation must match its recovery-only onboarding session; conflicting state, recorded sandbox-scoped providers, or additional resource ownership block recovery.

Use the failed onboarding attempt's gateway port to select its state root, for example:

```bash
NEMOCLAW_GATEWAY_PORT=19260 $$nemoclaw <sandbox-name> destroy --yes
```

Success clears the matching recovery metadata and releases the sandbox name without removing runtime resources.
If a local metadata write fails, resolve the reported write error.
Then rerun the same command with that port, even if the reservation was removed.

If NemoClaw could not save recovery evidence, preserve the registry entry and terminal output.

This fail-closed record keeps only the affected sandbox name unavailable. This command does not accept externally supplied identity authority.
To onboard another sandbox while the record remains unresolved, supply a different explicit name:
Expand Down
17 changes: 17 additions & 0 deletions src/lib/actions/sandbox/destroy-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ export function redactDestroyError(error: unknown): string {
return redactFull(error instanceof Error ? error.message : String(error));
}

export function stopSandboxInferenceResources(
sandboxName: string,
sandbox: SandboxEntry | null,
): void {
const nim = require("../../inference/nim") as {
stopNimContainer: (name: string, opts?: { silent?: boolean }) => void;
stopNimContainerByName: (name: string) => void;
};
if (sandbox?.nimContainer) {
console.log(` Stopping NIM for '${sandboxName}'...`);
nim.stopNimContainerByName(sandbox.nimContainer);
} else {
// Older registry entries may not record the convention-named container.
nim.stopNimContainer(sandboxName, { silent: true });
}
}

const SANDBOX_NATIVE_ROOT = "/sandbox";
const COMPLETE_NATIVE_HOME_AGENTS = new Set(["hermes", "langchain-deepagents-code", "openclaw"]);

Expand Down
6 changes: 6 additions & 0 deletions src/lib/actions/sandbox/destroy-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ interface ResolveGatewayCleanupRuntimeProviderDeps extends Pick<
"resolveOwnedRuntimeProviderId"
> {
configuredRuntimeProviderId?: string | null;
requireOwnedRuntime?: boolean;
recoveryRecordedAt?: string;
}

// Compute the Docker-driver gateway state directory that belongs to
Expand Down Expand Up @@ -96,8 +98,12 @@ export function resolveGatewayCleanupRuntimeProviderId(
gatewayName,
gatewayPort: perGatewayState.port,
stateDir: perGatewayState.stateDir,
...(deps.recoveryRecordedAt !== undefined
? { recoveryRecordedAt: deps.recoveryRecordedAt }
: {}),
},
);
if (deps.requireOwnedRuntime && !recorded) return null;
if (registered && recorded && registered !== recorded) {
throw new Error(
`Refusing cleanup for gateway '${gatewayName}': registered runtime provider '${registered}' does not match recorded gateway runtime provider '${recorded}'.`,
Expand Down
51 changes: 34 additions & 17 deletions src/lib/actions/sandbox/destroy-preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ import {
} from "./gateway-target";

export { teardownSandboxDashboardForward } from "./forward-recovery";
import { reconcileIdentityFreeRecovery as reconcileRetainedMetadata } from "./lifecycle/retained-recovery";

/** Probe only the recorded gateway before reconciling identity-free local metadata. */
export function reconcileIdentityFreeRecovery(
sandboxName: string,
records: Parameters<typeof reconcileRetainedMetadata>[1],
owningGatewayPort: number,
state: Omit<
Parameters<typeof reconcileRetainedMetadata>[3],
"observeSandbox" | "timeoutMs" | "registryEntryGatewayPort"
> & {
captureOpenshell?: typeof import("../../adapters/openshell/runtime").captureOpenshell;
},
): boolean {
const captureOpenshell =
state.captureOpenshell ??
(
require("../../adapters/openshell/runtime") as typeof import("../../adapters/openshell/runtime")
).captureOpenshell;
return reconcileRetainedMetadata(sandboxName, records, owningGatewayPort, {
...state,
registryEntryGatewayPort,
timeoutMs: OPENSHELL_PROBE_TIMEOUT_MS,
observeSandbox: (gatewayName) =>
classifyDestroySandboxPresence(
sandboxName,
captureOpenshell(["sandbox", "list", "-g", gatewayName, "--output", "json"], {
ignoreError: true,
includeStreams: true,
timeout: OPENSHELL_PROBE_TIMEOUT_MS,
}),
),
});
}

export type SandboxDestroyPreflight = {
cleanupGatewayName: string;
Expand Down Expand Up @@ -128,23 +162,6 @@ export function resolveSandboxDestroyRuntimeSelection(
return undefined;
}

export function stopSandboxInferenceResources(
sandboxName: string,
sandbox: SandboxEntry | null,
): void {
const nim = require("../../inference/nim") as {
stopNimContainer: (name: string, opts?: { silent?: boolean }) => void;
stopNimContainerByName: (name: string) => void;
};
if (sandbox?.nimContainer) {
console.log(` Stopping NIM for '${sandboxName}'...`);
nim.stopNimContainerByName(sandbox.nimContainer);
} else {
// Older registry entries may not record the convention-named container.
nim.stopNimContainer(sandboxName, { silent: true });
}
}

function sandboxGatewayPort(entry: SandboxEntry): number {
return registryEntryGatewayPort({
name: entry.name,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/actions/sandbox/destroy-presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export type DestroyContainerIdentityProof = {
/** Read the host observation consumed by the pure identity classifier. */
export function observeDestroyContainerIdentity(
sandboxName: string,
inspect?: Parameters<typeof inspectDockerSandboxNameLabeledContainers>[1],
): DockerSandboxIdentityObservation {
return inspectDockerSandboxNameLabeledContainers(sandboxName);
return inspectDockerSandboxNameLabeledContainers(sandboxName, inspect);
}

/**
Expand Down
20 changes: 1 addition & 19 deletions src/lib/actions/sandbox/destroy-retained-recovery-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,13 @@ function cancellationRecoveryFor(

function prepublicationRecoveryHarness(
options: {
identityFree?: boolean;
partialLifecycleGeneration?: boolean;
reservationSessionId?: string;
sandboxPresent?: boolean;
sessionRecoveryOverrides?: Partial<SessionCancellationRecovery>;
} = {},
) {
const recovery = options.identityFree
? retainedRecoveryRecordWithoutIdentity()
: retainedRecoveryRecord();
const recovery = retainedRecoveryRecord();
const harness = createDestroyHarness({
sandboxPresent: options.sandboxPresent ?? false,
dockerRunResult: { status: 0, stdout: "" },
Expand Down Expand Up @@ -267,21 +264,6 @@ describe("destroySandbox retained recovery flow", () => {
},
);

it(
"refuses identity-free recovery before pending identity publication (#11418)",
{ timeout: 30_000 },
async () => {
const { harness } = prepublicationRecoveryHarness({ identityFree: true });

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

expect(harness.resolveRetainedSandboxRecoverySpy).not.toHaveBeenCalled();
expect(harness.removeSandboxSpy).not.toHaveBeenCalled();
},
);

it(
"removes every container after OpenShell confirms the retained sandbox absent (#10547)",
{ timeout: 30_000 },
Expand Down
31 changes: 30 additions & 1 deletion src/lib/actions/sandbox/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
preparePortableDemoSandboxDestroyAuthority,
redactDestroyError,
retirePortableLifecycleAuthority,
stopSandboxInferenceResources,
} from "./destroy-execution";
import {
cleanupGatewayAfterLastSandbox,
Expand All @@ -83,6 +84,7 @@ import {
import { withSandboxLifecycleLock } from "./lifecycle/lock";
import {
prepareSandboxDestroy,
reconcileIdentityFreeRecovery,
recordManagedVllmRetirementPending,
reportManagedVllmDestroyOutcome,
resolveSandboxDestroyRegistryAuthority,
Expand All @@ -92,7 +94,6 @@ import {
listInferenceRouteOwnersAcrossGatewayRoots,
stopModelRouterForDestroyedSandbox,
stopDestroyedSandboxProxy,
stopSandboxInferenceResources,
teardownSandboxDashboardForward,
} from "./destroy-preflight";

Expand Down Expand Up @@ -753,6 +754,34 @@ async function destroySandboxUnlocked(
}
const destroySession = onboardSession.loadSession();
const retainedRecoveryRecords = onboardSession.listRetainedSandboxRecoveryRecords();
try {
if (
reconcileIdentityFreeRecovery(
sandboxName,
retainedRecoveryRecords,
registryAuthority.gatewayPort,
{
session: onboardSession,
registry,
...(retireRemovedImmutabilityState
? {
retireRemovedImmutabilityState: () => {
retireRemovedImmutabilityStateRecord(sandboxName, "sandbox-destroyed");
},
}
: {}),
},
)
) {
console.log(
` Cleared retained recovery for '${sandboxName}'. No sandbox resources were removed.`,
);
return;
}
} catch (error) {
console.error(` ${redactDestroyError(error)}`);
requestSandboxDestroyExit(1);
}
const retainedRecoveryAuthority = selectRetainedSandboxRecoveryAuthority(
sandboxName,
registeredSandbox,
Expand Down
Loading