From 1ee3ecb5282e7e0d4df7d37f35ee7ea92d1c92d6 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Wed, 26 Nov 2025 05:00:08 +0000 Subject: [PATCH] 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 --- src/core/webview/webviewMessageHandler.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 7ccee8c100d..3008dacb097 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -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.