diff --git a/src/lib/actions/sandbox/destroy-execution.ts b/src/lib/actions/sandbox/destroy-execution.ts index 93edff1e48e..d6ebcbc4d75 100644 --- a/src/lib/actions/sandbox/destroy-execution.ts +++ b/src/lib/actions/sandbox/destroy-execution.ts @@ -460,6 +460,8 @@ export async function executeSandboxDestroy({ runtimeProviders, ); const pendingCreateIdentity = sandbox?.pendingCreateIdentity; + const expectedSandboxIdentityFingerprint = + pendingCreateIdentity?.sandboxIdentityFingerprint ?? expectedContainerIdentityFingerprint; const expectedContainerProof: DestroyContainerIdentityProof = expectedRuntimeProviderIdentity ? { identities: undefined, @@ -479,12 +481,15 @@ export async function executeSandboxDestroy({ if (verdict.status === "recovery") return { identities: verdict.identities }; return null; }; - const inspectPendingCreateVerificationContinuity = (): IdentityContinuity => { - if (!pendingCreateIdentity) return { status: "match" }; + const inspectSandboxIdentityContinuity = (): IdentityContinuity => { + if (!expectedSandboxIdentityFingerprint) return { status: "match" }; + const subject = pendingCreateIdentity + ? "Pending create sandbox identity" + : "Retained sandbox identity"; if (!getSandbox) { return { status: "probe-failed", - subject: "Pending create sandbox identity", + subject, detail: "an exact registry reader is unavailable", }; } @@ -495,8 +500,10 @@ export async function executeSandboxDestroy({ } if ( sandboxConfirmedAbsent && - expectedContainerIdentities !== undefined && - expectedContainerIdentityFingerprint === pendingCreateIdentity.sandboxIdentityFingerprint + (!pendingCreateIdentity || + (expectedContainerIdentities !== undefined && + expectedContainerIdentityFingerprint === + pendingCreateIdentity.sandboxIdentityFingerprint)) ) { return isDeepStrictEqual(readCurrentCheckpoint(), pendingCreateIdentity) ? { status: "match" } @@ -507,30 +514,30 @@ export async function executeSandboxDestroy({ inspectOpenShellSandboxIdentityFingerprint; const liveFingerprint = inspectIdentity({ sandboxName, - gatewayName: pendingCreateIdentity.gatewayName, + gatewayName: pendingCreateIdentity?.gatewayName ?? deleteGatewayName, ...(destroyRuntimeSelection ? { runtimeSelection: destroyRuntimeSelection } : {}), }); if ( - liveFingerprint !== pendingCreateIdentity.sandboxIdentityFingerprint || + liveFingerprint !== expectedSandboxIdentityFingerprint || !isDeepStrictEqual(readCurrentCheckpoint(), pendingCreateIdentity) ) { return { status: "changed", - subject: "Pending create sandbox identity", + subject, }; } return { status: "match" }; } catch (error) { return { status: "probe-failed", - subject: "Pending create sandbox identity", + subject, detail: redactDestroyError(error), }; } }; const inspectIdentityContinuity = (): IdentityContinuity => { - const pendingContinuity = inspectPendingCreateVerificationContinuity(); - if (pendingContinuity.status !== "match") return pendingContinuity; + const sandboxContinuity = inspectSandboxIdentityContinuity(); + if (sandboxContinuity.status !== "match") return sandboxContinuity; if (portableContainerAuthority) { try { portableContainerAuthority.revalidate(); diff --git a/src/lib/actions/sandbox/destroy-retained-recovery-flow.test.ts b/src/lib/actions/sandbox/destroy-retained-recovery-flow.test.ts index 212723a3693..24a2bd57adb 100644 --- a/src/lib/actions/sandbox/destroy-retained-recovery-flow.test.ts +++ b/src/lib/actions/sandbox/destroy-retained-recovery-flow.test.ts @@ -256,7 +256,7 @@ describe("destroySandbox retained recovery flow", () => { ); expect(harness.errorSpy).toHaveBeenCalledWith( - expect.stringContaining("without an atomic OpenShell delete-by-identity primitive"), + expect.stringContaining("Retained sandbox identity could not be inspected"), ); expect(harness.runOpenshellSpy).not.toHaveBeenCalledWith( ["sandbox", "delete", "alpha"], @@ -380,7 +380,7 @@ describe("destroySandbox retained recovery flow", () => { ); it( - "does not delete a live retained sandbox when Docker identity is absent (#10547)", + "preserves live recovery when OpenShell identity cannot be inspected (#10863)", { timeout: 30_000 }, async () => { const recovery = retainedRecoveryRecord(); @@ -398,7 +398,7 @@ describe("destroySandbox retained recovery flow", () => { ); expect(harness.errorSpy).toHaveBeenCalledWith( - expect.stringContaining("cannot bind a mutable-name delete to the retained record"), + expect.stringContaining("sandbox identity could not be inspected"), ); expect(harness.runOpenshellSpy).not.toHaveBeenCalledWith( ["sandbox", "delete", "alpha"], @@ -410,12 +410,13 @@ describe("destroySandbox retained recovery flow", () => { ); it( - "does not issue mutable-name deletion for a live retained sandbox with matching identity (#10547)", + "destroys a live retained sandbox with matching identity (#10863)", { timeout: 30_000 }, async () => { const recovery = retainedRecoveryRecord(); const containerId = "a".repeat(64); const harness = createDestroyHarness({ + liveListOutput: "Id: sb-alpha", dockerRunResult: { status: 0, stdout: `${containerId}\topenshell\tdefault\tsb-alpha`, @@ -427,39 +428,26 @@ describe("destroySandbox retained recovery flow", () => { retainedRecoveryRecords: [recovery], }); - await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow( - "process.exit(1)", - ); + await expect(harness.destroySandbox("alpha", { yes: true })).resolves.toBeUndefined(); - expect(harness.errorSpy).toHaveBeenCalledWith( - expect.stringContaining("cannot bind a mutable-name delete to the retained record"), - ); - expect(harness.runOpenshellSpy).not.toHaveBeenCalledWith( - ["sandbox", "delete", "alpha"], + expect(harness.runOpenshellSpy).toHaveBeenCalledWith( + ["sandbox", "delete", "-g", recovery.gatewayName, "alpha"], expect.anything(), ); - expect(harness.resolveRetainedSandboxRecoverySpy).not.toHaveBeenCalled(); - expect(harness.removeSandboxSpy).not.toHaveBeenCalled(); + expect(harness.resolveRetainedSandboxRecoverySpy).toHaveBeenCalledWith(recovery); + expect(harness.removeSandboxSpy).toHaveBeenCalledWith("alpha"); + expect(exitSpy).not.toHaveBeenCalled(); }, ); it( - "still fails closed for a live retained sandbox even with a proven-matching OpenShell identity (#10863)", + "destroys a matching live retained sandbox without a host Docker container (#10863)", { timeout: 30_000 }, async () => { - // OpenShell exposes no atomic delete-by-identity primitive, so no - // amount of identity proof inside NemoClaw can close the window where - // another OpenShell client replaces the sandbox under the same name - // between the last read and OpenShell processing the delete. Automatic - // deletion of a live retained sandbox is therefore always fail-closed, - // even when the live OpenShell id matches the retained record. const recovery = retainedRecoveryRecord("sandbox-alpha"); - const containerId = "a".repeat(64); const harness = createDestroyHarness({ - dockerRunResult: { - status: 0, - stdout: `${containerId}\topenshell\tdefault\tsandbox-alpha`, - }, + liveListOutput: "Id: sandbox-alpha", + dockerRunResult: { status: 0, stdout: "" }, registryEntryOverrides: { lifecycleGeneration: recovery.lifecycleGeneration!, lifecycleLiveIdentityFingerprint: recovery.sandboxIdentityFingerprint!, @@ -467,24 +455,15 @@ describe("destroySandbox retained recovery flow", () => { retainedRecoveryRecords: [recovery], }); - await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow( - "process.exit(1)", - ); + await expect(harness.destroySandbox("alpha", { yes: true })).resolves.toBeUndefined(); - expect(harness.errorSpy).toHaveBeenCalledWith( - expect.stringContaining("cannot bind a mutable-name delete to the retained record"), - ); - expect(harness.errorSpy.mock.calls.flat().join("\n")).not.toContain( - "openshell sandbox delete", - ); - expect(harness.errorSpy).toHaveBeenCalledWith( - expect.stringContaining(`openshell sandbox list -g ${recovery.gatewayName} -o json`), - ); - expect(harness.runOpenshellSpy).not.toHaveBeenCalledWith( - ["sandbox", "delete", "alpha"], + expect(harness.runOpenshellSpy).toHaveBeenCalledWith( + ["sandbox", "delete", "-g", recovery.gatewayName, "alpha"], expect.anything(), ); - expect(harness.resolveRetainedSandboxRecoverySpy).not.toHaveBeenCalled(); + expect(harness.resolveRetainedSandboxRecoverySpy).toHaveBeenCalledWith(recovery); + expect(harness.removeSandboxSpy).toHaveBeenCalledWith("alpha"); + expect(exitSpy).not.toHaveBeenCalled(); }, ); @@ -514,6 +493,85 @@ describe("destroySandbox retained recovery flow", () => { }, ); + it.each([ + ["a replacement sandbox", "Id: sandbox-replacement", undefined], + ["unknown presence", "Id: sb-alpha", { status: 1, stdout: "", stderr: "" }], + ])( + "preserves retained identity when OpenShell reports %s (#10863)", + async (_scenario, liveListOutput, sandboxListResult) => { + const recovery = retainedRecoveryRecord(); + const harness = createDestroyHarness({ + liveListOutput, + dockerRunResult: { status: 0, stdout: "" }, + registryEntryOverrides: { + lifecycleGeneration: recovery.lifecycleGeneration!, + lifecycleLiveIdentityFingerprint: recovery.sandboxIdentityFingerprint!, + }, + retainedRecoveryRecords: [recovery], + ...(sandboxListResult ? { sandboxListResult } : {}), + }); + + await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow( + "process.exit(1)", + ); + + expect(harness.events).toEqual([]); + expect(harness.removeSandboxSpy).not.toHaveBeenCalled(); + expect(harness.resolveRetainedSandboxRecoverySpy).not.toHaveBeenCalled(); + }, + ); + + it("refuses retained identity drift at the delete boundary (#10863)", async () => { + const recovery = retainedRecoveryRecord(); + const harness = createDestroyHarness({ + dockerRunResult: { status: 0, stdout: "" }, + registryEntryOverrides: { + lifecycleGeneration: recovery.lifecycleGeneration!, + lifecycleLiveIdentityFingerprint: recovery.sandboxIdentityFingerprint!, + }, + retainedRecoveryRecords: [recovery], + }); + let identityReads = 0; + harness.captureOpenshellSpy.mockImplementation((args: string[]) => { + identityReads += Number(args[0] === "sandbox" && args[1] === "get"); + return { + status: 0, + output: `Id: ${identityReads < 5 ? "sb-alpha" : "sandbox-replacement"}`, + }; + }); + + await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow("process.exit(1)"); + + expect(harness.events).toContain("detach"); + expect(harness.events).not.toContain("delete"); + expect(harness.errorSpy).toHaveBeenCalledWith( + expect.stringContaining("Retained sandbox identity changed at the delete boundary"), + ); + expect(harness.removeSandboxSpy).not.toHaveBeenCalled(); + expect(harness.resolveRetainedSandboxRecoverySpy).not.toHaveBeenCalled(); + }); + + it("preserves matching retained recovery after deletion fails (#10863)", async () => { + const recovery = retainedRecoveryRecord(); + const harness = createDestroyHarness({ + liveListOutput: "Id: sb-alpha", + deleteStatus: 7, + deleteOutput: "delete failed", + dockerRunResult: { status: 0, stdout: "" }, + registryEntryOverrides: { + lifecycleGeneration: recovery.lifecycleGeneration!, + lifecycleLiveIdentityFingerprint: recovery.sandboxIdentityFingerprint!, + }, + retainedRecoveryRecords: [recovery], + }); + + await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow("process.exit(7)"); + + expect(harness.events).toContain("delete"); + expect(harness.removeSandboxSpy).not.toHaveBeenCalled(); + expect(harness.resolveRetainedSandboxRecoverySpy).not.toHaveBeenCalled(); + }); + it.each([ ["present", undefined, "reports a sandbox present"], ["a failed list command", { status: 1, stdout: "", stderr: "" }, "could not determine"], diff --git a/src/lib/actions/sandbox/destroy.ts b/src/lib/actions/sandbox/destroy.ts index ab80bcd202f..7cfde391dc6 100644 --- a/src/lib/actions/sandbox/destroy.ts +++ b/src/lib/actions/sandbox/destroy.ts @@ -897,23 +897,17 @@ async function destroySandboxUnlocked( `Refusing to destroy sandbox '${sandboxName}': gateway authority changed during preflight.`, ); } - if (retainedRecoveryAuthority && sandboxPresence !== "absent") { - // OpenShell has no atomic delete-by-identity primitive: it exposes no - // way to bind a mutable-name delete to the retained record's immutable - // sandbox id/resource version. Even a fresh identity read immediately - // before the delete command cannot close the window where another - // OpenShell client removes the retained sandbox and creates a - // replacement under the same name between that read and OpenShell - // processing the delete (#10863). Automatic deletion of a live retained - // sandbox is therefore always fail-closed. Inspection cannot authorize a - // later mutable-name delete, so the recovery record remains unresolved - // until OpenShell can prove absence through the owning gateway. + if ( + retainedRecoveryAuthority && + sandboxPresence !== "absent" && + (sandboxPresence !== "present" || !retainedSandboxIdentityFingerprint) + ) { const presenceDetail = sandboxPresence === "present" ? "OpenShell reports a sandbox present under this name." : "OpenShell could not determine whether a sandbox is present under this name."; console.error( - ` Refusing to delete retained sandbox '${sandboxName}': ${presenceDetail} NemoClaw cannot bind a mutable-name delete to the retained record (create-attempt label '${retainedRecoveryAuthority.createAttemptNonce}') without an atomic OpenShell delete-by-identity primitive. No sandbox resources were removed. Preserve the recovery record. Inspect 'openshell sandbox list -g ${retainedRecoveryAuthority.gatewayName} -o json' for diagnosis only; do not run mutable-name deletion. Recovery remains blocked until the owning gateway reports the sandbox absent. Then rerun '${CLI_NAME} ${sandboxName} destroy --yes' to reconcile verified residual resources and the recovery record.`, + ` Refusing to delete retained sandbox '${sandboxName}': ${presenceDetail} Its live identity cannot be verified. Inspect 'openshell sandbox list -g ${retainedRecoveryAuthority.gatewayName} -o json'. Preserve the recovery record; no sandbox resources were removed. Create-attempt label: '${retainedRecoveryAuthority.createAttemptNonce}'.`, ); preparedManagedLlamaCppCleanup?.abort(); requestSandboxDestroyExit(1); diff --git a/src/lib/onboard/cancel-rollback.test.ts b/src/lib/onboard/cancel-rollback.test.ts index 8e88459cba7..002367ce78a 100644 --- a/src/lib/onboard/cancel-rollback.test.ts +++ b/src/lib/onboard/cancel-rollback.test.ts @@ -37,8 +37,6 @@ describe("createSandboxCancelRollback", () => { expect(guidance).toContain( `ai.nvidia.nemoclaw.create-attempt=${RECOVERY_CONTEXT.createAttemptNonce}`, ); - expect(guidance).toContain("did not run OpenShell's mutable-name deletion command"); - expect(guidance).toContain("Do not delete the sandbox by mutable sandbox name"); expect(guidance).toContain("Shared inference providers are gateway configuration"); expect(guidance).toContain("not sandbox cleanup targets"); expect(guidance).toContain("nemoclaw new-sb destroy"); @@ -301,7 +299,7 @@ describe("makeOnboardCancelExit", () => { }); describe("buildCancelRollbackMessage", () => { - it("preserves identity-bound recovery guidance", () => { + it("places supported destroy guidance before recovery diagnostics (#10863)", () => { const message = buildCancelRollbackMessage("sb", SANDBOX_FINGERPRINT, RECOVERY_CONTEXT).join( "\n", ); @@ -309,8 +307,11 @@ describe("buildCancelRollbackMessage", () => { expect(message).toContain("preserved incomplete sandbox 'sb'"); expect(message).toContain(SANDBOX_FINGERPRINT); expect(message).toContain(RECOVERY_CONTEXT.createAttemptNonce); - expect(message).toContain("retained recovery evidence"); - expect(message).toContain("does not authorize deletion by mutable name"); + expect(message).toContain("nemoclaw sb destroy"); + expect(message).toContain("verify and remove the retained sandbox"); + expect(message.indexOf("nemoclaw sb destroy")).toBeLessThan( + message.indexOf(RECOVERY_CONTEXT.createAttemptNonce), + ); expect(message).not.toContain("openshell sandbox delete"); expect(message).not.toContain("cannot delete it by immutable identity"); }); @@ -318,7 +319,8 @@ describe("buildCancelRollbackMessage", () => { it("does not refer to an undisplayed create-attempt label", () => { const message = buildCancelRollbackMessage("sb", SANDBOX_FINGERPRINT).join("\n"); - expect(message).toContain("preserve the displayed fingerprint"); + expect(message).toContain("nemoclaw sb destroy"); + expect(message).toContain(SANDBOX_FINGERPRINT); expect(message).not.toContain("displayed create-attempt label"); }); }); diff --git a/src/lib/onboard/cancel-rollback.ts b/src/lib/onboard/cancel-rollback.ts index 320a3236903..27db2046bdb 100644 --- a/src/lib/onboard/cancel-rollback.ts +++ b/src/lib/onboard/cancel-rollback.ts @@ -61,34 +61,24 @@ export function buildCancelRollbackMessage( return [ "", ` Onboarding cancelled — preserved incomplete sandbox '${sandboxName}'.`, - ...(recoveryContext - ? [ - ` Create-attempt label: ${NEMOCLAW_CREATE_ATTEMPT_LABEL}=${recoveryContext.createAttemptNonce}`, - ] - : []), ...(sandboxIdentityFingerprint ? [ - ` Durable sandbox identity fingerprint: ${sandboxIdentityFingerprint}`, - " Preserve this fingerprint as retained recovery evidence; it does not authorize deletion by mutable name.", + ` Run '${cliName()} ${sandboxName} destroy' to verify and remove the retained sandbox and clear the matching recovery record.`, ] : [ " Its durable identity fingerprint is unavailable; preserve the registry and onboarding recovery state.", - " NemoClaw cannot verify this sandbox identity or authorize its removal without a recorded fingerprint.", + " Inspect the owning gateway. Destroy can clear the recovery record only after OpenShell confirms the sandbox absent.", + " Do not delete the sandbox by mutable sandbox name.", ]), - " NemoClaw did not run OpenShell's mutable-name deletion command because the name may now identify a replacement sandbox.", - " Do not delete the sandbox by mutable sandbox name.", " Shared inference providers are gateway configuration and are not sandbox cleanup targets.", - ...(sandboxIdentityFingerprint + ...(recoveryContext ? [ - ` Run '${cliName()} ${sandboxName} destroy'. If OpenShell confirms the retained sandbox absent, destroy removes only verified residual containers and can clear the matching recovery record.`, - recoveryContext - ? " If it is still live or presence is unknown, destroy refuses deletion. Inspect the owning gateway for diagnosis only; do not delete by mutable name." - : " If it is still live or presence is unknown, preserve the displayed fingerprint; destroy refuses deletion and preserves the recovery record.", + ` Create-attempt label: ${NEMOCLAW_CREATE_ATTEMPT_LABEL}=${recoveryContext.createAttemptNonce}`, ] - : [ - ` Run '${cliName()} ${sandboxName} destroy'. It can clear the recovery record only after OpenShell confirms the sandbox absent and residual cleanup succeeds.`, - " If the sandbox is present or presence is unknown, preserve the recovery record and do not delete by mutable name.", - ]), + : []), + ...(sandboxIdentityFingerprint + ? [` Durable sandbox identity fingerprint: ${sandboxIdentityFingerprint}`] + : []), ]; } diff --git a/src/lib/onboard/lifecycle-contracts.md b/src/lib/onboard/lifecycle-contracts.md index 049ae3b3bd9..6b76d580678 100644 --- a/src/lib/onboard/lifecycle-contracts.md +++ b/src/lib/onboard/lifecycle-contracts.md @@ -125,7 +125,7 @@ runtime mutation | Journey and entry | Desired state, planning, and assembly | Visible and destructive boundaries | Checkpoint and secret boundary | Compensation, coverage, and gaps | |---|---|---|---|---| -| **New interactive or non-interactive onboard** — `onboard()` and `resolveOnboardEntryOptions` | Current flags, environment, and prompts. `MessagingWorkflowPlanner.buildPlan`, `prepareSandboxMessagingPreflight`, resource-profile selection, `resolveSandboxCreateIntent`, and `materializeSandboxCreatePlan` assemble policy, provider, package, resource, host-forward, and runtime-setup contributions. Non-interactive mode replaces prompts with defaults or hard aborts. | Consent/session/lock setup and preflight can persist local state, install OpenShell, or clean stale gateway artifacts before the gateway handler. Gateway reuse/recovery/start is the first provider-routing effect; inference-provider upserts follow. For OpenClaw, messaging selection and plan reconciliation complete before web-search or messaging provider registration. Each validated provider group is then created or updated and checkpointed before resource selection. A name with no live sandbox has no sandbox-destructive boundary; an existing target enters the recreate contract below. | Whole-step session plus machine snapshot. OpenClaw adds narrow checkpoints after each completed secret-free sandbox prompt group; sandbox registry registration is deferred until readiness and live validation. The session stores credential environment names, redacted endpoint metadata, legacy-value digests, and non-secret names of web-search and messaging providers registered for resume; real values remain process- or gateway-bound. | Readiness, post-create policy verification, dashboard forwarding, and cancellation failures preserve the live sandbox and an independent identity-bound recovery record. A later `destroy` refuses mutable-name deletion while that sandbox is live. Recovery remains blocked while the sandbox is present or its presence is unknown. After OpenShell authoritatively reports absence, destroy uses the record to qualify immutable runtime identity and, for Docker-backed sandboxes, exact container identities before residual cleanup and record retirement. A different explicit sandbox name starts a fresh session without changing the retained record. Exact provider-owned GPU cleanup can proceed through its owner receipt. NemoClaw attempts to remove temporary policy and build-context sources and reports cleanup failures with the onboarding error; post-create failures retain recovery state. Cancellation before sandbox creation can leave the session resumable. Shared inference providers remain gateway configuration and are not sandbox cleanup targets. Coverage: `transition-traces.test.ts`, `sandbox-create-intent-boundary.test.ts`, `sandbox-create-plan.test.ts`, and the focused cancellation, readiness, GPU cleanup, dashboard, policy-authority, destroy, and retained-recovery tests. Gap: gateway upserts can outlive a failed or interrupted create. | +| **New interactive or non-interactive onboard** — `onboard()` and `resolveOnboardEntryOptions` | Current flags, environment, and prompts. `MessagingWorkflowPlanner.buildPlan`, `prepareSandboxMessagingPreflight`, resource-profile selection, `resolveSandboxCreateIntent`, and `materializeSandboxCreatePlan` assemble policy, provider, package, resource, host-forward, and runtime-setup contributions. Non-interactive mode replaces prompts with defaults or hard aborts. | Consent/session/lock setup and preflight can persist local state, install OpenShell, or clean stale gateway artifacts before the gateway handler. Gateway reuse/recovery/start is the first provider-routing effect; inference-provider upserts follow. For OpenClaw, messaging selection and plan reconciliation complete before web-search or messaging provider registration. Each validated provider group is then created or updated and checkpointed before resource selection. A name with no live sandbox has no sandbox-destructive boundary; an existing target enters the recreate contract below. | Whole-step session plus machine snapshot. OpenClaw adds narrow checkpoints after each completed secret-free sandbox prompt group; sandbox registry registration is deferred until readiness and live validation. The session stores credential environment names, redacted endpoint metadata, legacy-value digests, and non-secret names of web-search and messaging providers registered for resume; real values remain process- or gateway-bound. | Readiness, post-create policy verification, dashboard forwarding, and cancellation failures preserve the live sandbox and an independent identity-bound recovery record. A later `destroy` can delete a live retained sandbox whose OpenShell identity matches the recorded durable fingerprint. It rechecks that identity during cleanup and immediately before deletion. Missing identity, uncertain presence, or observed identity drift blocks deletion and preserves the recovery record. OpenShell deletes by mutable name; the final identity check and deletion are not atomic. Another gateway client can replace the sandbox between those operations, causing deletion of the replacement. After OpenShell authoritatively reports absence, destroy uses the record to qualify immutable runtime identity and, for Docker-backed sandboxes, exact container identities before residual cleanup and record retirement. A different explicit sandbox name starts a fresh session without changing the retained record. Exact provider-owned GPU cleanup can proceed through its owner receipt. NemoClaw attempts to remove temporary policy and build-context sources and reports cleanup failures with the onboarding error; post-create failures retain recovery state. Cancellation before sandbox creation can leave the session resumable. Shared inference providers remain gateway configuration and are not sandbox cleanup targets. Coverage: `transition-traces.test.ts`, `sandbox-create-intent-boundary.test.ts`, `sandbox-create-plan.test.ts`, and the focused cancellation, readiness, GPU cleanup, dashboard, policy-authority, destroy, and retained-recovery tests. Gap: gateway upserts can outlive a failed or interrupted create. | | **`--fresh` onboard** — `resolveOnboardEntryOptions`, `prepareFreshSession`, `createBaseImageResolutionContext` | Current flags/environment/prompts replace resumable intent. `--fresh` disables auto-resume and forces base-image resolution; it does not prove that the selected sandbox name is unused. | The first destructive effect is local: the prior onboard session is cleared before a new session is saved. A matching live sandbox can later reuse or recreate through the normal sandbox decision; `--fresh` does not itself delete it. | The new session and machine snapshot replace the old resume checkpoint. Credential and effect boundaries then match new onboard or live recreate. | The discarded resume checkpoint is not restored on later failure. Covered by `entry-options.test.ts`, `session-bootstrap.test.ts`, and base-image resolution tests. | | **Resume, re-onboard, or recreate** — `onboard()`, `prepareOnboardSession`, `decideSandboxResume`, live-sandbox handling in `createSandbox` | For `--resume`, the recorded session is authoritative and conflicting current name/provider/model/image/tool-disclosure hints are rejected. A new re-onboard run takes current flags, environment, and prompts as intent while registry/gateway state provides drift evidence. The machine resolves a complete secret-free create intent, including policy, messaging/provider, GPU, resource, disabled-channel, and agent inputs, before repair/removal or live recreation. | Ordinary live recreation conditionally backs up before provider cleanup, **delete**, and image removal. The recreate journal preserves the source registry row after deletion. Replacement registration commits the new row after readiness and validation. A selected pre-upgrade backup suppresses a new one; an explicit override permits recreation without backup. Resume registry removal and `repair-and-recreate` occur only after complete intent validation. Temporary policy/build artifacts remain materialization effects after the delete boundary. | Resume continues the recorded session/machine snapshot; non-resume re-onboard writes a new session first. OpenClaw records completed sandbox name, web search, messaging, and resource choices with explicit progress markers, including explicit `null` choices, while the complete create intent stays process-local and is not persisted or emitted. Raw credential values remain outside the session. A missing process value can be rebound only when the same OpenClaw session recorded successfully registering that provider and its live provider name, provider type, and credential key still match; otherwise interactive resume requests it again and non-interactive resume exits with environment-variable guidance. Credentials are checked before mutation and again immediately before materialization. | A failed replacement keeps the source registry row. Restore failures warn and can still publish the replacement; managed-DCode live-selection failure leaves a running, unregistered sandbox with manual-delete guidance. Checkpoint replay reuses an exact live sandbox after an interrupted create and backfills missing create/register receipts. Cancel rollback is not armed and there is no rebuild-style receipt rollback. Coverage: transition traces, create-intent characterization, checkpoint replay and resume guards, and sandbox-handler crash recovery. Gaps: early backup asymmetry and no rebuild-style cross-effect rollback. | | **Rebuild or installer-driven upgrade** — `rebuildSandbox` in `rebuild-pipeline.ts`; `upgradeSandboxes` | The registry remains authoritative only for non-MCP sandbox settings. Agent-native configuration and live OpenShell state are the MCP sources. A matching session may fill guarded legacy non-MCP gaps only when its selection agrees; an unrelated/global session is never used. Ambient provider/model selection is quarantined by `isolateAmbientRecreateEnv`, apart from narrowly scoped legacy recovery. Legacy and custom-image rebuilds retain and fingerprint a prepared build context. Managed-image rebuilds instead stage an immutable image and startup-profile handoff, skip Dockerfile image preflight, and revalidate provider-bound workload authority before each deletion boundary. | Consent persistence, target-gateway selection/recovery, and target-preflight registry updates can precede disposable image build/probes. Backup is the first durable recovery checkpoint when available. MCP detach/scrub uses a bounded source-derived handoff and NIM stop is a destructive in-place effect before the **sandbox delete** boundary. Legacy and custom-image paths recheck prepared context and mutation-edge conditions before delete. Managed-image paths revalidate the provider-bound handoff before delete. | Durable checkpoints are the backup/recovery manifest when one exists and the rewritten recreate session; stale recovery can reach deletion without a manifest, making that session its first new durable checkpoint. MCP handoff state and rollback receipts are process-local. Credential metadata comes from the target or guarded fallback; raw credentials/providers are checked against current process/gateway state, while prepared installer recovery may reconstruct a missing gateway provider from a validated host credential. | In-process rollback best-effort restores source-derived MCP state, but process death after non-MCP delete can still lose non-MCP registry metadata. The inner onboarding consumes the managed-workload handoff or selects the legacy resource profile after deletion. Covered by rebuild, managed-workload authority, image-preflight, DCode, and messaging tests. Gaps: health-before-delete and atomic swap. Closed issue #5801 records the original gap; #6835 fixed only the printed recovery path. | diff --git a/test/onboarding/onboard-fresh-create-identity.test.ts b/test/onboarding/onboard-fresh-create-identity.test.ts index ec2f1eeabe2..d5bb4c3a2fd 100644 --- a/test/onboarding/onboard-fresh-create-identity.test.ts +++ b/test/onboarding/onboard-fresh-create-identity.test.ts @@ -1217,10 +1217,12 @@ if (${JSON.stringify( assertRecoveryTuple(payload.retainedRecoveryRecords[0]); assert.match(result.stderr, /preserved incomplete sandbox 'my-assistant'/u); assert.match(result.stderr, new RegExp(identityFingerprint, "u")); - assert.match(result.stderr, /Do not delete the sandbox by mutable sandbox name/u); assert.match(result.stderr, /Shared inference providers are gateway configuration/u); assert.match(result.stderr, /not sandbox cleanup targets/u); - assert.match(result.stderr, /nemoclaw my-assistant destroy/u); + assert.match( + result.stderr, + /nemoclaw my-assistant destroy' to verify and remove the retained sandbox/u, + ); assert.match(result.stderr, /clear the matching recovery record/u); assertCreateAttemptLabelReported();