fix: preserve settings default thinking variant when switching agents (#1639)

* fix: preserve settings default thinking variant when switching agents

When a user sets a default thinking variant (e.g. 'high') in settings and
switches between plan and build agents in a session, the variant was reset
to 'default' (undefined) instead of respecting the settings default.

Root cause: two code paths failed to fall back to settingsDefaultVariant:

1. ModelControls variant sync effect: when no per-session+agent+model
   variant was saved, the effect set currentVariant to undefined instead
   of falling back to settingsDefaultVariant.

2. setAgent in useConfigStore: when the target agent had a configured
   model, the variant was always passed as undefined to
   applyResolvedModelSelection, ignoring both the saved per-session
   variant and the settings default.

Fix both paths to resolve variants in priority order:
saved variant > settingsDefaultVariant > undefined.

* fix: preserve agent variant fallback order

* fix: apply historical session variant on restore

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
weixiang1862
2026-06-23 13:35:36 +03:00
committed by GitHub
co-authored by Bohdan Triapitsyn
parent b863a4a83a
commit 3f4ad2a3e8
3 changed files with 128 additions and 23 deletions
+34 -19
View File
@@ -2437,6 +2437,35 @@ export const useConfigStore = create<ConfigStore>()(
});
};
const resolveVariantForModel = (
providerId: string,
modelId: string,
agentVariant?: string,
): string | undefined => {
const model = providers
.find((provider) => provider.id === providerId)
?.models.find((candidate) => candidate.id === modelId) as { variants?: Record<string, unknown> } | undefined;
const variants = model?.variants;
if (!variants) return undefined;
const savedVariant = currentSessionId
? useSelectionStore.getState().getAgentModelVariantForSession(
currentSessionId,
agentName,
providerId,
modelId,
)
: undefined;
for (const candidate of [savedVariant, agentVariant, settingsDefaultVariant]) {
if (candidate && Object.prototype.hasOwnProperty.call(variants, candidate)) {
return candidate;
}
}
return undefined;
};
// Prefer the selected agent's configured model when switching agents.
const agent = agents.find((candidate) => candidate.name === agentName);
const agentModelSelection = agent?.model;
@@ -2446,7 +2475,7 @@ export const useConfigStore = create<ConfigStore>()(
const agentModel = agentProvider?.models.find((model) => model.id === modelID);
if (agentModel) {
applyResolvedModelSelection(providerID, modelID, undefined);
applyResolvedModelSelection(providerID, modelID, resolveVariantForModel(providerID, modelID, agent?.variant));
return;
}
}
@@ -2454,18 +2483,13 @@ export const useConfigStore = create<ConfigStore>()(
if (currentSessionId) {
const existingAgentModel = useSelectionStore.getState().getAgentModelForSession(currentSessionId, agentName);
if (existingAgentModel && hasProviderModel(providers, existingAgentModel.providerId, existingAgentModel.modelId)) {
const savedVariant = useSelectionStore.getState().getAgentModelVariantForSession(
currentSessionId,
agentName,
existingAgentModel.providerId,
existingAgentModel.modelId,
);
const resolvedVariant = resolveVariantForModel(existingAgentModel.providerId, existingAgentModel.modelId, agent?.variant);
if (
currentProviderId !== existingAgentModel.providerId
|| currentModelId !== existingAgentModel.modelId
|| get().currentVariant !== savedVariant
|| get().currentVariant !== resolvedVariant
) {
applyResolvedModelSelection(existingAgentModel.providerId, existingAgentModel.modelId, savedVariant);
applyResolvedModelSelection(existingAgentModel.providerId, existingAgentModel.modelId, resolvedVariant);
}
return;
}
@@ -2477,16 +2501,7 @@ export const useConfigStore = create<ConfigStore>()(
if (parsed) {
const settingsProvider = providers.find((p) => p.id === parsed.providerId);
if (settingsProvider?.models.some((m) => m.id === parsed.modelId)) {
let nextVariant: string | undefined;
if (settingsDefaultVariant) {
const model = settingsProvider.models.find((m) => m.id === parsed.modelId) as { variants?: Record<string, unknown> } | undefined;
const variants = model?.variants;
if (variants && Object.prototype.hasOwnProperty.call(variants, settingsDefaultVariant)) {
nextVariant = settingsDefaultVariant;
}
}
applyResolvedModelSelection(parsed.providerId, parsed.modelId, nextVariant);
applyResolvedModelSelection(parsed.providerId, parsed.modelId, resolveVariantForModel(parsed.providerId, parsed.modelId, agent?.variant));
return;
}
}