Skip to content

Commit d56b82c

Browse files
macodev00juliusmarmingeclaude
authored
fix(web): keep saved default model when changing effort (#22193)
Co-authored-by: macodev00 <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 5da53f8 commit d56b82c

6 files changed

Lines changed: 222 additions & 16 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ProviderDriverKind } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { retainedModelWhileProviderLocked } from "./ProviderModelPicker.logic";
5+
6+
const claude = ProviderDriverKind.make("claudeAgent");
7+
const opus = { slug: "claude-opus-5-5", name: "Claude Opus 5.5", shortName: "Opus 5.5" };
8+
const sonnet = { slug: "claude-sonnet-5-5", name: "Claude Sonnet 5.5", shortName: "Sonnet 5.5" };
9+
const retained = (enabled: boolean, isAvailable: boolean, models = [sonnet, opus]) =>
10+
retainedModelWhileProviderLocked({ driverKind: claude, enabled, isAvailable, models }, opus.slug);
11+
12+
describe("retainedModelWhileProviderLocked", () => {
13+
it("shows a hidden saved model while its provider cannot run", () => {
14+
expect(retained(false, true)).toBe(opus);
15+
expect(retained(true, false)).toBe(opus);
16+
expect(retained(false, true, [sonnet])).toEqual({ slug: opus.slug, name: opus.slug });
17+
expect(retained(true, true)).toBeUndefined();
18+
expect(retainedModelWhileProviderLocked(null, opus.slug)).toBeUndefined();
19+
});
20+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ProviderDriverKind } from "@t3tools/contracts";
2+
3+
import type { ModelEsque } from "./providerIconUtils";
4+
5+
/** Keeps a hidden model visible while its provider is locked or turned off. */
6+
export function retainedModelWhileProviderLocked(
7+
entry: {
8+
readonly driverKind: ProviderDriverKind;
9+
readonly enabled: boolean;
10+
readonly isAvailable: boolean;
11+
readonly models: ReadonlyArray<Pick<ModelEsque, "slug" | "name" | "shortName" | "subProvider">>;
12+
} | null,
13+
model: string,
14+
): ModelEsque | undefined {
15+
if (!entry || (entry.enabled && entry.isAvailable) || !model) return undefined;
16+
if (entry.driverKind === "opencode" || entry.driverKind === "antigravity") return undefined;
17+
return entry.models.find((candidate) => candidate.slug === model) ?? { slug: model, name: model };
18+
}

‎apps/web/src/components/chat/ProviderModelPicker.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
2121
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
2222
import { cn } from "~/lib/utils";
2323
import { ModelPickerContent, resolveModelPickerSelectedModel } from "./ModelPickerContent";
24+
import { retainedModelWhileProviderLocked } from "./ProviderModelPicker.logic";
2425
import { ChatGptSharingControl } from "./ChatGptSharingControl";
2526
import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
2627
import { ModelEsque, getDisplayModelName, getTriggerDisplayModelName } from "./providerIconUtils";
@@ -161,6 +162,7 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
161162
model: props.model,
162163
options: selectedInstanceOptions,
163164
}) ??
165+
retainedModelWhileProviderLocked(activeEntry, props.model) ??
164166
(activeEntry?.driverKind === "opencode" || activeEntry?.driverKind === "antigravity"
165167
? undefined
166168
: selectedInstanceOptions[0]);
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2+
import { DEFAULT_UNIFIED_SETTINGS, type UnifiedSettings } from "@t3tools/contracts/settings";
3+
import { createModelSelection } from "@t3tools/shared/model";
4+
import { describe, expect, it } from "vite-plus/test";
5+
6+
import { providerInstanceEntriesFor } from "../../providerInstances";
7+
import { resolveDefaultModelSettingsPresentation } from "./ProjectDefaultsSettings.logic";
8+
9+
const claudeId = ProviderInstanceId.make("claudeAgent");
10+
const high = [{ id: "effort", value: "high" }];
11+
const savedClaude = createModelSelection(claudeId, "claude-opus-4-8", high);
12+
function provider(input: {
13+
instanceId: string;
14+
driver: string;
15+
enabled?: boolean;
16+
availability?: ServerProvider["availability"];
17+
models: ReadonlyArray<string>;
18+
}): ServerProvider {
19+
return {
20+
instanceId: ProviderInstanceId.make(input.instanceId),
21+
driver: ProviderDriverKind.make(input.driver),
22+
enabled: input.enabled ?? true,
23+
installed: true,
24+
version: null,
25+
status: "ready",
26+
...(input.availability ? { availability: input.availability } : {}),
27+
auth: { status: "authenticated" },
28+
checkedAt: "2026-01-01T00:00:00.000Z",
29+
models: input.models.map((slug, index) => ({
30+
slug,
31+
name: slug,
32+
isCustom: false,
33+
...(index === 0 ? { isDefault: true } : {}),
34+
capabilities: {},
35+
})),
36+
slashCommands: [],
37+
skills: [],
38+
};
39+
}
40+
41+
const claudeAndCodex = [
42+
provider({ instanceId: "codex", driver: "codex", models: ["gpt-5.6"] }),
43+
provider({ instanceId: "claudeAgent", driver: "claudeAgent", models: ["claude-opus-4-8"] }),
44+
];
45+
46+
function present(
47+
providers: ReadonlyArray<ServerProvider>,
48+
overrides: Partial<UnifiedSettings> = {},
49+
) {
50+
const settings = {
51+
...DEFAULT_UNIFIED_SETTINGS,
52+
defaultModelSelection: savedClaude,
53+
...overrides,
54+
};
55+
return resolveDefaultModelSettingsPresentation({
56+
entries: providerInstanceEntriesFor(providers, settings, null),
57+
providers,
58+
settings,
59+
projectId: null,
60+
});
61+
}
62+
63+
const claudeOff: Partial<UnifiedSettings> = {
64+
providerInstances: {
65+
[claudeId]: { driver: ProviderDriverKind.make("claudeAgent"), enabled: false },
66+
},
67+
};
68+
69+
describe("resolveDefaultModelSettingsPresentation", () => {
70+
it("keeps the saved model and explains why when its provider cannot run", () => {
71+
const withoutClaude = claudeAndCodex.filter((entry) => entry.instanceId !== claudeId);
72+
const claudeUnavailable = claudeAndCodex.map((entry) =>
73+
entry.instanceId === claudeId ? { ...entry, availability: "unavailable" as const } : entry,
74+
);
75+
// Settings turn Claude off before the server snapshot reflects it.
76+
expect(present(claudeAndCodex, claudeOff)).toEqual({
77+
selection: savedClaude,
78+
providerNote: "Claude is turned off.",
79+
});
80+
expect(present(claudeUnavailable)).toEqual({
81+
selection: savedClaude,
82+
providerNote: "Claude is unavailable.",
83+
});
84+
expect(present(withoutClaude)).toEqual({
85+
selection: savedClaude,
86+
providerNote: "This provider is not available on this environment.",
87+
});
88+
});
89+
90+
it("leaves effort editable when the saved provider can run", () => {
91+
expect(present(claudeAndCodex)).toEqual({ selection: savedClaude, providerNote: null });
92+
});
93+
94+
it("still follows a hidden model on the same provider", () => {
95+
const row = present(
96+
[
97+
provider({
98+
instanceId: "claudeAgent",
99+
driver: "claudeAgent",
100+
models: ["claude-sonnet-5", "claude-opus-4-8"],
101+
}),
102+
],
103+
{
104+
providerModelPreferences: {
105+
[claudeId]: { hiddenModels: ["claude-opus-4-8"], modelOrder: [] },
106+
},
107+
},
108+
);
109+
expect(row.providerNote).toBeNull();
110+
expect(row.selection).toMatchObject({ instanceId: claudeId, model: "claude-sonnet-5" });
111+
});
112+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { ModelSelection, ProjectId, ServerProvider } from "@t3tools/contracts";
2+
import type { UnifiedSettings } from "@t3tools/contracts/settings";
3+
4+
import { resolveEffectiveDefaultModelSelection } from "../../modelSelection";
5+
import {
6+
resolveDefaultProviderModelSelection,
7+
resolveProjectDefaultProviderModelSelection,
8+
type ProviderInstanceEntry,
9+
} from "../../providerInstances";
10+
11+
export interface DefaultModelSettingsPresentation {
12+
readonly selection: ModelSelection | null;
13+
/** Set when the saved model's provider cannot run; effort stays hidden until it can. */
14+
readonly providerNote: string | null;
15+
}
16+
17+
export function resolveDefaultModelSettingsPresentation(input: {
18+
readonly entries: ReadonlyArray<ProviderInstanceEntry>;
19+
readonly providers: ReadonlyArray<ServerProvider>;
20+
readonly settings: UnifiedSettings;
21+
readonly projectId: ProjectId | null;
22+
}): DefaultModelSettingsPresentation {
23+
const saved = input.settings.defaultModelSelection;
24+
if (saved === null) {
25+
const automatic = resolveProjectDefaultProviderModelSelection(
26+
input.providers,
27+
input.settings,
28+
input.projectId,
29+
);
30+
return {
31+
selection: automatic
32+
? resolveEffectiveDefaultModelSelection(input.settings, input.providers, automatic)
33+
: null,
34+
providerNote: null,
35+
};
36+
}
37+
38+
const savedEntry = input.entries.find((entry) => entry.instanceId === saved.instanceId);
39+
const resolved = resolveDefaultProviderModelSelection(input.providers, saved);
40+
// Settings can turn a provider off before the server snapshot catches up, so check both.
41+
if (
42+
!savedEntry?.enabled ||
43+
!savedEntry.isAvailable ||
44+
resolved?.instanceId !== saved.instanceId
45+
) {
46+
return { selection: saved, providerNote: providerNote(savedEntry) };
47+
}
48+
return {
49+
selection: resolveEffectiveDefaultModelSelection(input.settings, input.providers, resolved),
50+
providerNote: null,
51+
};
52+
}
53+
54+
function providerNote(entry: ProviderInstanceEntry | undefined): string {
55+
if (!entry) return "This provider is not available on this environment.";
56+
if (!entry.enabled) return `${entry.displayName} is turned off.`;
57+
return `${entry.displayName} is unavailable.`;
58+
}

‎apps/web/src/components/settings/ProjectDefaultsSettings.tsx‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ import { useClientSettings } from "../../hooks/useSettings";
1212
import {
1313
defaultModelSelectionsAreMixed,
1414
getCustomModelOptionsByInstance,
15-
resolveEffectiveDefaultModelSelection,
1615
} from "../../modelSelection";
17-
import {
18-
providerInstanceEntriesFor,
19-
resolveDefaultProviderModelSelection,
20-
resolveProjectDefaultProviderModelSelection,
21-
} from "../../providerInstances";
16+
import { providerInstanceEntriesFor } from "../../providerInstances";
2217
import { useEnvironmentProviders, useEnvironments } from "../../state/environments";
2318
import { firstManagedDenial } from "../../state/managedPolicy";
2419
import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
@@ -30,6 +25,7 @@ import { TraitsPicker } from "../chat/TraitsPicker";
3025
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
3126
import { toastManager } from "../ui/toast";
3227
import { Switch } from "../ui/switch";
28+
import { resolveDefaultModelSettingsPresentation } from "./ProjectDefaultsSettings.logic";
3329
import type { ProjectSettingsCategory } from "./ProjectSettingsPanel";
3430
import { searchableSetting } from "./settingsSearch";
3531
import { useSettingsScope } from "./SettingsScopeContext";
@@ -67,14 +63,14 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting
6763
(representative?.serverConfig
6864
? providersByEnvironment.get(representative.environmentId)
6965
: undefined) ?? EMPTY_SERVER_PROVIDERS;
70-
const storedSelection =
71-
settings.defaultModelSelection === null
72-
? resolveProjectDefaultProviderModelSelection(providers, settings, target?.projectId ?? null)
73-
: resolveDefaultProviderModelSelection(providers, settings.defaultModelSelection);
74-
const selection = storedSelection
75-
? resolveEffectiveDefaultModelSelection(settings, providers, storedSelection)
76-
: null;
7766
const entries = providerInstanceEntriesFor(providers, settings, target?.projectId ?? null);
67+
const presentation = resolveDefaultModelSettingsPresentation({
68+
entries,
69+
providers,
70+
settings,
71+
projectId: target?.projectId ?? null,
72+
});
73+
const selection = presentation.selection;
7874
const modelOptions = getCustomModelOptionsByInstance(
7975
settings,
8076
providers,
@@ -146,15 +142,15 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting
146142
status={
147143
mixedModel
148144
? `${automaticModel ? "Automatic defaults differ." : "Defaults differ."} Select one environment or choose a shared model to edit effort.`
149-
: effortDisabledReason
145+
: (presentation.providerNote ?? effortDisabledReason)
150146
}
151147
resetAction={
152148
settings.defaultModelSelection !== null ? (
153149
<SettingResetButton label="default model" onClick={() => setModel(null)} />
154150
) : null
155151
}
156152
control={
157-
selection && activeEntry ? (
153+
selection ? (
158154
<div className="flex min-w-0 flex-wrap items-center justify-end gap-1.5">
159155
<ProviderModelPicker
160156
environmentId={representative?.environmentId ?? null}
@@ -179,7 +175,7 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting
179175
setModel(createModelSelection(instanceId, model))
180176
}
181177
/>
182-
{!mixedModel && !effortDisabledReason ? (
178+
{!mixedModel && !presentation.providerNote && !effortDisabledReason && activeEntry ? (
183179
<TraitsPicker
184180
provider={activeEntry.driverKind}
185181
models={activeEntry.models}

0 commit comments

Comments
 (0)