diff --git a/src/cli/run-main.exit.test.ts b/src/cli/run-main.exit.test.ts index 696627f9305..a3fdb1d3761 100644 --- a/src/cli/run-main.exit.test.ts +++ b/src/cli/run-main.exit.test.ts @@ -545,6 +545,17 @@ describe("runCli exit behavior", () => { expect(closeActiveMemorySearchManagersMock).toHaveBeenCalledTimes(1); }); + it("does not fail the command when memory cleanup is unavailable", async () => { + tryRouteCliMock.mockResolvedValueOnce(true); + hasMemoryRuntimeMock.mockImplementationOnce(() => { + throw new Error("stale memory-state chunk"); + }); + + await expect(runCli(["node", "openclaw", "status"])).resolves.toBeUndefined(); + + expect(closeActiveMemorySearchManagersMock).not.toHaveBeenCalled(); + }); + it("returns after a handled container-target invocation", async () => { maybeRunCliInContainerMock.mockReturnValueOnce({ handled: true, exitCode: 0 }); diff --git a/src/cli/run-main.ts b/src/cli/run-main.ts index 39279462125..d4a292e2ceb 100644 --- a/src/cli/run-main.ts +++ b/src/cli/run-main.ts @@ -191,15 +191,16 @@ async function tryRunGatewayRunFastPath( } async function closeCliMemoryManagers(): Promise { - const { hasMemoryRuntime } = await import("../plugins/memory-state.js"); - if (!hasMemoryRuntime()) { - return; - } try { + const { hasMemoryRuntime } = await import("../plugins/memory-state.js"); + if (!hasMemoryRuntime()) { + return; + } const { closeActiveMemorySearchManagers } = await import("../plugins/memory-runtime.js"); await closeActiveMemorySearchManagers(); } catch { - // Best-effort teardown for short-lived CLI processes. + // Best-effort teardown for short-lived CLI processes. Package updates can + // replace hashed chunks before this finalizer runs. } }