fix(ui): keep the selected model when switching agent modes

Switching between Build and Plan modes reset the model selector to the
settings default because setAgent fell through to the settings-default
fallback whenever the target agent had no saved override, and the
explicit-switch path in ModelControls force-applied the agent's default
model, overwriting any per-agent override.

setAgent now keeps the current model selection when the user has a live
manual selection and the target agent configures no model of its own,
and the explicit-switch handler no longer clobbers saved per-agent
overrides with the agent default. Startup and pin behavior are
unchanged: the settings-default and agent-pin cascade still applies
when no manual selection exists yet.

Fixes #2531
This commit is contained in:
Serhii Dziupin
2026-08-05 13:50:23 +03:00
parent 34c221b07f
commit 264fc16f2c
3 changed files with 36 additions and 37 deletions
+12 -2
View File
@@ -2387,6 +2387,9 @@ export const useConfigStore = create<ConfigStore>()(
currentProviderId,
currentModelId,
} = get();
// Captured before the first set below, which unconditionally
// marks the selection as manual.
const hadManualSelection = get().selectionSource === "manual";
set((state) => {
const directoryKey = state.activeDirectoryKey;
@@ -2508,8 +2511,7 @@ export const useConfigStore = create<ConfigStore>()(
// Prefer a session-level manual override for this agent over the
// agent's configured default. Re-applying setAgent after subtask
// completion / rematerialization must not clobber the override
// (issue #2404). Explicit agent-picker switches still force the
// agent default via ModelControls' shouldPreferAgentModel path.
// (issue #2404).
if (currentSessionId) {
const existingAgentModel = useSelectionStore.getState().getAgentModelForSession(currentSessionId, agentName);
if (existingAgentModel && hasProviderModel(providers, existingAgentModel.providerId, existingAgentModel.modelId)) {
@@ -2538,6 +2540,14 @@ export const useConfigStore = create<ConfigStore>()(
}
}
// The user has a live manual model selection and the target
// agent configures no model of its own. Switching modes or
// agents must not reset the selection to the settings default
// (issue #2531) — mode switches are not model changes.
if (hadManualSelection && currentProviderId && currentModelId) {
return;
}
// If the agent has no preferred model, use settings default.
if (settingsDefaultModel) {
const parsed = parseModelString(settingsDefaultModel);