fix: doctor false API key warning for ollama memory search provider (#46584)

This commit is contained in:
Yuhan Lei 2026-03-15 12:47:22 +08:00
parent 82e3ac21ee
commit 55a18bc598
2 changed files with 73 additions and 0 deletions

View File

@ -290,6 +290,57 @@ describe("noteMemorySearchHealth", () => {
const providersChecked = providerCalls.map(([arg]) => arg.provider);
expect(providersChecked).toEqual(["openai", "google", "voyage", "mistral"]);
});
it("does not warn when ollama provider is set and gateway probe is ready", async () => {
resolveMemorySearchConfig.mockReturnValue({
provider: "ollama",
local: {},
remote: {},
});
await noteMemorySearchHealth(cfg, {
gatewayMemoryProbe: { checked: true, ready: true },
});
expect(note).not.toHaveBeenCalled();
});
it("shows informational note when ollama provider is set and gateway probe is not ready", async () => {
resolveMemorySearchConfig.mockReturnValue({
provider: "ollama",
local: {},
remote: {},
});
await noteMemorySearchHealth(cfg, {
gatewayMemoryProbe: { checked: true, ready: false, error: "connection refused" },
});
expect(note).toHaveBeenCalledTimes(1);
const message = String(note.mock.calls[0]?.[0] ?? "");
expect(message).toContain("ollama");
expect(message).toContain("does not require an API key");
expect(message).toContain("connection refused");
expect(message).not.toContain("API key was not found");
expect(note.mock.calls[0]?.[1]).toBe("Memory search");
});
it("shows informational note when ollama provider is set and no gateway probe", async () => {
resolveMemorySearchConfig.mockReturnValue({
provider: "ollama",
local: {},
remote: {},
});
await noteMemorySearchHealth(cfg);
expect(note).toHaveBeenCalledTimes(1);
const message = String(note.mock.calls[0]?.[0] ?? "");
expect(message).toContain("ollama");
expect(message).toContain("does not require an API key");
expect(message).not.toContain("API key was not found");
expect(note.mock.calls[0]?.[1]).toBe("Memory search");
});
});
describe("detectLegacyWorkspaceDirs", () => {

View File

@ -79,6 +79,28 @@ export async function noteMemorySearchHealth(
);
return;
}
if (resolved.provider === "ollama") {
// Ollama runs locally and does not require an API key.
// If a gateway probe confirmed embeddings are ready, all good.
if (opts?.gatewayMemoryProbe?.checked && opts.gatewayMemoryProbe.ready) {
return;
}
// No probe or probe not ready — nudge the user to verify the service.
const detail = opts?.gatewayMemoryProbe?.error?.trim();
note(
[
'Memory search provider is set to "ollama".',
"Ollama does not require an API key, but the ollama service must be running.",
detail ? `Gateway probe: ${detail}` : null,
"",
`Verify: ${formatCliCommand("openclaw memory status --deep")}`,
]
.filter(Boolean)
.join("\n"),
"Memory search",
);
return;
}
// Remote provider — check for API key
if (hasRemoteApiKey || (await hasApiKeyForProvider(resolved.provider, cfg, agentDir))) {
return;