fix: add error reporting and timeouts for Ollama external server connections#11470
fix: add error reporting and timeouts for Ollama external server connections#11470roomote[bot] wants to merge 1 commit intomainfrom
Conversation
…ections - Add 10s timeout to Ollama HTTP requests (prevents indefinite hangs) - Propagate connection errors with user-friendly messages instead of silently returning empty results - Always send response to webview (prevents silent timeout) - Display connection errors in Ollama settings UI - Handle error responses in useOllamaModels hook - Update and add tests for new error behavior Addresses #11466
Reviewed the error reporting and timeout changes across the Ollama fetcher, webview message handler, settings UI, and hook. The core approach is solid -- surfacing connection errors to users is a clear improvement over silent failures. Found 2 issues:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| </div> | ||
| </VSCodeTextField> | ||
| )} | ||
| {connectionError && <div className="text-sm text-vscode-errorForeground">{connectionError}</div>} |
There was a problem hiding this comment.
Duplicate error display: connectionError is rendered here as a standalone <div>, and also passed to ModelPicker via errorMessage={connectionError ?? modelNotAvailableError} on line 115. When there's a connection error, the user sees the same message twice -- once in this div and once inside ModelPicker's ApiErrorMessage. Consider removing this standalone div and relying solely on the ModelPicker prop, or vice versa.
Fix it with Roo Code or mention @roomote and request a fix.
| } catch (error: any) { | ||
| // Build a user-friendly error message based on the failure type | ||
| const code = error?.code | ||
| const status = error?.response?.status | ||
|
|
||
| if (code === "ECONNREFUSED") { | ||
| throw new Error(`Connection refused by Ollama at ${baseUrl}. Is the server running and accessible?`) | ||
| } else if (code === "ECONNABORTED" || code === "ETIMEDOUT" || error?.message?.includes("timeout")) { | ||
| throw new Error( | ||
| `Connection to Ollama at ${baseUrl} timed out after ${OLLAMA_REQUEST_TIMEOUT_MS / 1000}s. The server may be unreachable (check firewall settings).`, | ||
| ) | ||
| } else if (code === "ENOTFOUND") { | ||
| throw new Error(`Could not resolve hostname for Ollama at ${baseUrl}. Check the URL.`) | ||
| } else if (status) { | ||
| throw new Error(`Ollama at ${baseUrl} returned HTTP ${status}.`) | ||
| } else { | ||
| throw new Error(`Failed to connect to Ollama at ${baseUrl}: ${error?.message || String(error)}`) | ||
| } | ||
| } |
There was a problem hiding this comment.
The try block starting at line 85 encompasses both the /api/tags request and the Promise.all of individual /api/show calls. If /api/tags succeeds but a single model's /api/show call fails (e.g., times out on a large model), Promise.all rejects and this catch block produces a connection-level error like "Connection to Ollama at ... timed out" -- which is misleading since the server IS reachable. Consider wrapping individual /api/show calls with their own error handling (or using Promise.allSettled) so that one model's failure doesn't discard all successfully-fetched models and produce a false connection error.
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #11466
Description
This PR attempts to address Issue #11466 (Roo Code won't connect to external Ollama server). Feedback and guidance are welcome.
The core problem: when connecting to external Ollama servers fails, the extension silently swallows all errors, leaving users with no feedback about what went wrong. This makes it impossible to distinguish between a firewall issue, a misconfigured URL, or a code bug.
Key changes:
src/api/providers/fetchers/ollama.ts- Added 10-second timeout to axios HTTP requests (prevents indefinite hangs for unreachable servers). Changed error handling to throw descriptive errors instead of silently returning{}. Error messages are user-friendly and include the URL and failure type (ECONNREFUSED, timeout, ENOTFOUND, HTTP status, etc.).src/core/webview/webviewMessageHandler.ts- TherequestOllamaModelshandler now always sends a response to the webview (even on error or empty results). Previously it silently dropped empty responses, causing the webview to just timeout. Error messages are forwarded to the webview via the existingerrorfield onExtensionMessage.webview-ui/src/components/settings/providers/Ollama.tsx- AddedconnectionErrorstate that surfaces backend error messages. Displays a visible error banner and passes the error to the ModelPicker'serrorMessageprop.webview-ui/src/components/ui/hooks/useOllamaModels.ts- Updated to handle error responses from the backend (rejects with the server's error message). Increased timeout from 10s to 15s to allow the backend's 10s timeout to complete first.Test Procedure
cd src && npx vitest run api/providers/fetchers/__tests__/ollama.test.ts(16 tests pass)cd src && npx vitest run core/webview/__tests__/webviewMessageHandler.spec.ts(24 tests pass)Manual testing steps:
http://10.3.4.5:11434)Pre-Submission Checklist
Documentation Updates
Additional Notes
This PR focuses on error visibility rather than fixing the underlying network connectivity issue (which may vary by user environment -- firewalls, Ollama bind address config, etc.). By surfacing clear error messages, users can now self-diagnose whether the issue is network-related (e.g., "Connection refused" or "timed out -- check firewall settings") or configuration-related.