diff --git a/.changeset/selected-agent-over-stale-session.md b/.changeset/selected-agent-over-stale-session.md new file mode 100644 index 00000000000..d3274831551 --- /dev/null +++ b/.changeset/selected-agent-over-stale-session.md @@ -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. diff --git a/packages/kilo-vscode/tests/unit/session-agent.test.ts b/packages/kilo-vscode/tests/unit/session-agent.test.ts index a10cdbbe43c..2949fb55ac6 100644 --- a/packages/kilo-vscode/tests/unit/session-agent.test.ts +++ b/packages/kilo-vscode/tests/unit/session-agent.test.ts @@ -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() diff --git a/packages/kilo-vscode/webview-ui/src/context/session-agent.ts b/packages/kilo-vscode/webview-ui/src/context/session-agent.ts index 87d243295a5..b285aaccf40 100644 --- a/packages/kilo-vscode/webview-ui/src/context/session-agent.ts +++ b/packages/kilo-vscode/webview-ui/src/context/session-agent.ts @@ -31,7 +31,17 @@ export function resolvePromptAgent(input: { selections: Record 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 }