Skip to content

fix: add error reporting and timeouts for Ollama external server connections#11470

Draft
roomote[bot] wants to merge 1 commit intomainfrom
fix/ollama-external-server-error-reporting
Draft

fix: add error reporting and timeouts for Ollama external server connections#11470
roomote[bot] wants to merge 1 commit intomainfrom
fix/ollama-external-server-error-reporting

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Feb 13, 2026

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:

  1. 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.).

  2. src/core/webview/webviewMessageHandler.ts - The requestOllamaModels handler 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 existing error field on ExtensionMessage.

  3. webview-ui/src/components/settings/providers/Ollama.tsx - Added connectionError state that surfaces backend error messages. Displays a visible error banner and passes the error to the ModelPicker's errorMessage prop.

  4. 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

  • Updated existing tests and added new ones for error scenarios
  • Run: cd src && npx vitest run api/providers/fetchers/__tests__/ollama.test.ts (16 tests pass)
  • Run: cd src && npx vitest run core/webview/__tests__/webviewMessageHandler.spec.ts (24 tests pass)
  • New test cases: ECONNREFUSED, ENOTFOUND, timeout, invalid URL, empty response handling, error message propagation

Manual testing steps:

  1. Configure Ollama provider with an unreachable external URL (e.g., http://10.3.4.5:11434)
  2. Verify that a clear error message is shown (e.g., "Connection to Ollama at http://10.3.4.5:11434 timed out after 10s")
  3. Configure with a reachable Ollama server and verify models load normally

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

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.

…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
@roomote
Copy link
Contributor Author

roomote bot commented Feb 13, 2026

Rooviewer Clock   See task

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:

  • Duplicate error display in Ollama.tsx -- connectionError is shown both as a standalone <div> and via the ModelPicker's errorMessage prop, resulting in the same message appearing twice in the UI.
  • Broad try-catch scope in ollama.ts -- The catch block covers both /api/tags and individual /api/show calls. If /api/tags succeeds but a single model's /api/show fails, the user gets a misleading connection-level error (e.g., "timed out") when the server is actually reachable.

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>}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +118 to 136
} 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)}`)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roo Code won't connect to external Ollama server (Reopening #6589)

1 participant