From 5bd21a240d4f591089dd49ea669db7a02454d502 Mon Sep 17 00:00:00 2001 From: Sri Pasumarthi <111310667+sripasg@users.noreply.github.com> Date: Tue, 3 Mar 2026 19:28:12 -0800 Subject: [PATCH] fix: model persistence for all scenarios (#21051) --- packages/core/src/config/config.test.ts | 17 +++++++++++++++++ packages/core/src/config/config.ts | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index ed05635373..33a04b52ab 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -2198,6 +2198,23 @@ describe('Config getHooks', () => { expect(onModelChange).not.toHaveBeenCalled(); }); + + it('should call onModelChange when persisting a model that was previously temporary', () => { + const onModelChange = vi.fn(); + const config = new Config({ + ...baseParams, + model: 'some-other-model', + onModelChange, + }); + + // Temporary selection + config.setModel(DEFAULT_GEMINI_MODEL, true); + expect(onModelChange).not.toHaveBeenCalled(); + + // Persist selection of the same model + config.setModel(DEFAULT_GEMINI_MODEL, false); + expect(onModelChange).toHaveBeenCalledWith(DEFAULT_GEMINI_MODEL); + }); }); }); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index cff1eb2714..ce07271139 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1403,9 +1403,9 @@ export class Config implements McpContext { // When the user explicitly sets a model, that becomes the active model. this._activeModel = newModel; coreEvents.emitModelChanged(newModel); - if (this.onModelChange && !isTemporary) { - this.onModelChange(newModel); - } + } + if (this.onModelChange && !isTemporary) { + this.onModelChange(newModel); } this.modelAvailabilityService.reset(); }