From 0e3fe0e8f892495992ba5333c89b11d839649749 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 9 Oct 2025 19:30:40 +0000 Subject: [PATCH] fix: preserve OpenAI-like provider settings when switching modes - Save current provider configuration when switching to a mode without saved config - Re-activate custom OpenAI provider profiles to ensure settings persist - Fixes issue where Jan.ai and other OpenAI-compatible provider settings were lost Fixes #8583 --- src/core/webview/ClineProvider.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 91b8687966..c16190489a 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1211,14 +1211,20 @@ export class ClineProvider await this.activateProviderProfile({ name: profile.name }) } } else { - // If no saved config for this mode, save current config as default. + // If no saved config exists for this mode, handle the current configuration const currentApiConfigName = this.getGlobalState("currentApiConfigName") + const currentConfig = listApiConfig.find(({ name }) => name === currentApiConfigName) - if (currentApiConfigName) { - const config = listApiConfig.find((c) => c.name === currentApiConfigName) + if (currentApiConfigName && currentConfig?.id) { + // Always save the current config as the default for the new mode + // This ensures that custom OpenAI providers (and all other providers) persist across mode switches + await this.providerSettingsManager.setModeConfig(newMode, currentConfig.id) - if (config?.id) { - await this.providerSettingsManager.setModeConfig(newMode, config.id) + // For custom OpenAI providers, we need to ensure the configuration is properly loaded + // The "openai" provider is the customizable one that users configure for OpenAI-compatible endpoints + if (currentConfig.apiProvider === "openai") { + // Re-activate the profile to ensure all settings are properly loaded + await this.activateProviderProfile({ name: currentConfig.name }) } } }