From 208e7539dbb9d3f571c8516e5565daf872d0e3d7 Mon Sep 17 00:00:00 2001 From: harjoth Date: Tue, 4 Aug 2026 13:29:17 -0700 Subject: [PATCH 1/7] fix(uninstall): delete the scoped sandbox before removing its unit (#8220) Signed-off-by: harjoth --- docs/manage-sandboxes/uninstall-nemoclaw.mdx | 4 + docs/reference/commands.mdx | 4 + .../run-plan-gateway-service.test.ts | 89 +++++++++++++++++++ src/lib/actions/uninstall/run-plan.ts | 27 +++++- 4 files changed, 120 insertions(+), 4 deletions(-) diff --git a/docs/manage-sandboxes/uninstall-nemoclaw.mdx b/docs/manage-sandboxes/uninstall-nemoclaw.mdx index 77116f204b4..76b055e62b4 100644 --- a/docs/manage-sandboxes/uninstall-nemoclaw.mdx +++ b/docs/manage-sandboxes/uninstall-nemoclaw.mdx @@ -70,6 +70,10 @@ Resolve the reported error, inspect the remaining gateways with `openshell gatew Default-port uninstall removes NemoClaw-managed entries in `openshell/gateway.env`. For a NemoClaw-managed authority, it also removes only NemoClaw's marked Linux gateway unit. It preserves upstream Linux package units, the macOS Homebrew service, and unrelated environment entries. +Gateway-scoped cleanup removes that gateway's OpenShell resources first, then the marked Linux unit. +The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. +If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. +Resolve the reported error, then rerun `$$nemoclaw uninstall`. For an externally supervised authority, uninstall preserves the local gateway state used by the running process in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. A custom-port uninstall does not stop or remove the default gateway service or its environment file. diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 4470dfe9e43..3227b74ae29 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3546,6 +3546,10 @@ The compatibility `--gateway` flag cannot select another instance: when present, Default-port uninstall removes NemoClaw-managed entries in `openshell/gateway.env`. For a NemoClaw-managed authority, it also removes only NemoClaw's marked Linux gateway unit. It preserves upstream Linux package units, the macOS Homebrew service, and unrelated environment entries. +Gateway-scoped cleanup removes that gateway's OpenShell resources first, then the marked Linux unit. +The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. +If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. +Resolve the reported error, then rerun `$$nemoclaw uninstall`. For an externally supervised authority, uninstall preserves the selected local gateway state in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. A custom-port uninstall does not stop or remove the default gateway service or its environment file. diff --git a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts index 382f76cc570..2c084e1f20c 100644 --- a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts +++ b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts @@ -68,6 +68,20 @@ function writeGatewayEnv(test: Fixture, contents = "OPENSHELL_SERVER_PORT=8080\n return envPath; } +function writeSelectedSandboxRegistry(test: Fixture, sandboxName: string): void { + const registryPath = path.join(test.home, ".nemoclaw", "sandboxes.json"); + fs.mkdirSync(path.dirname(registryPath), { recursive: true }); + fs.writeFileSync( + registryPath, + `${JSON.stringify({ + defaultSandbox: sandboxName, + sandboxes: { + [sandboxName]: { name: sandboxName, gatewayName: "nemoclaw", gatewayPort: 8080 }, + }, + })}\n`, + ); +} + function writeGatewayState(test: Fixture): string { const configPath = path.join( test.home, @@ -184,6 +198,81 @@ describe("uninstall OpenShell gateway user service", () => { expect(fs.existsSync(gatewayStatePath)).toBe(true); }); + it("deletes the selected sandbox before it disables the marked Linux unit on scoped uninstall (#8220)", () => { + const test = fixture(true); + const servicePath = writeManagedService(test); + writeSelectedSandboxRegistry(test, "my-assistant"); + const calls: string[][] = []; + const dockerCalls: string[][] = []; + let gatewayStopped = false; + + const result = uninstall( + test, + false, + { + commandExists: (command) => command === "systemctl" || command === "docker", + run: (command, args) => { + calls.push([command, ...args]); + gatewayStopped ||= command === "systemctl" && args.includes("disable"); + // `systemctl disable --now` also stops the OpenShell gateway service, + // so every scoped `openshell` call fails once the unit is disabled. + return command === "openshell" && gatewayStopped + ? { status: 1, stdout: "", stderr: "gateway unreachable" } + : ok(); + }, + runDocker: (args) => { + dockerCalls.push(args); + return args[0] === "ps" + ? ok("sandbox-id openshell/sandbox openshell-cluster-nemoclaw\n") + : ok(); + }, + }, + [{ name: "nemoclaw" }, { name: "nemoclaw-8081" }], + ); + + const deletedAt = calls.findIndex( + (call) => call[0] === "openshell" && call[1] === "sandbox" && call[2] === "delete", + ); + const disabledAt = calls.findIndex( + (call) => call[0] === "systemctl" && call.includes("disable"), + ); + + expect(result.exitCode).toBe(0); + expect(deletedAt).toBeGreaterThanOrEqual(0); + expect(disabledAt).toBeGreaterThan(deletedAt); + expect(dockerCalls).toContainEqual(["rm", "-f", "sandbox-id"]); + expect(fs.existsSync(servicePath)).toBe(false); + }); + + it("keeps the marked Linux unit when scoped OpenShell cleanup fails (#8220)", () => { + const test = fixture(true); + const servicePath = writeManagedService(test); + writeSelectedSandboxRegistry(test, "my-assistant"); + const calls: string[][] = []; + + const result = uninstall( + test, + false, + { + commandExists: (command) => command === "systemctl", + run: (command, args) => { + calls.push([command, ...args]); + return command === "openshell" && args[0] === "gateway" && args[1] === "select" + ? { status: 1, stdout: "", stderr: "no such gateway" } + : ok(); + }, + }, + [{ name: "nemoclaw" }, { name: "nemoclaw-8081" }], + ); + + // `openshell gateway select` failed, so uninstall refuses the sandbox + // deletion and returns before it disables the unit. A rerun needs the + // OpenShell gateway service still running. + expect(result.exitCode).toBe(1); + expect(fs.existsSync(servicePath)).toBe(true); + expect(calls.some((call) => call[0] === "systemctl" && call.includes("disable"))).toBe(false); + }); + it("removes only the marked Linux unit and managed env on full uninstall (#6903)", () => { const test = fixture(true); const servicePath = writeManagedService(test); diff --git a/src/lib/actions/uninstall/run-plan.ts b/src/lib/actions/uninstall/run-plan.ts index 39c75135374..a292305c066 100644 --- a/src/lib/actions/uninstall/run-plan.ts +++ b/src/lib/actions/uninstall/run-plan.ts @@ -970,6 +970,20 @@ function removeNemoclawOpenShellGatewayUserService(runtime: UninstallRuntime): b return true; } +// scripts/install.sh stages the NemoClaw-managed gateway user service only for +// the default gateway port, so an uninstall run for any other port leaves it in +// place. `--keep-openshell` and an externally supervised authority leave it in +// place too. +function removeManagedDefaultGatewayUserService( + runtime: UninstallRuntime, + options: UninstallRunOptions, + externallySupervised: boolean, +): boolean { + return options.keepOpenShell || externallySupervised || GATEWAY_PORT !== DEFAULT_GATEWAY_PORT + ? true + : removeNemoclawOpenShellGatewayUserService(runtime); +} + function removeNemoclawOpenShellGatewayEnv( paths: UninstallPaths, runtime: UninstallRuntime, @@ -1782,12 +1796,14 @@ function executePlan( if (!scopedToSelectedGateway && !removeManagedDistributedVllmRuntime(paths, runtime)) { return { ok: false }; } + // #8220: a gateway-scoped uninstall still needs the selected OpenShell + // gateway service running to delete its sandbox, so "OpenShell resources" + // removes that unit after the sandbox delete succeeds. if ( - !options.keepOpenShell && - !externallySupervised && - GATEWAY_PORT === DEFAULT_GATEWAY_PORT + !scopedToSelectedGateway && + !removeManagedDefaultGatewayUserService(runtime, options, externallySupervised) ) { - if (!removeNemoclawOpenShellGatewayUserService(runtime)) ok = false; + ok = false; } if (!scopedToSelectedGateway) { stopHelperServices(paths, runtime); @@ -1857,6 +1873,9 @@ function executePlan( return { ok: false }; } if (scopedToSelectedGateway && !options.keepOpenShell && !externallySupervised) { + if (!removeManagedDefaultGatewayUserService(runtime, options, externallySupervised)) { + ok = false; + } stopHostGatewayProcessesForUninstall(runtime, { gatewayBin: runtime.env.NEMOCLAW_OPENSHELL_GATEWAY_BIN, logNoProcesses: true, From 2356fa3cda623fd27c49310ed8265f8f9ad124ea Mon Sep 17 00:00:00 2001 From: harjoth Date: Tue, 4 Aug 2026 13:42:45 -0700 Subject: [PATCH 2/7] test(uninstall): cover the scoped sandbox-delete failure path (#8220) Signed-off-by: harjoth --- docs/manage-sandboxes/uninstall-nemoclaw.mdx | 2 +- docs/reference/commands.mdx | 2 +- .../uninstall/run-plan-gateway-service.test.ts | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/manage-sandboxes/uninstall-nemoclaw.mdx b/docs/manage-sandboxes/uninstall-nemoclaw.mdx index 76b055e62b4..0fabd40900f 100644 --- a/docs/manage-sandboxes/uninstall-nemoclaw.mdx +++ b/docs/manage-sandboxes/uninstall-nemoclaw.mdx @@ -73,7 +73,7 @@ It preserves upstream Linux package units, the macOS Homebrew service, and unrel Gateway-scoped cleanup removes that gateway's OpenShell resources first, then the marked Linux unit. The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. -Resolve the reported error, then rerun `$$nemoclaw uninstall`. +Resolve the reported error, inspect the remaining gateways with `openshell gateway list`, and rerun `$$nemoclaw uninstall`. For an externally supervised authority, uninstall preserves the local gateway state used by the running process in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. A custom-port uninstall does not stop or remove the default gateway service or its environment file. diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 3227b74ae29..5dc782db071 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3549,7 +3549,7 @@ It preserves upstream Linux package units, the macOS Homebrew service, and unrel Gateway-scoped cleanup removes that gateway's OpenShell resources first, then the marked Linux unit. The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. -Resolve the reported error, then rerun `$$nemoclaw uninstall`. +Resolve the reported error, inspect the remaining gateways with `openshell gateway list`, and rerun `$$nemoclaw uninstall`. For an externally supervised authority, uninstall preserves the selected local gateway state in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. A custom-port uninstall does not stop or remove the default gateway service or its environment file. diff --git a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts index 2c084e1f20c..62e41de7a7a 100644 --- a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts +++ b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts @@ -257,17 +257,18 @@ describe("uninstall OpenShell gateway user service", () => { commandExists: (command) => command === "systemctl", run: (command, args) => { calls.push([command, ...args]); - return command === "openshell" && args[0] === "gateway" && args[1] === "select" - ? { status: 1, stdout: "", stderr: "no such gateway" } + return command === "openshell" && args[0] === "sandbox" + ? { status: 1, stdout: "", stderr: "sandbox unreachable" } : ok(); }, }, [{ name: "nemoclaw" }, { name: "nemoclaw-8081" }], ); - // `openshell gateway select` failed, so uninstall refuses the sandbox - // deletion and returns before it disables the unit. A rerun needs the - // OpenShell gateway service still running. + // The sandbox delete failed, so uninstall returns before it disables the + // unit and a rerun still finds the OpenShell gateway service running. + // `openshell gateway remove` still runs ahead of that return; that is the + // pre-existing absent-resource behavior #7906 tracks, not this change. expect(result.exitCode).toBe(1); expect(fs.existsSync(servicePath)).toBe(true); expect(calls.some((call) => call[0] === "systemctl" && call.includes("disable"))).toBe(false); From 5e4c85ba4d6c7fbc4ba6820abfe1d6c1593847f7 Mon Sep 17 00:00:00 2001 From: harjoth Date: Tue, 4 Aug 2026 13:48:12 -0700 Subject: [PATCH 3/7] docs(uninstall): note partial completion before a scoped cleanup failure (#8220) Signed-off-by: harjoth --- docs/manage-sandboxes/uninstall-nemoclaw.mdx | 1 + docs/reference/commands.mdx | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/manage-sandboxes/uninstall-nemoclaw.mdx b/docs/manage-sandboxes/uninstall-nemoclaw.mdx index 0fabd40900f..3def49e15d7 100644 --- a/docs/manage-sandboxes/uninstall-nemoclaw.mdx +++ b/docs/manage-sandboxes/uninstall-nemoclaw.mdx @@ -73,6 +73,7 @@ It preserves upstream Linux package units, the macOS Homebrew service, and unrel Gateway-scoped cleanup removes that gateway's OpenShell resources first, then the marked Linux unit. The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. +That cleanup can partially complete before the failure. Resolve the reported error, inspect the remaining gateways with `openshell gateway list`, and rerun `$$nemoclaw uninstall`. For an externally supervised authority, uninstall preserves the local gateway state used by the running process in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 5dc782db071..e789dbac77f 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3549,6 +3549,7 @@ It preserves upstream Linux package units, the macOS Homebrew service, and unrel Gateway-scoped cleanup removes that gateway's OpenShell resources first, then the marked Linux unit. The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. +That cleanup can partially complete before the failure. Resolve the reported error, inspect the remaining gateways with `openshell gateway list`, and rerun `$$nemoclaw uninstall`. For an externally supervised authority, uninstall preserves the selected local gateway state in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. From bffbc084df7da188892780cb6ba0e60f94f9dfae Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Wed, 5 Aug 2026 01:25:09 -0700 Subject: [PATCH 4/7] test(uninstall): clarify scoped cleanup failure --- .../actions/uninstall/run-plan-gateway-service.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts index 62e41de7a7a..8ebc7d432ff 100644 --- a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts +++ b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts @@ -244,7 +244,7 @@ describe("uninstall OpenShell gateway user service", () => { expect(fs.existsSync(servicePath)).toBe(false); }); - it("keeps the marked Linux unit when scoped OpenShell cleanup fails (#8220)", () => { + it("preserves the marked Linux unit when scoped sandbox deletion fails (#8220)", () => { const test = fixture(true); const servicePath = writeManagedService(test); writeSelectedSandboxRegistry(test, "my-assistant"); @@ -265,10 +265,8 @@ describe("uninstall OpenShell gateway user service", () => { [{ name: "nemoclaw" }, { name: "nemoclaw-8081" }], ); - // The sandbox delete failed, so uninstall returns before it disables the - // unit and a rerun still finds the OpenShell gateway service running. - // `openshell gateway remove` still runs ahead of that return; that is the - // pre-existing absent-resource behavior #7906 tracks, not this change. + // Sandbox deletion failed, so uninstall returns before it removes the gateway registration. + // It preserves the marked Linux unit and the running OpenShell gateway service for a retry. expect(result.exitCode).toBe(1); expect(fs.existsSync(servicePath)).toBe(true); expect(calls.some((call) => call[0] === "systemctl" && call.includes("disable"))).toBe(false); From 4c44520960a2094d0a47c3e4ec61cfaa13e089c7 Mon Sep 17 00:00:00 2001 From: harjoth Date: Wed, 5 Aug 2026 09:38:43 -0700 Subject: [PATCH 5/7] test(uninstall): cover the scoped gateway-removal failure path (#8220) The scoped-uninstall regression covered only sandbox-delete failure. Add the second cleanup boundary: sandbox delete succeeds, gateway registration removal fails, and uninstall still returns before it removes the marked Linux unit. --- .../run-plan-gateway-service.test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts index a45c396228b..53b66b9549d 100644 --- a/src/lib/actions/uninstall/run-plan-gateway-service.test.ts +++ b/src/lib/actions/uninstall/run-plan-gateway-service.test.ts @@ -272,6 +272,35 @@ describe("uninstall OpenShell gateway user service", () => { expect(calls.some((call) => call[0] === "systemctl" && call.includes("disable"))).toBe(false); }); + it("preserves the marked Linux unit when scoped gateway registration removal fails (#8220)", () => { + const test = fixture(true); + const servicePath = writeManagedService(test); + writeSelectedSandboxRegistry(test, "my-assistant"); + const calls: string[][] = []; + + const result = uninstall( + test, + false, + { + commandExists: (command) => command === "systemctl", + run: (command, args) => { + calls.push([command, ...args]); + return command === "openshell" && args[0] === "gateway" && args[1] === "remove" + ? { status: 1, stdout: "", stderr: "gateway registration is busy" } + : ok(); + }, + }, + [{ name: "nemoclaw" }, { name: "nemoclaw-8081" }], + ); + + // Sandbox deletion succeeded, so this pins the second cleanup boundary: registration + // removal failed, and uninstall still returns before it removes the gateway service. + expect(calls).toContainEqual(["openshell", "sandbox", "delete", "my-assistant"]); + expect(result.exitCode).toBe(1); + expect(fs.existsSync(servicePath)).toBe(true); + expect(calls.some((call) => call[0] === "systemctl" && call.includes("disable"))).toBe(false); + }); + it("removes only the marked Linux unit and managed env on full uninstall (#6903)", () => { const test = fixture(true); const servicePath = writeManagedService(test); From cfc6ce2cda02b9eb7e0f635e92bd8ace3ff92d7f Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 5 Aug 2026 11:42:20 -0700 Subject: [PATCH 6/7] chore: resynchronize PR #8259 head Signed-off-by: Charan Jagwani From 43886757ee869638a1fa896339bd3be031b1d234 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Wed, 5 Aug 2026 12:01:35 -0700 Subject: [PATCH 7/7] docs(uninstall): preserve gateway port on retry Signed-off-by: Carlos Villela --- docs/manage-sandboxes/uninstall-nemoclaw.mdx | 4 +++- docs/reference/commands.mdx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/manage-sandboxes/uninstall-nemoclaw.mdx b/docs/manage-sandboxes/uninstall-nemoclaw.mdx index 7a8ac1bef79..aa0c4743575 100644 --- a/docs/manage-sandboxes/uninstall-nemoclaw.mdx +++ b/docs/manage-sandboxes/uninstall-nemoclaw.mdx @@ -74,7 +74,9 @@ Gateway-scoped cleanup removes that gateway's OpenShell resources first, then th The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. That cleanup can partially complete before the failure. -Resolve the reported error, inspect the remaining gateways with `openshell gateway list`, and rerun `$$nemoclaw uninstall`. +Resolve the reported error. +Inspect the remaining gateways with `openshell gateway list`. +Rerun `NEMOCLAW_GATEWAY_PORT= $$nemoclaw uninstall` with the gateway port from the failed uninstall. For an externally supervised authority, uninstall preserves the local gateway state used by the running process in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. A custom-port uninstall does not stop or remove the default gateway service or its environment file. diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index ca3c5976a37..e1a5aebfb5f 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -3658,7 +3658,9 @@ Gateway-scoped cleanup removes that gateway's OpenShell resources first, then th The OpenShell gateway service therefore keeps running while uninstall deletes the selected gateway's sandboxes. If that OpenShell cleanup fails, uninstall exits nonzero and preserves the marked Linux unit and the gateway process. That cleanup can partially complete before the failure. -Resolve the reported error, inspect the remaining gateways with `openshell gateway list`, and rerun `$$nemoclaw uninstall`. +Resolve the reported error. +Inspect the remaining gateways with `openshell gateway list`. +Rerun `NEMOCLAW_GATEWAY_PORT= $$nemoclaw uninstall` with the gateway port from the failed uninstall. For an externally supervised authority, uninstall preserves the selected local gateway state in both full and gateway-scoped cleanup. It also preserves the gateway process, supervisor resources, marked Linux unit, Docker resources, OpenShell binaries, and the declared external state directory. A custom-port uninstall does not stop or remove the default gateway service or its environment file.