Skip to content

Commit 7246156

Browse files
committed
Preserve provider instance fallback ids
1 parent d07f560 commit 7246156

5 files changed

Lines changed: 68 additions & 6 deletions

File tree

apps/desktop/src/settings/DesktopClientSettings.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as DesktopClientSettings from "./DesktopClientSettings.ts";
1313

1414
const clientSettings: ClientSettings = {
1515
autoOpenPlanSidebar: false,
16+
codexUsageIndicatorMode: "five-hour",
1617
confirmThreadArchive: true,
1718
confirmThreadDelete: false,
1819
dismissedProviderUpdateNotificationKeys: [],

apps/web/src/components/ChatView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,10 @@ export default function ChatView(props: ChatViewProps) {
12941294
selectedProvider,
12951295
lockedProvider,
12961296
lockedContinuationGroupKey,
1297+
fallbackInstanceIds: [
1298+
activeThread?.modelSelection.instanceId,
1299+
activeProject?.defaultModelSelection?.instanceId,
1300+
],
12971301
});
12981302
const selectedEntry = providerInstanceEntries.find(
12991303
(entry) => entry.instanceId === selectedInstanceId,

apps/web/src/components/chat/ChatComposer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ export const ChatComposer = memo(
635635
selectedProvider,
636636
lockedProvider,
637637
lockedContinuationGroupKey,
638+
fallbackInstanceIds: [
639+
activeThreadModelSelection?.instanceId,
640+
activeProjectDefaultModelSelection?.instanceId,
641+
],
638642
});
639643
}, [
640644
activeProjectDefaultModelSelection?.instanceId,

apps/web/src/providerInstances.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,54 @@ describe("resolveSelectedProviderInstanceId", () => {
149149
}),
150150
).toBe("codex");
151151
});
152+
153+
it("keeps persisted model selections as the last fallback before codex", () => {
154+
const persistedInstanceId = ProviderInstanceId.make("codex_saved");
155+
156+
expect(
157+
resolveSelectedProviderInstanceId({
158+
entries: [],
159+
candidates: [null],
160+
selectedProvider: ProviderDriverKind.make("codex"),
161+
fallbackInstanceIds: [persistedInstanceId],
162+
}),
163+
).toBe(persistedInstanceId);
164+
});
165+
166+
it("falls back instead of returning a disabled explicit selection", () => {
167+
const providers = [
168+
provider({
169+
provider: ProviderDriverKind.make("codex"),
170+
instanceId: "codex_disabled",
171+
enabled: false,
172+
}),
173+
provider({ provider: ProviderDriverKind.make("codex"), instanceId: "codex" }),
174+
];
175+
const entries = deriveProviderInstanceEntries(providers);
176+
177+
expect(
178+
resolveSelectedProviderInstanceId({
179+
entries,
180+
candidates: [ProviderInstanceId.make("codex_disabled")],
181+
selectedProvider: ProviderDriverKind.make("codex"),
182+
}),
183+
).toBe("codex");
184+
});
185+
186+
it("falls back instead of returning an explicit selection outside a lock", () => {
187+
const providers = [
188+
provider({ provider: ProviderDriverKind.make("claudeAgent"), instanceId: "claudeAgent" }),
189+
provider({ provider: ProviderDriverKind.make("codex"), instanceId: "codex" }),
190+
];
191+
const entries = deriveProviderInstanceEntries(providers);
192+
193+
expect(
194+
resolveSelectedProviderInstanceId({
195+
entries,
196+
candidates: [ProviderInstanceId.make("claudeAgent")],
197+
selectedProvider: ProviderDriverKind.make("claudeAgent"),
198+
lockedProvider: ProviderDriverKind.make("codex"),
199+
}),
200+
).toBe("codex");
201+
});
152202
});

apps/web/src/providerInstances.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ export function resolveSelectedProviderInstanceId(input: {
190190
selectedProvider: ProviderDriverKind;
191191
lockedProvider?: ProviderDriverKind | null | undefined;
192192
lockedContinuationGroupKey?: string | null | undefined;
193+
fallbackInstanceIds?: ReadonlyArray<ProviderInstanceId | null | undefined>;
193194
}): ProviderInstanceId {
194195
const lockedProvider = input.lockedProvider ?? null;
195196
const lockedContinuationGroupKey = input.lockedContinuationGroupKey ?? null;
196-
const explicitSelection = input.candidates.find((candidate) => candidate != null);
197197

198198
for (const candidate of input.candidates) {
199199
if (!candidate) continue;
@@ -206,10 +206,6 @@ export function resolveSelectedProviderInstanceId(input: {
206206
return match.instanceId;
207207
}
208208

209-
if (explicitSelection) {
210-
return ProviderInstanceId.make(explicitSelection);
211-
}
212-
213209
const fallbackProvider = lockedProvider ?? input.selectedProvider;
214210
const byKind = input.entries.find(
215211
(entry) =>
@@ -220,7 +216,14 @@ export function resolveSelectedProviderInstanceId(input: {
220216
if (byKind) return byKind.instanceId;
221217

222218
const anyEnabled = input.entries.find((entry) => entry.enabled);
223-
return anyEnabled?.instanceId ?? input.entries[0]?.instanceId ?? ProviderInstanceId.make("codex");
219+
const fallbackSelection = input.fallbackInstanceIds?.find((instanceId) => instanceId != null);
220+
return (
221+
anyEnabled?.instanceId ??
222+
input.entries[0]?.instanceId ??
223+
(fallbackSelection
224+
? ProviderInstanceId.make(fallbackSelection)
225+
: ProviderInstanceId.make("codex"))
226+
);
224227
}
225228

226229
/**

0 commit comments

Comments
 (0)