fix(cli): ignore stale memory cleanup after package update

This commit is contained in:
Vincent Koc
2026-04-28 21:09:16 -07:00
parent be445dd1c1
commit 09cb0b0e64
2 changed files with 17 additions and 5 deletions

View File

@@ -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 });

View File

@@ -191,15 +191,16 @@ async function tryRunGatewayRunFastPath(
}
async function closeCliMemoryManagers(): Promise<void> {
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.
}
}