From 93dd87a67c876358d42ef399a083d86baf3dc5a0 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Sun, 31 May 2026 07:37:38 -0700 Subject: [PATCH] fix(status): preserve registry on missing live sandbox Signed-off-by: Aaron Erickson --- src/lib/actions/sandbox/status.ts | 52 +++++++++++------------ test/cli.test.ts | 13 +++--- test/gateway-state-reconcile-2276.test.ts | 18 ++++---- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/lib/actions/sandbox/status.ts b/src/lib/actions/sandbox/status.ts index 0f90d107d70..775533d7f9b 100644 --- a/src/lib/actions/sandbox/status.ts +++ b/src/lib/actions/sandbox/status.ts @@ -14,7 +14,6 @@ import { import * as agentRuntime from "../../agent/runtime"; import { CLI_DISPLAY_NAME, CLI_NAME } from "../../cli/branding"; import { D, G, R, RD, YW } from "../../cli/terminal-style"; -import { getNamedGatewayLifecycleState } from "../../gateway-runtime-action"; import { parseGatewayInference } from "../../inference/config"; import { type ProviderHealthProbeOptions, @@ -25,8 +24,6 @@ import * as nim from "../../inference/nim"; import * as sandboxVersion from "../../sandbox/version"; import * as shields from "../../shields"; import { parseSandboxPhase } from "../../state/gateway"; -import type { Session } from "../../state/onboard-session"; -import * as onboardSession from "../../state/onboard-session"; import * as registry from "../../state/registry"; import { createSystemDeps as createSessionDeps, @@ -239,6 +236,29 @@ async function printGatewayFailureLayerHeader(sandboxName: string): Promise { // #2666: never let an unexpected throw from the gateway probe (e.g. openshell @@ -360,31 +380,7 @@ export async function showSandboxStatus(sandboxName: string): Promise { console.log(lookup.output); process.exit(1); } else if (lookup.state === "missing") { - // Belt-and-suspenders: only destroy registry state if the nemoclaw gateway - // is demonstrably the healthy active gateway. Guards against regressions - // in the reconciler. - const guard = getNamedGatewayLifecycleState(); - if (guard.state !== "healthy_named") { - console.log(""); - if (guard.state === "connected_other") { - printWrongGatewayActiveGuidance(sandboxName, guard.activeGateway, console.log); - } else { - await printGatewayFailureLayerHeader(sandboxName); - printGatewayLifecycleHint(guard.status || "", sandboxName, console.log); - } - } else { - registry.removeSandbox(sandboxName); - const session = onboardSession.loadSession(); - if (session && session.sandboxName === sandboxName) { - onboardSession.updateSession((s: Session) => { - s.sandboxName = null; - return s; - }); - } - console.log(""); - console.log(` Sandbox '${sandboxName}' is not present in the live OpenShell gateway.`); - console.log(" Removed stale local registry entry."); - } + printMissingLiveSandboxStatusGuidance(sandboxName, lookup); process.exit(1); } else if (lookup.state === "identity_drift") { console.log(""); diff --git a/test/cli.test.ts b/test/cli.test.ts index 84e4d76e0c5..20b6c8e243d 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -6063,7 +6063,7 @@ describe("CLI dispatch", () => { testTimeout(10_000), ); - it("auto-cleans an orphan registry entry on status when the named gateway is healthy", () => { + it("preserves an orphan registry entry on passive status when the named gateway is healthy", () => { const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-cli-status-orphan-")); const localBin = path.join(home, "bin"); const registryDir = path.join(home, ".nemoclaw"); @@ -6117,12 +6117,15 @@ describe("CLI dispatch", () => { expect(statusResult.code).toBe(1); expect(statusResult.out).not.toContain("Inference: healthy"); - expect(statusResult.out).toContain("is not present in the live OpenShell gateway"); - expect(statusResult.out).toContain("Removed stale local registry entry"); + expect(statusResult.out).toContain( + "registered locally, but is not present in the live OpenShell gateway", + ); + expect(statusResult.out).toContain("No local registry entry was removed"); + expect(statusResult.out).not.toContain("Removed stale local registry entry"); const saved = JSON.parse(fs.readFileSync(path.join(registryDir, "sandboxes.json"), "utf8")); - expect(saved.sandboxes.alpha).toBeUndefined(); - expect(saved.defaultSandbox).toBeNull(); + expect(saved.sandboxes.alpha).toBeDefined(); + expect(saved.defaultSandbox).toBe("alpha"); }); }); diff --git a/test/gateway-state-reconcile-2276.test.ts b/test/gateway-state-reconcile-2276.test.ts index 5ebd16c4f9d..133544fb862 100644 --- a/test/gateway-state-reconcile-2276.test.ts +++ b/test/gateway-state-reconcile-2276.test.ts @@ -315,10 +315,10 @@ describe("Scenario 1: connect — healthy nemoclaw active + sandbox NotFound tru }); }); -// ─── Scenario 2 ─── destructive path preserved for `status` ──────────────── +// ─── Scenario 2 ─── passive `status` must preserve registry state ───────── describe("Scenario 2: status — healthy nemoclaw active + sandbox NotFound truly gone", () => { it( - "removes the registry entry, clears session, and logs removal (no exit 1)", + "reports the missing live sandbox without removing local registry state", { timeout: TIMEOUT_MS }, () => { writeStubOpenshell({ @@ -331,18 +331,16 @@ describe("Scenario 2: status — healthy nemoclaw active + sandbox NotFound trul const r = runCli("status"); - // status doesn't exit non-zero on a missing sandbox — it just logs. + assert.equal(r.status, 1, `expected exit 1, got ${r.status}`); assert.equal( registrySandboxPresent(r), - false, - `expected registry entry removed, got: ${JSON.stringify(r.registry)}`, - ); - assert.equal( - r.sessionSandboxName === null || r.sessionSandboxName === undefined, true, - `expected session sandboxName cleared, got: ${r.sessionSandboxName}`, + `expected registry entry preserved, got: ${JSON.stringify(r.registry)}`, ); - assert.match(r.stdout, /Removed stale local registry entry/); + assert.equal(r.sessionSandboxName, SANDBOX_NAME, "expected session sandboxName preserved"); + assert.match(r.stdout, /registered locally, but is not present/); + assert.match(r.stdout, /No local registry entry was removed/); + assert.doesNotMatch(r.stdout, /Removed stale local registry entry/); }, ); });