Skip to content

Commit d70120e

Browse files
committed
Preserve provider instance fallback ids
1 parent 6b8a1a4 commit d70120e

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,17 @@ 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+
});
152165
});

apps/web/src/providerInstances.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ 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;
@@ -220,7 +221,14 @@ export function resolveSelectedProviderInstanceId(input: {
220221
if (byKind) return byKind.instanceId;
221222

222223
const anyEnabled = input.entries.find((entry) => entry.enabled);
223-
return anyEnabled?.instanceId ?? input.entries[0]?.instanceId ?? ProviderInstanceId.make("codex");
224+
const fallbackSelection = input.fallbackInstanceIds?.find((instanceId) => instanceId != null);
225+
return (
226+
anyEnabled?.instanceId ??
227+
input.entries[0]?.instanceId ??
228+
(fallbackSelection
229+
? ProviderInstanceId.make(fallbackSelection)
230+
: ProviderInstanceId.make("codex"))
231+
);
224232
}
225233

226234
/**

0 commit comments

Comments
 (0)