mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(llama-cpp): keep failed cleanup terminal
This commit is contained in:
@@ -947,17 +947,15 @@ describe("llama.cpp inference provider", () => {
|
||||
mocks.contextDispose.mockRejectedValueOnce(new Error("context cleanup failed"));
|
||||
|
||||
const firstDisposal = inferenceRuntime.dispose();
|
||||
await expect(firstDisposal).rejects.toThrow(
|
||||
"llama.cpp runtime cleanup failed: Error: context cleanup failed",
|
||||
);
|
||||
expect(mocks.modelDispose).toHaveBeenCalledOnce();
|
||||
expect(mocks.llamaDispose).toHaveBeenCalledOnce();
|
||||
await expect(firstDisposal).rejects.toThrow("context cleanup failed");
|
||||
expect(mocks.modelDispose).not.toHaveBeenCalled();
|
||||
expect(mocks.llamaDispose).not.toHaveBeenCalled();
|
||||
const repeatedDisposal = inferenceRuntime.dispose();
|
||||
expect(repeatedDisposal).toBe(firstDisposal);
|
||||
await expect(repeatedDisposal).rejects.toThrow("context cleanup failed");
|
||||
expect(mocks.contextDispose).toHaveBeenCalledOnce();
|
||||
expect(mocks.modelDispose).toHaveBeenCalledOnce();
|
||||
expect(mocks.llamaDispose).toHaveBeenCalledOnce();
|
||||
expect(mocks.modelDispose).not.toHaveBeenCalled();
|
||||
expect(mocks.llamaDispose).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -312,32 +312,14 @@ function disposeLlamaCppInferenceRuntime(state: LlamaCppInferenceRuntimeState):
|
||||
// Plugin services stop once, and node-llama-cpp disposers mark themselves
|
||||
// disposed before awaiting cleanup. The first disposal attempt is authoritative.
|
||||
state.disposePromise = serialize(state, async () => {
|
||||
const errors: unknown[] = [];
|
||||
const attemptDispose = async (dispose: () => Promise<void>) => {
|
||||
try {
|
||||
await dispose();
|
||||
} catch (error) {
|
||||
errors.push(error);
|
||||
}
|
||||
};
|
||||
if (state.loadedModel) {
|
||||
const previous = state.loadedModel;
|
||||
await attemptDispose(() => previous.context.dispose());
|
||||
await attemptDispose(() => previous.model.dispose());
|
||||
if (state.loadedModel === previous) {
|
||||
state.loadedModel = undefined;
|
||||
}
|
||||
}
|
||||
await disposeLoadedModel(state);
|
||||
if (state.llamaInstance) {
|
||||
const previous = state.llamaInstance;
|
||||
await attemptDispose(() => previous.dispose());
|
||||
await previous.dispose();
|
||||
if (state.llamaInstance === previous) {
|
||||
state.llamaInstance = undefined;
|
||||
}
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
throw new AggregateError(errors, `llama.cpp runtime cleanup failed: ${String(errors[0])}`);
|
||||
}
|
||||
}).finally(() => {
|
||||
state.lifecycle = "closed";
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user