fix: preserve selected OpenRouter models not in cache

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
This commit is contained in:
Roo Code 2025-11-26 05:00:08 +00:00
parent 099ea6dc6a
commit 1ee3ecb528

View file

@ -912,6 +912,23 @@ export const webviewMessageHandler = async (
if (result.status === "fulfilled") {
routerModels[routerName] = result.value.models
// 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)`,
}
}
}
// Ollama and LM Studio settings pages still need these events. They are not fetched here.
} else {
// Handle rejection: Post a specific error message for this provider.