fix(ollama): address Rooviewer feedback - double API calls and silent failures

- Change flushModels(options, true) to flushModels(options, false) in both
  requestOllamaModels and refreshOllamaModels handlers to avoid redundant
  /api/tags + /api/show calls (discoverOllamaModelsWithSorting already
  performs the full discovery)
- Always send ollamaModels message to the UI regardless of totalCount,
  so the UI clears stale state when no models are found
- Update test expectation for flushModels(_, false)
This commit is contained in:
Roo Code 2026-02-21 07:13:11 +00:00
parent 609fbac98e
commit 6d14eecce3
2 changed files with 18 additions and 19 deletions

View file

@ -252,7 +252,7 @@ describe("webviewMessageHandler - requestOllamaModels", () => {
type: "requestOllamaModels",
})
expect(mockFlushModels).toHaveBeenCalledWith({ provider: "ollama", baseUrl: "http://localhost:1234" }, true)
expect(mockFlushModels).toHaveBeenCalledWith({ provider: "ollama", baseUrl: "http://localhost:1234" }, false)
expect(mockDiscoverOllamaModels).toHaveBeenCalledWith(
"http://localhost:1234",
undefined,

View file

@ -990,7 +990,7 @@ export const webviewMessageHandler = async (
baseUrl: ollamaApiConfig.ollamaBaseUrl,
apiKey: ollamaApiConfig.ollamaApiKey,
}
await flushModels(ollamaOptions, true)
await flushModels(ollamaOptions, false)
const result = await discoverOllamaModelsWithSorting(
ollamaApiConfig.ollamaBaseUrl,
@ -1009,15 +1009,13 @@ export const webviewMessageHandler = async (
modelsWithToolsRecord[model.name] = model.modelInfo
}
// Always send the models message if we have any results
if (result.totalCount > 0) {
provider.postMessageToWebview({
type: "ollamaModels",
ollamaModels: modelsWithToolsRecord,
ollamaModelsWithTools: result.modelsWithTools,
modelsWithoutTools: result.modelsWithoutTools,
})
}
// Always send the models message so the UI reflects current state
provider.postMessageToWebview({
type: "ollamaModels",
ollamaModels: modelsWithToolsRecord,
ollamaModelsWithTools: result.modelsWithTools,
modelsWithoutTools: result.modelsWithoutTools,
})
} catch (error) {
console.debug("Ollama models fetch failed:", error)
}
@ -1075,7 +1073,7 @@ export const webviewMessageHandler = async (
ollamaEnableLogging: ollamaApiConfig.ollamaEnableLogging,
}
await flushModels(ollamaOptions, true)
await flushModels(ollamaOptions, false)
const result = await discoverOllamaModelsWithSorting(baseUrl, apiKey, {
modelDiscoveryTimeout: ollamaApiConfig.ollamaModelDiscoveryTimeout,
@ -1104,14 +1102,15 @@ export const webviewMessageHandler = async (
})
}
// Always send the models message if we have any results
// Always send the models message so the UI reflects current state
provider.postMessageToWebview({
type: "ollamaModels",
ollamaModels: modelsWithToolsRecord,
ollamaModelsWithTools: result.modelsWithTools,
modelsWithoutTools: result.modelsWithoutTools,
})
if (result.totalCount > 0) {
provider.postMessageToWebview({
type: "ollamaModels",
ollamaModels: modelsWithToolsRecord,
ollamaModelsWithTools: result.modelsWithTools,
modelsWithoutTools: result.modelsWithoutTools,
})
provider.postMessageToWebview({
type: "ollamaModelsRefreshResult",
success: true,