diff --git a/bin/lib/onboard.js b/bin/lib/onboard.js index 252a303c8..30a5e889a 100644 --- a/bin/lib/onboard.js +++ b/bin/lib/onboard.js @@ -363,6 +363,9 @@ async function preflight() { console.log(" Cleaning up previous NemoClaw session..."); run("openshell forward stop 18789 2>/dev/null || true", { ignoreError: true }); run("openshell gateway destroy -g nemoclaw 2>/dev/null || true", { ignoreError: true }); + // Sandboxes under the destroyed gateway no longer exist in OpenShell — + // clear the local registry so `nemoclaw list` stays consistent. (#532) + registry.clearAll(); console.log(" ✓ Previous session cleaned up"); } @@ -420,8 +423,9 @@ async function preflight() { async function startGateway(gpu) { step(2, 7, "Starting OpenShell gateway"); - // Destroy old gateway + // Destroy old gateway — also clear registry since its sandboxes are gone. (#532) run("openshell gateway destroy -g nemoclaw 2>/dev/null || true", { ignoreError: true }); + registry.clearAll(); const gwArgs = ["--name", "nemoclaw"]; // Do NOT pass --gpu here. On DGX Spark (and most GPU hosts), inference is diff --git a/bin/lib/registry.js b/bin/lib/registry.js index c42a44fdf..f5ea54c86 100644 --- a/bin/lib/registry.js +++ b/bin/lib/registry.js @@ -91,7 +91,12 @@ function setDefault(name) { return true; } +function clearAll() { + save({ sandboxes: {}, defaultSandbox: null }); +} + module.exports = { + clearAll, load, save, getSandbox, diff --git a/test/registry.test.js b/test/registry.test.js index 0f471b0be..80bc10e79 100644 --- a/test/registry.test.js +++ b/test/registry.test.js @@ -102,4 +102,29 @@ describe("registry", () => { const { sandboxes } = registry.listSandboxes(); assert.equal(sandboxes.length, 0); }); + + it("clearAll removes all sandboxes and resets default", () => { + registry.registerSandbox({ name: "alpha" }); + registry.registerSandbox({ name: "beta" }); + registry.setDefault("beta"); + registry.clearAll(); + const { sandboxes, defaultSandbox } = registry.listSandboxes(); + assert.equal(sandboxes.length, 0); + assert.equal(defaultSandbox, null); + }); + + it("clearAll persists empty state to disk", () => { + registry.registerSandbox({ name: "persist-me" }); + registry.clearAll(); + const data = JSON.parse(fs.readFileSync(regFile, "utf-8")); + assert.deepEqual(data.sandboxes, {}); + assert.equal(data.defaultSandbox, null); + }); + + it("clearAll is safe to call on empty registry", () => { + registry.clearAll(); + const { sandboxes, defaultSandbox } = registry.listSandboxes(); + assert.equal(sandboxes.length, 0); + assert.equal(defaultSandbox, null); + }); });