fix(vscode): apply the selected agent instead of the stale session agent

This commit is contained in:
hdcode.dev
2026-08-15 20:10:23 +02:00
parent c8271ad6f4
commit f8dce5b457
3 changed files with 24 additions and 1 deletions
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---
Fix agent mode switch getting stuck on draft/cloud-import sessions: apply the explicitly selected agent instead of reverting to the stale session agent.
@@ -146,6 +146,14 @@ describe("resolvePromptAgent", () => {
expect(resolvePromptAgent({ selections: {}, pending: "code" })).toBe("code")
})
it("honors an explicit pending selection for a draft scope with no per-session entry", () => {
expect(resolvePromptAgent({ sessionID: "draft-1", selections: {}, pending: "ask" })).toBe("ask")
})
it("does not fall back to pending for a real server session with no per-session entry", () => {
expect(resolvePromptAgent({ sessionID: "ses_1", selections: {}, pending: "ask" })).toBeUndefined()
})
it("omits the agent when there is no explicit selection", () => {
expect(resolvePromptAgent({ sessionID: "ses_1", selections: {}, pending: null })).toBeUndefined()
expect(resolvePromptAgent({ selections: {}, pending: null })).toBeUndefined()
@@ -31,7 +31,17 @@ export function resolvePromptAgent(input: {
selections: Record<string, string>
pending: string | null
}) {
if (input.sessionID) return input.selections[input.sessionID]
if (input.sessionID) {
const sel = input.selections[input.sessionID]
if (sel) return sel
// Only fall back to the pending selection for draft scopes, not real server
// sessions. A server session with no stored selection must keep its own agent
// rather than be flipped to the stale/default pending agent.
if (!input.sessionID.startsWith("ses_")) {
return input.pending ?? undefined
}
return undefined
}
return input.pending ?? undefined
}