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

This commit is contained in:
Yuhan Lei 2026-03-15 12:54:49 +08:00
parent 55a18bc598
commit 960b567f53
2 changed files with 20 additions and 25 deletions

View File

@ -320,12 +320,12 @@ describe("noteMemorySearchHealth", () => {
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).toContain("Gateway probe: 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 () => {
it("does not warn when ollama provider is set and no gateway probe is available", async () => {
resolveMemorySearchConfig.mockReturnValue({
provider: "ollama",
local: {},
@ -334,12 +334,7 @@ describe("noteMemorySearchHealth", () => {
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");
expect(note).not.toHaveBeenCalled();
});
});

View File

@ -81,24 +81,24 @@ export async function noteMemorySearchHealth(
}
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;
// Only warn when the gateway probe explicitly reports not-ready;
// if no probe ran we cannot tell whether the service is up, so
// stay silent (consistent with the "local" branch above).
if (opts?.gatewayMemoryProbe?.checked && !opts.gatewayMemoryProbe.ready) {
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",
);
}
// 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