Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions src/lib/onboard/local-inference-topology.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ vi.mock("../inference/local", () => ({
applyOllamaRuntimeContextWindow: vi.fn(),
findReachableOllamaHost: vi.fn(),
isLocalProviderHostHealthy: vi.fn(),
OLLAMA_LOCALHOST: "127.0.0.1",
validateOllamaModel: vi.fn(),
}));
vi.mock("../inference/ollama/proxy", () => ({
Expand Down Expand Up @@ -164,7 +165,9 @@ describe("repairLocalInferenceSystemdOverrideOrExit (#6760)", () => {
expect(mockedApplyRuntimeContext).toHaveBeenCalledWith(recordedModel, {
contextWindowFloor: MIN_HERMES_OLLAMA_CONTEXT_WINDOW,
});
expect(callOrder).toEqual(["systemd", "host", "warm", "runtime-context"]);
// The topology probe runs first so a Windows-host daemon can skip the
// override; the post-override probe still proves the restarted daemon (#8596).
expect(callOrder).toEqual(["host", "systemd", "host", "warm", "runtime-context"]);
});

it("preserves the legacy OpenClaw loopback-only repair", () => {
Expand All @@ -179,11 +182,49 @@ describe("repairLocalInferenceSystemdOverrideOrExit (#6760)", () => {
isNonInteractive,
contextWindowFloor: MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW,
});
expect(mockedFindReachableHost).not.toHaveBeenCalled();
expect(mockedFindReachableHost).toHaveBeenCalledTimes(1);
expect(mockedValidateModel).not.toHaveBeenCalled();
expect(mockedApplyRuntimeContext).not.toHaveBeenCalled();
});

it("skips the Linux systemd loopback override for a Windows-host Ollama daemon on resume (#8596)", () => {
mockedFindReachableHost.mockReturnValue("host.docker.internal");

repairHermesResume();

expect(mockedEnsureSystemdOverride).not.toHaveBeenCalled();
expect(mockedValidateModel).toHaveBeenCalledWith(recordedModel);
expect(mockedApplyRuntimeContext).toHaveBeenCalledWith(recordedModel, {
contextWindowFloor: MIN_HERMES_OLLAMA_CONTEXT_WINDOW,
});
});

it("still applies the override on resume when a loopback Ollama answers (#8596)", () => {
mockedFindReachableHost.mockReturnValue("127.0.0.1");

repairHermesResume();

expect(mockedEnsureSystemdOverride).toHaveBeenCalledWith({
isNonInteractive,
contextWindowFloor: MIN_HERMES_OLLAMA_CONTEXT_WINDOW,
});
});

it("still applies the override on resume when no Ollama daemon answers (#8596)", () => {
mockedFindReachableHost.mockReturnValue(null);
mockedEnsureSystemdOverride.mockReturnValue("ready");

expectFailure(
repairHermesResume,
"Ollama is not reachable, so the recorded model's runtime context window cannot be verified.",
);

expect(mockedEnsureSystemdOverride).toHaveBeenCalledWith({
isNonInteractive,
contextWindowFloor: MIN_HERMES_OLLAMA_CONTEXT_WINDOW,
});
});

it("rejects a strict resume when the recorded model is missing", () => {
expectFailure(
() =>
Expand All @@ -195,7 +236,7 @@ describe("repairLocalInferenceSystemdOverrideOrExit (#6760)", () => {
}),
"The recorded Ollama model is missing, so its runtime context window cannot be verified.",
);
expect(mockedFindReachableHost).not.toHaveBeenCalled();
expect(mockedFindReachableHost).toHaveBeenCalledTimes(1);
});

it("rejects a strict resume when Ollama is unreachable", () => {
Expand Down
26 changes: 21 additions & 5 deletions src/lib/onboard/local-inference-topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
applyOllamaRuntimeContextWindow,
findReachableOllamaHost,
isLocalProviderHostHealthy,
OLLAMA_LOCALHOST,
validateOllamaModel,
} from "../inference/local";
import { ensureOllamaAuthProxy, isProxyHealthy } from "../inference/ollama/proxy";
Expand Down Expand Up @@ -163,6 +164,14 @@ function failOllamaResumeRepair(message: string): never {
throw new Error(message);
}

// True when Ollama answers on a non-loopback host, which on WSL means the
// Windows-host daemon reached through host.docker.internal. Mirrors the
// loopback check the model-list path already applies in inference/local.
function respondingOllamaIsWindowsHost(): boolean {
const host = findReachableOllamaHost();
return host !== null && host !== OLLAMA_LOCALHOST;
}

// Repair the Ollama systemd loopback override for recorded ollama-local
// providers. Agents with a strict context floor also warm the exact recorded
// model and verify the running daemon before resume can skip provider setup.
Expand All @@ -173,11 +182,18 @@ export function repairLocalInferenceSystemdOverrideOrExit(
const { provider, model, isNonInteractive } = options;
if (provider !== "ollama-local") return;
const contextWindowFloor = resolveOllamaContextWindowFloor(options.contextWindowFloor);
const state = ensureOllamaLoopbackSystemdOverride({ isNonInteractive, contextWindowFloor });
if (state === "failed") {
failOllamaResumeRepair(
"Ollama systemd restart did not recover after applying the loopback override.",
);
// A Windows-host Ollama daemon reached at host.docker.internal is not a Linux
// systemd service, so the override restarts an unrelated ollama.service and
// exits 1. Provider selection already skips it, but it records the same
// "ollama-local" provider for both topologies, so resume carries no Windows
// marker and has to re-derive the distinction here (#8596).
if (!respondingOllamaIsWindowsHost()) {
const state = ensureOllamaLoopbackSystemdOverride({ isNonInteractive, contextWindowFloor });
if (state === "failed") {
failOllamaResumeRepair(
"Ollama systemd restart did not recover after applying the loopback override.",
);
}
}
if (contextWindowFloor <= MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW) return;
if (!model) {
Expand Down
Loading