Skip to content

Conversation

@randomizedcoder
Copy link

@randomizedcoder randomizedcoder commented Jan 25, 2026

feat(ollama): add tools support filtering, configurable timeouts, and improved UI

Features added
image

Connection settings
image

Works when squished
image

Test Base URL
image

Refresh models
image

Related GitHub Issue

Closes: #10795
#10795

Description

This PR addresses issue #10795 by adding a "Refresh Models" button and significantly enhancing the Ollama provider integration.

The video for this pull request is (updated) : https://youtu.be/IqmIjSklBe8

The changes include:

Key Implementation Details:

  1. Enhanced Model Discovery (discoverOllamaModelsWithSorting)

    • Single-pass discovery: One /api/tags call followed by parallel /api/show calls for all models
    • Automatic sorting into "Tools Support" and "No Tools Support" groups based on capabilities.includes("tools")
    • Robust null/undefined handling for model_info fields (fixes Object.keys(null) errors)
    • Graceful partial failure handling - if some model detail calls fail, others still succeed
  2. Axios Configuration (createOllamaAxiosInstance)

    • Centralized Axios instance creation with configurable timeouts, retries, and logging
    • Retry logic with exponential backoff (configurable retries and delay)
    • Request/response interceptors for detailed logging when enabled
    • Proper timeout error handling (ECONNABORTED, ETIMEDOUT)
  3. UI Redesign

    • Tools Support Table: Structured table display with Model Name (radio selection), Context, Size (GB/MB), Quantization, Family, and Images support
    • No Tools Support Section: Informational list of models that don't support native tool calling
    • Connection Testing: "Test" button validates Base URL with timing information
    • Model Refresh: "Refresh Models" button forces model list update with completion time (solves [BUG] Force update the ollama models? #10795)
    • Connection Settings: Collapsible section with configurable timeouts, retries, and logging
  4. Type System Extensions

    • Added OllamaModelWithTools interface for table display data
    • Added OllamaModelsDiscoveryResult interface for discovery results
    • Extended ProviderSettings with new configuration options:
      • ollamaRequestTimeout (default: 60 min, max: 120 min)
      • ollamaModelDiscoveryTimeout (default: 10 sec, max: 10 min)
      • ollamaMaxRetries (default: 0, max: 10)
      • ollamaRetryDelay (default: 1 sec)
      • ollamaEnableLogging (default: false)

Design Choices:

  • Separate timeouts for model discovery vs. LLM requests (discovery should be fast, LLM requests can be long)
  • Default to 0 retries (users can enable if needed) to avoid unexpected behavior
  • Table format for tools-support models provides better information density than radio list
  • Informational display of non-tools models provides transparency without cluttering selectable options

Reviewer Attention:

  • Check null handling in parseOllamaModel and discoverOllamaModelsWithSorting - we use != null checks to handle both null and undefined
  • Verify Axios timeout configuration is properly applied via createOllamaAxiosInstance
  • Confirm UI state management for modelsWithTools array matches backend OllamaModelWithTools[] structure
  • Test the "Refresh Models" button actually triggers model discovery and updates the UI

Test Procedure

Unit Tests:

All tests are located in src/api/providers/fetchers/__tests__/ollama.test.ts. To run:

cd src && npx vitest run api/providers/fetchers/__tests__/ollama.test.ts

Test Coverage (20 tests, all passing):

  1. parseOllamaModel - Handles null/undefined model_info gracefully
  2. getOllamaModels - Fetches models with tools capability filtering
  3. getOllamaModels - Filters out models without tools capability
  4. getOllamaModels - Handles /api/tags call failures
  5. getOllamaModels - Handles ECONNREFUSED errors
  6. getOllamaModels - Handles models with null families
  7. getOllamaModels - Includes Authorization header when API key provided
  8. getOllamaModels - Uses custom timeout configuration
  9. getOllamaModels - Handles timeout errors during discovery
  10. getOllamaModels - Handles ECONNABORTED timeout errors
  11. discoverOllamaModelsWithSorting - Handles null model_info gracefully
  12. discoverOllamaModelsWithSorting - Handles undefined model_info gracefully
  13. discoverOllamaModelsWithSorting - Handles empty model_info object gracefully
  14. discoverOllamaModelsWithSorting - Sorts models correctly into tools and non-tools groups
  15. discoverOllamaModelsWithSorting - Handles partial failures gracefully (some models succeed, others fail)
  16. discoverOllamaModelsWithSorting - Handles models with both tools and vision capabilities
  17. discoverOllamaModelsWithSorting - Handles timeout errors during /api/tags call
  18. discoverOllamaModelsWithSorting - Handles timeout errors gracefully for individual /api/show calls
  19. discoverOllamaModelsWithSorting - Uses custom timeout configuration
  20. discoverOllamaModelsWithSorting - Verifies totalCount matches sum of both groups

Manual Testing Steps:

  1. Model Discovery & Refresh:

    • Open Roo Code Settings → Providers → Ollama
    • Click "Refresh Models" button
    • Verify models are discovered and displayed in "Tools Support" table
    • Verify models without tools support appear in "No Tools Support" section
    • Verify completion time is displayed after refresh
    • Add a new model to Ollama (e.g., ollama pull llama3.2)
    • Click "Refresh Models" again
    • Verify new model appears in appropriate section
  2. Connection Testing:

    • Enter valid Ollama Base URL (e.g., http://localhost:11434)
    • Click "Test" button
    • Verify success message with timing information
    • Enter invalid URL
    • Click "Test" button
    • Verify error message
  3. Model Selection:

    • Verify only models in "Tools Support" table are selectable (radio buttons work)
    • Select a model from the table
    • Verify model ID field updates
    • Verify selected model persists after page refresh
  4. Configuration Settings:

    • Expand "Connection Settings" section
    • Modify Request Timeout, verify validation (1000-7200000 range)
    • Modify Model Discovery Timeout, verify validation (1000-600000 range)
    • Modify Max Retries, verify validation (0-10 range)
    • Modify Retry Delay, verify validation (100-10000 range)
    • Toggle "Enable Request Logging"
    • Verify settings persist after saving
  5. Error Handling:

    • Stop Ollama service
    • Click "Refresh Models"
    • Verify graceful error handling (no crashes)
    • Start Ollama service
    • Click "Refresh Models" again
    • Verify models are discovered successfully

Testing Environment:

  • NixOS 26.05 (unstable)
  • Ollama running locally on http://localhost:11434
  • Multiple models installed (9 with tools support, 5 without)
  • Roo Code version: 3.41.1+

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.

Screenshots / Videos

The video for this pull request is (updated): https://youtu.be/IqmIjSklBe8

Before:

  • Simple text input for Model ID with no way to refresh the model list
  • No visibility into which models support tools vs. don't
  • No connection testing capability

After:

  • "Refresh Models" button that updates the model list with completion time
  • "Tools Support" table showing selectable models with detailed metadata (Context, Size, Quantization, Family, Images)
  • "No Tools Support" section showing non-selectable models for reference
  • "Test" button for Base URL validation
  • "Connection Settings" section with configurable timeouts, retries, and logging
image image

Documentation Updates

  • No documentation updates are required.
  • Yes, documentation updates are required.

Documentation Updates Needed:

This change actually makes the current default configuration much more obvious, so this is partially self documenting.

  1. Ollama Provider Documentation (https://docs.roocode.com/providers/ollama):

    • Add section explaining the "Refresh Models" button and when to use it
    • Document the new "Connection Settings" section and available configuration options
    • Explain the difference between "Tools Support" and "No Tools Support" model groups
    • Document the table columns (Context, Size, Quantization, Family, Images)
    • Add information about configurable timeouts and when to adjust them
  2. Settings Reference:

    • Document new Ollama configuration options:
      • ollamaRequestTimeout (default: 3600000 ms)
      • ollamaModelDiscoveryTimeout (default: 10000 ms)
      • ollamaMaxRetries (default: 0)
      • ollamaRetryDelay (default: 1000 ms)
      • ollamaEnableLogging (default: false)

Additional Notes

Implementation Notes:

  1. Null Safety: The Ollama API can return model_info as null or undefined. We use explicit != null checks (which handles both) instead of truthy checks to avoid Object.keys(null) errors.

  2. Zod Schema Validation: The validation is intentionally lenient - if Zod validation fails but essential fields (family, parameter_size) are present, we proceed with the raw data. This allows the code to work with minimal mock data in tests while still validating real API responses.

  3. Axios Timeout Configuration: Timeouts are configured at the Axios instance level, not per-request. This ensures consistent behavior across all API calls.

  4. Model Discovery Performance: The parallel /api/show calls significantly improve discovery speed compared to sequential calls. With 14 models, this reduces discovery time from ~14 seconds to ~2-3 seconds.

  5. Backward Compatibility: All new configuration options have sensible defaults, so existing configurations continue to work without modification.

  6. Test Coverage: The test suite includes comprehensive coverage for:

    • Success paths
    • Failure modes (timeouts, connection errors, partial failures)
    • Edge cases (null/undefined values, empty objects, mixed capabilities)
    • Configuration validation

Questions for Reviewers:

  • Should we add a loading indicator during model discovery? (Currently shows "Refreshing..." on the button)
  • Should the "No Tools Support" section be collapsible to reduce UI clutter?
  • Are the default timeout values appropriate? (60 min for requests, 10 sec for discovery)

Get in Touch

Discord: randomizedcoder (or @randomizedcoder)


Important

Enhances Ollama provider with model discovery, UI improvements, and configurable settings, including timeouts and retries, with comprehensive test coverage.

  • Behavior:
    • Adds discoverOllamaModelsWithSorting for model discovery with sorting into tools and non-tools groups.
    • Implements connection testing and model refresh in webviewMessageHandler.ts.
    • Adds UI elements for testing connection and refreshing models in Ollama.tsx.
  • Configuration:
    • Adds configurable timeouts, retries, and logging in provider-settings.ts.
    • Updates Ollama.tsx to handle new configuration options.
  • UI Enhancements:
    • Redesigns model display with a table format in Ollama.tsx.
    • Adds advanced connection settings section in Ollama.tsx.
  • Testing:
    • Adds unit tests in ollama.test.ts and ollama-axios-config.spec.ts for new functionalities.
  • Misc:
    • Updates settings.json for new UI text and descriptions.
    • Adds createOllamaAxiosInstance for centralized Axios configuration in ollama.ts.

This description was created by Ellipsis for 77a2cae. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. Documentation Improvements or additions to documentation Enhancement New feature or request labels Jan 25, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 25, 2026

Rooviewer Clock   See task on Roo Cloud

All issues resolved. Latest commit (05ae911) completes the internationalization of the Ollama settings page with translations for all 18 supported languages and proper plural form handling.

  • Dead code/duplicate file ollama-axios-config.ts - Fixed in 5bfb9dc
  • Table headers not internationalized - Fixed in 05ae911
  • Backend messages not internationalized - Fixed in 05ae911 (using translateMessage helper)
  • "Completed in" message not internationalized - Fixed in 05ae911
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@@ -0,0 +1,119 @@
import axios, { AxiosInstance, AxiosError, InternalAxiosRequestConfig, AxiosResponse } from "axios"
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is unused and contains duplicate code. The exact same implementation exists in ollama.ts (lines 19-135):

  • createOllamaAxiosInstance function
  • setupRetryInterceptor function
  • setupLoggingInterceptor function

This file should be removed to avoid duplication and potential maintenance issues where changes to one file might not be reflected in the other.

Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Overall, this is a solid PR with valuable functionality for Ollama model discovery. The code is well-tested with comprehensive test coverage (28 tests passing).

One issue needs to be addressed:

The file src/api/providers/fetchers/ollama-axios-config.ts is dead code. It contains the exact same implementation as lines 19-135 of ollama.ts (createOllamaAxiosInstance, setupRetryInterceptor, setupLoggingInterceptor) and is not imported anywhere in the codebase.

Please remove this duplicate file before merging.

Once this is addressed, the PR is ready to merge.

<thead>
<tr className="border-b border-vscode-foreground/10">
<th className="text-left py-2 px-3 font-medium text-vscode-foreground">
Model Name
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we update this table to use the internationalized strings?

provider.postMessageToWebview({
type: "ollamaModelsRefreshResult",
success: true,
message: `Found ${result.modelsWithTools.length} model(s) with tools support (${result.totalCount} total)`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we internationalize these messages too?

}`}>
<div>{testResult.message}</div>
{testResult.durationMs !== undefined && (
<div className="text-xs mt-1 opacity-80">Completed in {testResult.durationMs}ms</div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one too

</thead>
<tbody>
{modelsWithTools.map((model) => {
const formatSize = (bytes?: number): string => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we probably already have a helper for this somewhere

@randomizedcoder
Copy link
Author

@mrubens

Thanks for the feedback! On it! 🚀

Also fixed the Kdenlive render ( av1 apparently doesn't work, so did h265 )

https://youtu.be/IqmIjSklBe8

@dreness
Copy link

dreness commented Jan 25, 2026

I tried this, and it works - however it didn't seem to honor a non-default ollama port, if configured. Also noticed that the first time through (perhaps in the first-time-user flow, after being asked if I want to create a roo account or use a 3rd party provider, and I choose 3rd party provider), the ollama settings view didn't seem to scroll far enough, so the content was clipped partway through the list of models with no tools support. As soon as I got to the regular API provider config UI (i.e. not Roo's first-run flow), all the ollama settings UI was accessible.

@randomizedcoder
Copy link
Author

@dreness

Thank you! Yes you found a bug! Awesome. The "Test" button wasn't passing the URL correctly. Fix has been pushed.

I tested this on my local machine by moving ollama to 11435

[das@l:~/nixos/desktop/l]$ netstat -an | grep 11435
tcp6       0      0 :::11435                :::*                    LISTEN

Before with bug

image

Fix applied

image

@randomizedcoder
Copy link
Author

Ok, have done most of the work on the internationalization.

I did Indonesian at high school, so this was my test. The first iteration wasn't great, because there were too many English words, but I think it's looking pretty good now. -> as for the other languages and the translation quality, well, I ran it by Gemini also, and Google is pretty good at internationalization, so I think it should be ok

... I'll review this again, and push the code tomorrow

image image

@randomizedcoder
Copy link
Author

@mrubens - wow. added i18n was quite a lot of work. it's done, and I think it looks pretty good.

Example of Spanish, including the "Update models" text
image

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

Labels

Documentation Improvements or additions to documentation Enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Force update the ollama models?

3 participants