Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-ideas-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Fix mode selection after anonymous usage
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
})

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ export const webviewMessageHandler = async (
}

// 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Prefer nullish coalescing to avoid treating falsy-but-valid values as "default"

Using || will replace any falsy value (e.g. an empty string) with "default". If currentApiConfigName is only ever string | undefined, using ?? is a safer defaulting pattern.

Suggested change
const currentApiConfigName = getGlobalState("currentApiConfigName") || "default"
const currentApiConfigName = getGlobalState("currentApiConfigName") ?? "default"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Prefer nullish coalescing (??) over || when defaulting currentApiConfigName

Using || treats "" (empty string) as missing. If currentApiConfigName can ever be an empty string (e.g. corrupted/migrated state), this will unexpectedly fall back to "default". ?? only falls back for null/undefined.

Suggested change
const currentApiConfigName = getGlobalState("currentApiConfigName") || "default"
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")
Expand Down
Loading