From b90c9e1fa5e014ed1e00cd304594da30943dd884 Mon Sep 17 00:00:00 2001 From: Josh Lambert Date: Thu, 29 Jan 2026 14:01:05 +0100 Subject: [PATCH 1/3] Fix model selection --- .../__tests__/webviewMessageHandler.autoSwitch.spec.ts | 6 +++--- src/core/webview/webviewMessageHandler.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/webview/__tests__/webviewMessageHandler.autoSwitch.spec.ts b/src/core/webview/__tests__/webviewMessageHandler.autoSwitch.spec.ts index 036cd307f58..d76565d339f 100644 --- a/src/core/webview/__tests__/webviewMessageHandler.autoSwitch.spec.ts +++ b/src/core/webview/__tests__/webviewMessageHandler.autoSwitch.spec.ts @@ -145,7 +145,7 @@ describe("webviewMessageHandler - Automatic Organization Switching", () => { kilocodeToken: "test-token", kilocodeOrganizationId: "org-1", }, - false, + true, // Changed: Now correctly activates the profile (fix for PR #5415 bug) ) // Verify flag was set to true after the recursive call @@ -407,7 +407,7 @@ describe("webviewMessageHandler - Automatic Organization Switching", () => { kilocodeToken: "new-token", kilocodeOrganizationId: undefined, }, - false, + true, // Changed: Now correctly activates the profile (fix for PR #5415 bug) ) }) @@ -569,7 +569,7 @@ describe("webviewMessageHandler - Automatic Organization Switching", () => { kilocodeToken: "test-token", kilocodeOrganizationId: "org-1", }, - false, + true, // Changed: Now correctly activates the profile (fix for PR #5415 bug) ) // Verify log message mentions the correct organization diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 9aa7dfc64ba..bcba7181016 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -2259,11 +2259,13 @@ export const webviewMessageHandler = async ( if (message.text && message.apiConfiguration) { let configToSave = message.apiConfiguration let organizationChanged = false + let currentConfig: any = undefined try { - const { ...currentConfig } = await provider.providerSettingsManager.getProfile({ + currentConfig = await provider.providerSettingsManager.getProfile({ name: message.text, }) + // Only clear organization ID if we actually had a kilocode token before and it's different now const hadPreviousToken = currentConfig.kilocodeToken !== undefined const hasNewToken = message.apiConfiguration.kilocodeToken !== undefined @@ -2301,11 +2303,12 @@ export const webviewMessageHandler = async ( }) } } catch (error) { - // Config might not exist yet, that's fine + // Profile doesn't exist yet (expected for new profiles) + // This is fine - we'll create it below } // kilocode_change start: If we're updating the active profile, we need to activate it to ensure it's persisted - const currentApiConfigName = getGlobalState("currentApiConfigName") + const currentApiConfigName = getGlobalState("currentApiConfigName") || "default" const isActiveProfile = message.text === currentApiConfigName await provider.upsertProviderProfile(message.text, configToSave, isActiveProfile) // Activate if it's the current active profile vscode.commands.executeCommand("kilo-code.ghost.reload") From 9aad449cf1788cc192a23514b0d2a3fbe04f2799 Mon Sep 17 00:00:00 2001 From: Josh Lambert Date: Thu, 29 Jan 2026 14:18:34 +0100 Subject: [PATCH 2/3] Remove unnecessary changes --- src/core/webview/webviewMessageHandler.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index bcba7181016..13dd8ef5edc 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -2259,13 +2259,11 @@ export const webviewMessageHandler = async ( if (message.text && message.apiConfiguration) { let configToSave = message.apiConfiguration let organizationChanged = false - let currentConfig: any = undefined try { - currentConfig = await provider.providerSettingsManager.getProfile({ + const { ...currentConfig } = await provider.providerSettingsManager.getProfile({ name: message.text, }) - // Only clear organization ID if we actually had a kilocode token before and it's different now const hadPreviousToken = currentConfig.kilocodeToken !== undefined const hasNewToken = message.apiConfiguration.kilocodeToken !== undefined @@ -2303,8 +2301,7 @@ export const webviewMessageHandler = async ( }) } } catch (error) { - // Profile doesn't exist yet (expected for new profiles) - // This is fine - we'll create it below + // Config might not exist yet, that's fine } // kilocode_change start: If we're updating the active profile, we need to activate it to ensure it's persisted From e53f0865d32296cb5e4db5f853466f5fa7671371 Mon Sep 17 00:00:00 2001 From: Kevin van Dijk Date: Thu, 29 Jan 2026 14:56:35 +0100 Subject: [PATCH 3/3] Add changeset --- .changeset/early-ideas-hug.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/early-ideas-hug.md diff --git a/.changeset/early-ideas-hug.md b/.changeset/early-ideas-hug.md new file mode 100644 index 00000000000..b8199cde141 --- /dev/null +++ b/.changeset/early-ideas-hug.md @@ -0,0 +1,5 @@ +--- +"kilo-code": patch +--- + +Fix mode selection after anonymous usage