Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b5fddb1
fix(onboard): recover retained sandbox cleanup (#10547)
prekshivyas Aug 28, 2026
d88e130
fix(onboard): harden retained cleanup reconciliation (#10547)
prekshivyas Aug 28, 2026
fc287e0
refactor(destroy): unify container identity proof (#10547)
prekshivyas Aug 28, 2026
820374f
fix(destroy): resolve retained identity conflicts (#10547)
prekshivyas Aug 28, 2026
248750c
fix(onboard): consolidate retained cleanup evidence
prekshivyas Aug 28, 2026
4b0f636
docs(onboard): clarify retained identity recovery
prekshivyas Aug 28, 2026
90c1826
fix(destroy): revalidate retained sandbox identity (#10547)
prekshivyas Aug 28, 2026
2c75b80
fix(destroy): refuse mutable retained deletion (#10547)
prekshivyas Aug 28, 2026
66c1b11
merge: sync upstream main
prekshivyas Aug 29, 2026
fd51e39
fix(onboard): surface retained recovery identity
prekshivyas Aug 28, 2026
812bd03
test(destroy): model verified container removal
prekshivyas Aug 29, 2026
2a9f7e6
fix(destroy): fail closed on recovery conflict
prekshivyas Aug 29, 2026
12bd585
fix(destroy): preserve retained recovery retry
prekshivyas Aug 29, 2026
19ab121
test(e2e): reconcile retained onboarding cleanup
prekshivyas Aug 29, 2026
af6b521
test(e2e): prove retained cleanup ordering
prekshivyas Aug 29, 2026
92c9100
docs(recovery): cover unavailable identity evidence
prekshivyas Aug 29, 2026
f84bd79
fix(state): migrate retained recovery authority
prekshivyas Aug 29, 2026
4e9f5d0
fix(state): partition retained recovery migration
prekshivyas Aug 29, 2026
ed383e5
fix(state): reject incomplete recovery intents
prekshivyas Aug 29, 2026
12ea021
test(e2e): initialize gateway before MCP cleanup
prekshivyas Aug 29, 2026
47709ad
test(e2e): bind MCP cleanup to gateway
prekshivyas Aug 29, 2026
9b5b1bb
docs(recovery): qualify Docker identity guidance
prekshivyas Aug 29, 2026
9164a3c
docs(recovery): clarify fail-closed decisions
prekshivyas Aug 29, 2026
1ca2d4d
fix(state): serialize retained recovery migration
senthilr-nv Aug 29, 2026
c9c4b5e
fix(destroy): bind retained recovery gateway
senthilr-nv Aug 29, 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
30 changes: 30 additions & 0 deletions src/lib/actions/sandbox/destroy-container-identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { describe, expect, it, vi } from "vitest";

import { fingerprintOpenShellSandboxId } from "../../adapters/openshell/sandbox-identity";
import {
classifyDestroyContainerIdentity,
type DestroyContainerIdentityVerdict,
Expand Down Expand Up @@ -126,6 +127,35 @@ describe("classifyDestroyContainerIdentity", () => {
expect(verdict.reason).toContain("2 managed containers");
});

it("accepts every managed container bound to one retained sandbox identity (#10547)", () => {
const sandboxIdentityFingerprint = fingerprintOpenShellSandboxId(MANAGED.sandboxId)!;
const identities = [MANAGED, { ...MANAGED, id: "dddd000000000000" }];

expect(
classifyDestroyContainerIdentity(
"destroytest",
observeRows(identities),
sandboxIdentityFingerprint,
),
).toEqual({ status: "recovery", identities });
});

it("refuses a retained recovery set that contains another sandbox identity (#10547)", () => {
const sandboxIdentityFingerprint = fingerprintOpenShellSandboxId(MANAGED.sandboxId)!;
const verdict = expectAmbiguous(
classifyDestroyContainerIdentity(
"destroytest",
observeRows([
MANAGED,
{ ...MANAGED, id: "dddd000000000000", sandboxId: "sb-replacement" },
]),
sandboxIdentityFingerprint,
),
);

expect(verdict.reason).toContain("retained sandbox identity");
});

it.each([
["workspace", { ...MANAGED, workspace: "" }],
["sandbox ID", { ...MANAGED, sandboxId: "" }],
Expand Down
68 changes: 53 additions & 15 deletions src/lib/actions/sandbox/destroy-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import { readTimerMarker } from "../../shields/timer-control";
import type { SandboxEntry } from "../../state/registry";
import {
classifyDestroyContainerIdentity,
isSameDestroyContainerIdentity,
isSameDestroyContainerIdentityProof,
observeDestroyContainerIdentity,
removeExactDestroyContainerIdentity,
removeExactDestroyContainerIdentities,
type DestroyContainerIdentityProof,
type SandboxNameLabeledContainer,
} from "./destroy-presence";
import { type DestroyRunOpenshell, SANDBOX_DESTROY_TIMEOUT_MS } from "./destroy-gateway";
Expand Down Expand Up @@ -69,10 +70,11 @@ type SandboxDestroyExecutionInput = {
sandbox: SandboxEntry | null;
sandboxConfirmedAbsent: boolean;
sandboxName: string;
// `undefined` delegates identity gating to the runtime provider.
// `null` records confirmed absence; an object records the one managed
// container observed by the pre-destroy guard.
expectedContainerIdentity?: SandboxNameLabeledContainer | null;
// `undefined` delegates identity gating to the runtime provider. An empty
// array records confirmed absence; other arrays contain the immutable
// Docker IDs qualified before destroy preparation.
expectedContainerIdentities?: readonly SandboxNameLabeledContainer[];
expectedContainerIdentityFingerprint?: string;
portableContainerAuthority?: PreparedPortableDemoSandboxDestroyAuthority;
stopInferenceResources: () => void;
runtimeProviders?: RuntimeProviderBundleRegistry;
Expand Down Expand Up @@ -299,7 +301,8 @@ export async function executeSandboxDestroy({
sandbox,
sandboxConfirmedAbsent,
sandboxName,
expectedContainerIdentity,
expectedContainerIdentities,
expectedContainerIdentityFingerprint,
portableContainerAuthority,
stopInferenceResources,
runtimeProviders = CURRENT_RUNTIME_PROVIDER_BUNDLES,
Expand All @@ -312,6 +315,19 @@ export async function executeSandboxDestroy({
| { status: "ambiguous"; detail: string; subject?: string }
| { status: "probe-failed"; detail: string; subject?: string };
const pendingPolicyVerification = sandbox?.pendingPolicyVerification;
const expectedContainerProof: DestroyContainerIdentityProof =
expectedContainerIdentities === undefined
? { identity: undefined }
: { identities: expectedContainerIdentities };
const proofFromVerdict = (
verdict: ReturnType<typeof classifyDestroyContainerIdentity>,
): DestroyContainerIdentityProof | null => {
if (verdict.status === "clear") {
return { identities: verdict.identity === null ? [] : [verdict.identity] };
}
if (verdict.status === "recovery") return { identities: verdict.identities };
return null;
};
const inspectPendingPolicyVerificationContinuity = (): IdentityContinuity => {
if (!pendingPolicyVerification) return { status: "match" };
if (!getSandbox) {
Expand All @@ -326,6 +342,16 @@ export async function executeSandboxDestroy({
if (!isDeepStrictEqual(readCurrentCheckpoint(), pendingPolicyVerification)) {
return { status: "changed", subject: "Pending policy verification authority" };
}
if (
sandboxConfirmedAbsent &&
expectedContainerIdentities !== undefined &&
expectedContainerIdentityFingerprint ===
pendingPolicyVerification.sandboxIdentityFingerprint
) {
return isDeepStrictEqual(readCurrentCheckpoint(), pendingPolicyVerification)
? { status: "match" }
: { status: "changed", subject: "Pending policy verification authority" };
}
const inspectIdentity =
deps.inspectOpenShellSandboxIdentityFingerprint ??
inspectOpenShellSandboxIdentityFingerprint;
Expand Down Expand Up @@ -362,12 +388,17 @@ export async function executeSandboxDestroy({
return { status: "probe-failed", detail: redactDestroyError(error) };
}
}
if (expectedContainerIdentity === undefined) return { status: "match" };
if (expectedContainerIdentities === undefined) return { status: "match" };
const verdict = classifyDestroyContainerIdentity(
sandboxName,
observeDestroyContainerIdentity(sandboxName),
expectedContainerIdentityFingerprint,
);
if (isSameDestroyContainerIdentity(expectedContainerIdentity, verdict)) {
const actualContainerProof = proofFromVerdict(verdict);
if (
actualContainerProof &&
isSameDestroyContainerIdentityProof(expectedContainerProof, actualContainerProof)
) {
return { status: "match" };
}
if (verdict.status === "probe-failed") {
Expand Down Expand Up @@ -510,14 +541,14 @@ export async function executeSandboxDestroy({
" Managed inference cleanup may already be partial; inspect or restart its resources before retrying.",
);
}
// `expectedContainerIdentity === null` is a completed Docker identity
// An empty `expectedContainerIdentities` is a completed Docker identity
// probe with zero matching containers. `undefined` means this runtime
// does not use that probe (or Portable owns identity); skip hardening
// only when OpenShell already proved absence. A live labeled Docker
// identity still hardens even if the OpenShell list says absent.
const sandboxRuntimeConfirmedAbsent =
expectedContainerIdentity === null ||
(expectedContainerIdentity === undefined && sandboxConfirmedAbsent);
expectedContainerIdentities?.length === 0 ||
(expectedContainerIdentities === undefined && sandboxConfirmedAbsent);
let hardened: HardenedDeleteState;
try {
hardened = wipeAndHardenLiveSandbox(
Expand Down Expand Up @@ -638,12 +669,19 @@ export async function executeSandboxDestroy({
};
}

if (!forcedLocalCleanup && (portableContainerAuthority || expectedContainerIdentity)) {
if (
!forcedLocalCleanup &&
(portableContainerAuthority || expectedContainerIdentities !== undefined)
) {
try {
if (portableContainerAuthority) {
portableContainerAuthority.verifyAbsent();
} else if (expectedContainerIdentity) {
removeExactDestroyContainerIdentity(sandboxName, expectedContainerIdentity, console.log);
} else if (expectedContainerIdentities !== undefined) {
removeExactDestroyContainerIdentities(
sandboxName,
expectedContainerIdentities,
console.log,
);
}
} catch (error) {
const detail = redactDestroyError(error);
Expand Down
94 changes: 81 additions & 13 deletions src/lib/actions/sandbox/destroy-presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
OPENSHELL_SANDBOX_ID_LABEL,
OPENSHELL_SANDBOX_NAME_LABEL,
removeExactOpenShellDockerSandboxContainer,
removeExactOpenShellDockerSandboxContainers,
} from "../../onboard/openshell-docker-sandbox-containers";
import { fingerprintOpenShellSandboxId } from "../../adapters/openshell/sandbox-identity";
import { sanitizeReadinessText } from "../../readiness/sanitize";
import {
type DockerSandboxIdentityObservation,
Expand Down Expand Up @@ -35,6 +37,7 @@ export type SandboxNameLabeledContainer = {
/** Verdict for whether destroy resolved one complete managed container identity. */
export type DestroyContainerIdentityVerdict =
| { status: "clear"; identity: SandboxNameLabeledContainer | null }
| { status: "recovery"; identities: SandboxNameLabeledContainer[] }
| { status: "probe-failed"; detail: string }
| {
status: "ambiguous";
Expand All @@ -47,14 +50,27 @@ export type DestroyContainerIdentityVerdict =
export type AssertUnambiguousDestroyIdentityDeps = {
providerId: string;
redact: (detail: string) => string;
retainedSandboxIdentityFingerprint?: string;
cliName?: string;
classify?: (sandboxName: string) => DestroyContainerIdentityVerdict;
classify?: (
sandboxName: string,
retainedSandboxIdentityFingerprint?: string,
) => DestroyContainerIdentityVerdict;
error?: (message: string) => void;
};

export type DestroyContainerIdentityProof = {
identity: SandboxNameLabeledContainer | null | undefined;
};
export type DestroyContainerIdentityProof =
| { identity: SandboxNameLabeledContainer | null | undefined }
| { identities: readonly SandboxNameLabeledContainer[] };

/** Normalize the legacy single-container proof and recovery set proof. */
export function getDestroyContainerIdentities(
proof: DestroyContainerIdentityProof,
): readonly SandboxNameLabeledContainer[] | undefined {
if ("identities" in proof) return proof.identities;
if (proof.identity === undefined) return undefined;
return proof.identity === null ? [] : [proof.identity];
}

function observeDockerSandboxIdentities(sandboxName: string): DockerSandboxIdentityObservation {
return inspectDockerSandboxIdentities(`${OPENSHELL_SANDBOX_NAME_LABEL}=${sandboxName}`, {
Expand All @@ -80,6 +96,19 @@ export function removeExactDestroyContainerIdentity(
removeExactOpenShellDockerSandboxContainer(sandboxName, expectedIdentity.id, log);
}

/** Retire the exact container set qualified from one retained recovery fingerprint. */
export function removeExactDestroyContainerIdentities(
sandboxName: string,
expectedIdentities: readonly SandboxNameLabeledContainer[],
log: (message: string) => void,
): void {
removeExactOpenShellDockerSandboxContainers(
sandboxName,
expectedIdentities.map((identity) => identity.id),
log,
);
}

/**
* Classify every Docker container carrying `openshell.ai/sandbox-name=<name>`.
* The query intentionally does not filter by managed-by so a foreign container
Expand All @@ -88,6 +117,7 @@ export function removeExactDestroyContainerIdentity(
export function classifyDestroyContainerIdentity(
sandboxName: string,
observation: DockerSandboxIdentityObservation,
retainedSandboxIdentityFingerprint?: string,
): DestroyContainerIdentityVerdict {
if (observation.status === "probe-failed") {
return {
Expand Down Expand Up @@ -124,6 +154,30 @@ export function classifyDestroyContainerIdentity(
managed,
};
}
if (managed.length > 0 && retainedSandboxIdentityFingerprint !== undefined) {
const identityMatches = managed.every(
(row) =>
row.workspace.length > 0 &&
row.sandboxId.length > 0 &&
fingerprintOpenShellSandboxId(row.sandboxId) === retainedSandboxIdentityFingerprint,
);
const oneWorkspace = new Set(managed.map((row) => row.workspace)).size === 1;
if (!identityMatches || !oneWorkspace) {
return {
status: "ambiguous",
sandboxName,
reason: "one or more managed containers do not match the retained sandbox identity",
foreign,
managed,
};
}
if (managed.length > 1) {
return {
status: "recovery",
identities: [...managed].sort((left, right) => left.id.localeCompare(right.id)),
};
}
}
if (managed.length !== 1) {
return {
status: "ambiguous",
Expand Down Expand Up @@ -208,12 +262,18 @@ export function assertUnambiguousDestroyContainerIdentity(
): DestroyContainerIdentityProof | false {
const classify =
deps.classify ??
((name: string) =>
classifyDestroyContainerIdentity(name, observeDestroyContainerIdentity(name)));
((name: string, retainedSandboxIdentityFingerprint?: string) =>
classifyDestroyContainerIdentity(
name,
observeDestroyContainerIdentity(name),
retainedSandboxIdentityFingerprint,
));
const error = deps.error ?? ((message: string) => console.error(` ${message}`));
if (deps.providerId !== "docker") return { identity: undefined };

const verdict = classify(sandboxName);
const verdict = deps.retainedSandboxIdentityFingerprint
? classify(sandboxName, deps.retainedSandboxIdentityFingerprint)
: classify(sandboxName);
if (verdict.status === "ambiguous") {
for (const line of formatAmbiguousDestroyIdentity(verdict, deps.cliName ?? "nemoclaw")) {
error(line);
Expand All @@ -228,20 +288,28 @@ export function assertUnambiguousDestroyContainerIdentity(
);
return false;
}
return { identity: verdict.identity };
return verdict.status === "recovery"
? { identities: verdict.identities }
: { identity: verdict.identity };
}

/** Compare provider-owned identity proofs across two destroy checkpoints. */
export function isSameDestroyContainerIdentityProof(
expected: DestroyContainerIdentityProof,
actual: DestroyContainerIdentityProof,
): boolean {
if (expected.identity === undefined || actual.identity === undefined) {
return expected.identity === actual.identity;
const expectedIdentities = getDestroyContainerIdentities(expected);
const actualIdentities = getDestroyContainerIdentities(actual);
if (expectedIdentities === undefined || actualIdentities === undefined) {
return expectedIdentities === actualIdentities;
}
return isSameDestroyContainerIdentity(expected.identity, {
status: "clear",
identity: actual.identity,
if (expectedIdentities.length !== actualIdentities.length) return false;
return expectedIdentities.every((identity, index) => {
const candidate = actualIdentities[index];
return candidate !== undefined && isSameDestroyContainerIdentity(identity, {
status: "clear",
identity: candidate,
});
});
}

Expand Down
Loading
Loading