Skip to content

Commit 9cb45ec

Browse files
fix(server): text generation falls back to an enabled custom instance instead of a disabled default (pingdotgg#28918)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 1843c93 commit 9cb45ec

4 files changed

Lines changed: 24 additions & 49 deletions

File tree

‎apps/server/src/textGeneration/TextGeneration.ts‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,21 @@ export const make = Effect.gen(function* () {
123123
),
124124
);
125125
selection =
126-
fallbackTextGenerationModelSelection(
127-
settings.providerInstances,
128-
(instanceId, driver) => {
129-
const provider = snapshots.find((candidate) => candidate.instanceId === instanceId);
130-
return (
131-
instanceId !== selection.instanceId &&
132-
provider?.enabled === true &&
133-
resolveProjectProviderInstanceEnabled(settings, projectId ?? null, instanceId) &&
134-
provider.installed &&
135-
provider.auth.status !== "unauthenticated" &&
136-
provider.status !== "error" &&
137-
isProviderAvailable(provider) &&
138-
isProviderTextGenerationCapable(provider) &&
139-
(operation !== "generateReviewGuide" || INVESTIGATING_DRIVERS.has(driver)) &&
140-
!exhaustedUsageWindow(provider, now, defaultTextGenerationModel(driver))
141-
);
142-
},
143-
{ includeConfiguredInstances: true },
144-
) ?? selection;
126+
fallbackTextGenerationModelSelection(settings.providerInstances, (instanceId, driver) => {
127+
const provider = snapshots.find((candidate) => candidate.instanceId === instanceId);
128+
return (
129+
instanceId !== selection.instanceId &&
130+
provider?.enabled === true &&
131+
resolveProjectProviderInstanceEnabled(settings, projectId ?? null, instanceId) &&
132+
provider.installed &&
133+
provider.auth.status !== "unauthenticated" &&
134+
provider.status !== "error" &&
135+
isProviderAvailable(provider) &&
136+
isProviderTextGenerationCapable(provider) &&
137+
(operation !== "generateReviewGuide" || INVESTIGATING_DRIVERS.has(driver)) &&
138+
!exhaustedUsageWindow(provider, now, defaultTextGenerationModel(driver))
139+
);
140+
}) ?? selection;
145141
}
146142
if (textGeneratorCannotRun && selection.instanceId === textGeneratorId) {
147143
return yield* new TextGenerationError({

‎packages/shared/src/projectSettings.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ function resolveProjectOverrides(
156156
const fallback = fallbackTextGenerationModelSelection(
157157
settings.providerInstances,
158158
(instanceId) => resolveProjectProviderInstanceEnabled(settings, projectId, instanceId),
159-
{
160-
includeConfiguredInstances: true,
161-
defaultModelSelection: effective.defaultModelSelection as ModelSelection | null,
162-
},
159+
{ defaultModelSelection: effective.defaultModelSelection as ModelSelection | null },
163160
);
164161
if (fallback !== null) effective.textGenerationModelSelection = fallback;
165162
}

‎packages/shared/src/serverSettings.test.ts‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("fallbackTextGenerationModelSelection", () => {
5858
applyServerSettingsPatch(settings, { fallbackModelSelection: null }).fallbackModelSelection,
5959
).toBeNull();
6060
});
61-
it("ignores a configured non-default instance at machine scope, matching no fallback", () => {
61+
it("falls back to a configured non-default instance", () => {
6262
const configured = ProviderInstanceId.make("codex_work");
6363
const providerInstances = {
6464
[configured]: { driver: ProviderDriverKind.make("codex"), config: {} },
@@ -67,19 +67,6 @@ describe("fallbackTextGenerationModelSelection", () => {
6767
providerInstances,
6868
(instanceId) => instanceId === configured,
6969
);
70-
expect(fallback).toBeNull();
71-
});
72-
73-
it("considers a configured non-default instance only when asked to", () => {
74-
const configured = ProviderInstanceId.make("codex_work");
75-
const providerInstances = {
76-
[configured]: { driver: ProviderDriverKind.make("codex"), config: {} },
77-
};
78-
const fallback = fallbackTextGenerationModelSelection(
79-
providerInstances,
80-
(instanceId) => instanceId === configured,
81-
{ includeConfiguredInstances: true },
82-
);
8370
expect(fallback?.instanceId).toBe(configured);
8471
});
8572
});

‎packages/shared/src/serverSettings.ts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,21 @@ const TEXT_GENERATION_FALLBACK_DRIVERS = [
7070
"antigravity",
7171
].map((driver) => ProviderDriverKind.make(driver));
7272

73-
/** Only project-scoped callers may include configured instances when falling back; machine-level callers leave it unset. */
73+
/** Configured instances come after every default instance, so they only win when no default qualifies. */
7474
export function fallbackTextGenerationModelSelection(
7575
providerInstances: ServerSettings["providerInstances"],
7676
isEnabled: (instanceId: ProviderInstanceId, driver: ProviderDriverKind) => boolean,
77-
options?: {
78-
readonly includeConfiguredInstances?: boolean;
79-
readonly defaultModelSelection?: ModelSelection | null;
80-
},
77+
options?: { readonly defaultModelSelection?: ModelSelection | null },
8178
): ModelSelection | null {
8279
const candidates = [
8380
...TEXT_GENERATION_FALLBACK_DRIVERS.map(
8481
(driver) => [defaultInstanceIdForDriver(driver), driver] as const,
8582
),
86-
...(options?.includeConfiguredInstances === true
87-
? Object.entries(providerInstances).flatMap(([instanceId, instance]) =>
88-
TEXT_GENERATION_FALLBACK_DRIVERS.includes(instance.driver)
89-
? [[ProviderInstanceId.make(instanceId), instance.driver] as const]
90-
: [],
91-
)
92-
: []),
83+
...Object.entries(providerInstances).flatMap(([instanceId, instance]) =>
84+
TEXT_GENERATION_FALLBACK_DRIVERS.includes(instance.driver)
85+
? [[ProviderInstanceId.make(instanceId), instance.driver] as const]
86+
: [],
87+
),
9388
];
9489
const match = candidates.find(([instanceId, driver]) => isEnabled(instanceId, driver));
9590
if (match === undefined) return null;

0 commit comments

Comments
 (0)