Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Nov 26, 2025

Summary

This PR attempts to address Issue #9597 where newer OpenRouter models (gpt-5.1, gemini-3, grok-4.1-fast, etc.) disappear from the configuration after a few minutes and automatically switch to Claude Sonnet.

Root Cause

As @mrubens correctly suspected, the issue is related to the caching mechanism added in PR #9410. The problem occurs when:

  1. User selects a newer model that exists in OpenRouter but isn't in our cached model list
  2. After 5 minutes, the cache refreshes from the OpenRouter API
  3. If the model isn't in the API response (newer models not yet included), it gets marked as invalid
  4. The UI automatically falls back to Claude Sonnet

Solution

Modified the requestRouterModels handler in webviewMessageHandler.ts to preserve the user's currently selected OpenRouter model even if it's not in the cached model list. When the selected model is missing from the cache, we add it with default values, allowing continued use of newer models.

Changes

  • Added logic to check if the selected OpenRouter model exists in the fetched models
  • If missing, creates a minimal model entry with default values
  • Preserves user's model selection across cache refreshes

Testing

  • Ran existing tests for the model fetchers
  • All 91 tests pass successfully

Feedback and guidance are welcome!


Important

Fixes OpenRouter model cache validation in webviewMessageHandler.ts to preserve user-selected models not in cache.

  • Behavior:
    • Modifies requestRouterModels in webviewMessageHandler.ts to preserve user-selected OpenRouter models not in cache.
    • Adds minimal model entry with default values if selected model is missing from cache.
  • Testing:
    • Ran existing tests for model fetchers; all 91 tests pass.

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

When the OpenRouter model cache refreshes, preserve the user's currently
selected model even if it's not in the API response. This prevents newer
models (gpt-5.1, gemini-3, grok-4.1-fast, etc.) from being marked as
invalid and automatically switching to Claude Sonnet.

The fix adds the selected model to the models list with default values
if it's missing, allowing continued use of models that aren't yet in
the OpenRouter API response.

Fixes #9597
@roomote roomote bot requested review from cte, jr and mrubens as code owners November 26, 2025 05:04
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Nov 26, 2025
@roomote
Copy link
Contributor Author

roomote bot commented Nov 26, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. Found 2 issues that should be addressed:

  • Hardcoded default values may not accurately represent newer models' capabilities
  • Preserved model is not persisted to cache, will be lost on next refresh

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

Comment on lines +923 to +928
routerModels[routerName][selectedModelId] = {
maxTokens: 128000, // Default max tokens
contextWindow: 128000, // Default context window
supportsPromptCache: false,
description: `Model ${selectedModelId} (preserved from configuration)`,
}
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 hardcoded default values (128000 tokens, no prompt cache support) may not accurately represent newer models' actual capabilities. This could lead to incorrect token limits being enforced or missing features. Consider using null for maxTokens to avoid imposing artificial limits, and document that these are placeholder values until the model appears in the OpenRouter API response.

Fix it with Roo Code or mention @roomote and request a fix.

Comment on lines +915 to +930
// For OpenRouter: preserve the currently selected model if it's not in the cache
// This prevents newer models from being marked as invalid after cache refresh
if (routerName === "openrouter" && apiConfiguration.openRouterModelId) {
const selectedModelId = apiConfiguration.openRouterModelId
// Only add if not already in the models list
if (!routerModels[routerName][selectedModelId]) {
// Create a minimal model info for the selected model
// This allows users to continue using newer models that aren't in the API response yet
routerModels[routerName][selectedModelId] = {
maxTokens: 128000, // Default max tokens
contextWindow: 128000, // Default context window
supportsPromptCache: false,
description: `Model ${selectedModelId} (preserved from configuration)`,
}
}
}
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 preserved model is only added to the in-memory routerModels object sent to the webview, but it's not persisted to the cache. This means the model will be lost on the next cache refresh (which occurs every 5 minutes according to the cache TTL in modelCache.ts). Consider also updating the memory cache and disk cache with the preserved model to ensure it persists across cache refreshes.

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

3 participants