diff --git a/src/providers/ChatViewProvider.ts b/src/providers/ChatViewProvider.ts index ba3d039..b503068 100644 --- a/src/providers/ChatViewProvider.ts +++ b/src/providers/ChatViewProvider.ts @@ -2008,7 +2008,7 @@ export class ChatViewProvider this.clearSessionTodos(sessionId); // Restore per-session agent / model / thinking selections - await this.modelAndAgentManager.applySessionSettings(sessionId); + await this.applySessionSettings(sessionId); if (abandonIfStale("applySessionSettings")) return; // ============================================================================ @@ -9288,7 +9288,9 @@ export class ChatViewProvider * Applies session-specific model, agent, and thinking level */ private async applySessionSettings(sessionId: string): Promise { - return this.modelAndAgentManager.applySessionSettings(sessionId); + await this.modelAndAgentManager.applySessionSettings(sessionId); + this.selectedModel = this.modelAndAgentManager.getSelectedModel(); + this.selectedAgent = this.modelAndAgentManager.getSelectedAgent() ?? "build"; } /** diff --git a/tests/regression/session-model-selection-regression.test.mjs b/tests/regression/session-model-selection-regression.test.mjs new file mode 100644 index 0000000..742608d --- /dev/null +++ b/tests/regression/session-model-selection-regression.test.mjs @@ -0,0 +1,32 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { extractFunctionBody, joinFromRoot, readSource } from "../helpers/source-utils.mjs"; + +const provider = readSource( + [joinFromRoot("src", "providers", "ChatViewProvider.ts")], + "ChatViewProvider.ts", +); + +test("session switches synchronize the prompt model with restored session settings", () => { + const applySessionSettings = extractFunctionBody( + provider, + "private async applySessionSettings(sessionId: string): Promise", + ); + + assert.match( + applySessionSettings, + /await this\.modelAndAgentManager\.applySessionSettings\(sessionId\)/, + "session settings must be restored before synchronizing prompt state", + ); + assert.match( + applySessionSettings, + /this\.selectedModel\s*=\s*this\.modelAndAgentManager\.getSelectedModel\(\)/, + "prompts must use the model restored for the active session", + ); + assert.match( + provider, + /await this\.applySessionSettings\(sessionId\);/, + "session loading must use the synchronized restore path", + ); +});