fix(llama-cpp): record native shutdown failures

This commit is contained in:
Vincent Koc
2026-08-05 02:25:52 +08:00
parent ce229353f3
commit 865b517235
2 changed files with 17 additions and 12 deletions
@@ -950,17 +950,17 @@ describe("llama.cpp inference provider", () => {
expectDisposeCalls(1, 1, 1);
});
it("keeps a failed cleanup terminal", async () => {
it("keeps a failed native runtime cleanup terminal", async () => {
await collectTestEvents();
mocks.contextDispose.mockRejectedValueOnce(new Error("context cleanup failed"));
mocks.llamaDispose.mockRejectedValueOnce(new Error("llama cleanup failed"));
const firstDisposal = inferenceRuntime.dispose();
await expect(firstDisposal).rejects.toThrow("context cleanup failed");
expectDisposeCalls(1, 0, 0);
const repeatedDisposal = inferenceRuntime.dispose();
expect(repeatedDisposal).toBe(firstDisposal);
await expect(repeatedDisposal).rejects.toThrow("context cleanup failed");
expectDisposeCalls(1, 0, 0);
await expect(firstDisposal).rejects.toThrow("llama cleanup failed");
expectDisposeCalls(1, 1, 1);
const unavailable = await createTestStream({ prompt: "after failed stop" });
await expect(unavailable.result()).resolves.toMatchObject({
errorMessage: expect.stringContaining("openclaw gateway restart"),
});
expect(inferenceRuntime.dispose()).toBe(firstDisposal);
});
it.each([
@@ -356,9 +356,14 @@ function disposeLlamaCppInferenceRuntime(state: LlamaCppInferenceRuntimeState):
state.llamaInstance = undefined;
}
}
}).finally(() => {
state.lifecycle = "closed";
});
})
.catch((error) => {
recordCleanupFailure(state, error);
throw error;
})
.finally(() => {
state.lifecycle = "closed";
});
return state.disposePromise;
}