-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix OpenRouter model cache validation for newer models #9601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
Review completed. Found 2 issues that should be addressed:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| routerModels[routerName][selectedModelId] = { | ||
| maxTokens: 128000, // Default max tokens | ||
| contextWindow: 128000, // Default context window | ||
| supportsPromptCache: false, | ||
| description: `Model ${selectedModelId} (preserved from configuration)`, | ||
| } |
There was a problem hiding this comment.
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.
| // 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)`, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
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:
Solution
Modified the
requestRouterModelshandler inwebviewMessageHandler.tsto 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
Testing
Feedback and guidance are welcome!
Important
Fixes OpenRouter model cache validation in
webviewMessageHandler.tsto preserve user-selected models not in cache.requestRouterModelsinwebviewMessageHandler.tsto preserve user-selected OpenRouter models not in cache.This description was created by
for 1ee3ecb. You can customize this summary. It will automatically update as commits are pushed.