Skip to content

Conversation

@pdecat
Copy link
Contributor

@pdecat pdecat commented Dec 5, 2025

Related GitHub Issue

Closes: #9682

Description

This PR fixes two related issues with the LiteLLM provider (and potentially others like LM Studio and Ollama):

  1. "Refresh models" button not working: The flushModels function was being called without credentials (apiKey, baseUrl), causing the subsequent refreshModels call to fail when trying to fetch models from the provider.
  2. Initial request using wrong model: When starting a new task, RouterProvider.getModel() was being called synchronously before fetchModel() had populated the instance's model list. This caused it to fall back to the default model (Claude 3.7 Sonnet) for the first request or system prompt generation, even if a different model was selected.

Implementation Details:

  • Updated flushModels signature in src/api/providers/fetchers/modelCache.ts to accept GetModelsOptions instead of just a provider string. This allows credentials to be passed through to refreshModels.
  • Updated src/core/webview/webviewMessageHandler.ts to pass apiKey and baseUrl when handling the refreshRouterModels message for LiteLLM, LM Studio, and Ollama.
  • Modified RouterProvider.getModel() in src/api/providers/router-provider.ts to check the global synchronous cache (getModelsFromCache) if the instance's this.models is empty. This ensures models are available immediately if they have been previously cached, preventing the fallback to the default model on the first request.

Test Procedure

  1. Verify Refresh:

    • Configure LiteLLM provider with valid URL and API key.
    • Click "Refresh models".
    • Verify that a request is sent to the LiteLLM server (can be checked with a proxy or by seeing the model list update).
  2. Verify Model Selection:

    • Select a non-default model (e.g., gemini-3-pro-preview).
    • Start a new task.
    • Ask "Which model is this?".
    • Verify the response indicates the selected model, not the default claude-3-7-sonnet-20250219.
  3. Unit Tests:

    • npm run test src/api/providers/__tests__/lite-llm.spec.ts
    • npm run test src/api/providers/fetchers/__tests__/modelCache.spec.ts
    • npm run test src/core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts

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.

Important

Fixes refresh models button by passing credentials and ensures correct model usage on initial request.

  • Behavior:
    • Fix flushModels in modelCache.ts to accept GetModelsOptions for credentials, ensuring refreshModels can fetch models correctly.
    • Modify RouterProvider.getModel() in router-provider.ts to use global cache if this.models is empty, preventing fallback to default model.
  • Webview Handling:
    • Update webviewMessageHandler.ts to pass apiKey and baseUrl for refreshRouterModels message for LiteLLM, LM Studio, and Ollama.
  • Testing:
    • Update tests in webviewMessageHandler.routerModels.spec.ts to verify flushModels and getModels are called with correct credentials.
  • Misc:
    • Minor logging changes in extension.ts for Roo models cache handling.

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

@pdecat pdecat requested review from cte, jr and mrubens as code owners December 5, 2025 18:17
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Dec 5, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 5, 2025

Rooviewer Clock   See task on Roo Cloud

Re-review completed - no new issues found. The latest change improves async behavior by ensuring flushModels waits for cache refresh completion before returning.

Latest change (commit 8a5560f):

  • Changed refreshModels(options).catch(...) to await refreshModels(options) on line 285
  • Makes async behavior explicit and ensures cache is fully updated before callers proceed
  • Error handling remains intact in refreshModels function (never throws)
  • Aligns with caller expectations in webviewMessageHandler.ts

Overall PR summary:

  • ✅ Credentials properly passed to flushModels for all providers requiring them
  • ✅ Type safety maintained with GetModelsOptions discriminated union
  • ✅ Smart cache fallback logic prevents incorrect default model usage
  • ✅ Tests updated and passing
  • ✅ Race condition handling preserved via in-flight request tracking
Previous reviews

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

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 5, 2025
@pdecat pdecat force-pushed the fix/litellm_refresh_models_cache branch from 9ed9955 to 0d40375 Compare December 5, 2025 18:36
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Dec 5, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Dec 5, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 5, 2025
@pdecat
Copy link
Contributor Author

pdecat commented Dec 5, 2025

Added a commit to resolve a last remaining issue reported in #9683 (comment)

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

Labels

bug Something isn't working PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

[BUG] LiteLLM cache flush doesn't work

2 participants