Skip to content

Commit 1ee3ecb

Browse files
committed
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
1 parent 099ea6d commit 1ee3ecb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,23 @@ export const webviewMessageHandler = async (
912912
if (result.status === "fulfilled") {
913913
routerModels[routerName] = result.value.models
914914

915+
// For OpenRouter: preserve the currently selected model if it's not in the cache
916+
// This prevents newer models from being marked as invalid after cache refresh
917+
if (routerName === "openrouter" && apiConfiguration.openRouterModelId) {
918+
const selectedModelId = apiConfiguration.openRouterModelId
919+
// Only add if not already in the models list
920+
if (!routerModels[routerName][selectedModelId]) {
921+
// Create a minimal model info for the selected model
922+
// This allows users to continue using newer models that aren't in the API response yet
923+
routerModels[routerName][selectedModelId] = {
924+
maxTokens: 128000, // Default max tokens
925+
contextWindow: 128000, // Default context window
926+
supportsPromptCache: false,
927+
description: `Model ${selectedModelId} (preserved from configuration)`,
928+
}
929+
}
930+
}
931+
915932
// Ollama and LM Studio settings pages still need these events. They are not fetched here.
916933
} else {
917934
// Handle rejection: Post a specific error message for this provider.

0 commit comments

Comments
 (0)