Skip to content

Commit cba0aa9

Browse files
fix(server): text generation falls back to enabled custom instances
When every built-in default instance was disabled, the machine-level text generation fallback only considered default instance ids, so it kept a disabled Codex selection and branch-name generation spawned `codex exec` on a disabled instance. The fallback now always considers configured instances of text-generation-capable drivers after the defaults, so outcomes only change when no default instance qualifies. Every caller now wants this, so the `includeConfiguredInstances` option is removed. Fixes #28906 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 56bb966 commit cba0aa9

4 files changed

Lines changed: 23 additions & 48 deletions

File tree

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,20 @@ export const make = Effect.gen(function* () {
103103
),
104104
);
105105
selection =
106-
fallbackTextGenerationModelSelection(
107-
settings.providerInstances,
108-
(instanceId, driver) => {
109-
const provider = snapshots.find((candidate) => candidate.instanceId === instanceId);
110-
return (
111-
instanceId !== selection.instanceId &&
112-
provider?.enabled === true &&
113-
resolveProjectProviderInstanceEnabled(settings, null, instanceId) &&
114-
provider.installed &&
115-
provider.auth.status !== "unauthenticated" &&
116-
isProviderAvailable(provider) &&
117-
isProviderTextGenerationCapable(provider) &&
118-
(operation !== "generateReviewGuide" || INVESTIGATING_DRIVERS.has(driver)) &&
119-
!exhaustedUsageWindow(provider, now, defaultTextGenerationModel(driver))
120-
);
121-
},
122-
{ includeConfiguredInstances: true },
123-
) ?? selection;
106+
fallbackTextGenerationModelSelection(settings.providerInstances, (instanceId, driver) => {
107+
const provider = snapshots.find((candidate) => candidate.instanceId === instanceId);
108+
return (
109+
instanceId !== selection.instanceId &&
110+
provider?.enabled === true &&
111+
resolveProjectProviderInstanceEnabled(settings, null, instanceId) &&
112+
provider.installed &&
113+
provider.auth.status !== "unauthenticated" &&
114+
isProviderAvailable(provider) &&
115+
isProviderTextGenerationCapable(provider) &&
116+
(operation !== "generateReviewGuide" || INVESTIGATING_DRIVERS.has(driver)) &&
117+
!exhaustedUsageWindow(provider, now, defaultTextGenerationModel(driver))
118+
);
119+
}) ?? selection;
124120
}
125121
return yield* resolveInstance(registry, operation, selection.instanceId).pipe(
126122
Effect.flatMap((service) => invoke(service, selection)),

‎packages/shared/src/projectSettings.ts‎

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

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("fallbackTextGenerationModelSelection", () => {
5656
applyServerSettingsPatch(settings, { fallbackModelSelection: null }).fallbackModelSelection,
5757
).toBeNull();
5858
});
59-
it("ignores a configured non-default instance at machine scope, matching no fallback", () => {
59+
it("falls back to a configured non-default instance", () => {
6060
const configured = ProviderInstanceId.make("codex_work");
6161
const providerInstances = {
6262
[configured]: { driver: ProviderDriverKind.make("codex"), config: {} },
@@ -65,19 +65,6 @@ describe("fallbackTextGenerationModelSelection", () => {
6565
providerInstances,
6666
(instanceId) => instanceId === configured,
6767
);
68-
expect(fallback).toBeNull();
69-
});
70-
71-
it("considers a configured non-default instance only when asked to", () => {
72-
const configured = ProviderInstanceId.make("codex_work");
73-
const providerInstances = {
74-
[configured]: { driver: ProviderDriverKind.make("codex"), config: {} },
75-
};
76-
const fallback = fallbackTextGenerationModelSelection(
77-
providerInstances,
78-
(instanceId) => instanceId === configured,
79-
{ includeConfiguredInstances: true },
80-
);
8168
expect(fallback?.instanceId).toBe(configured);
8269
});
8370
});

‎packages/shared/src/serverSettings.ts‎

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

63-
/** Only project-scoped callers may include configured instances when falling back; machine-level callers leave it unset. */
63+
/** Configured instances come after every default instance, so they only win when no default qualifies. */
6464
export function fallbackTextGenerationModelSelection(
6565
providerInstances: ServerSettings["providerInstances"],
6666
isEnabled: (instanceId: ProviderInstanceId, driver: ProviderDriverKind) => boolean,
67-
options?: {
68-
readonly includeConfiguredInstances?: boolean;
69-
readonly defaultModelSelection?: ModelSelection | null;
70-
},
67+
options?: { readonly defaultModelSelection?: ModelSelection | null },
7168
): ModelSelection | null {
7269
const candidates = [
7370
...TEXT_GENERATION_FALLBACK_DRIVERS.map(
7471
(driver) => [defaultInstanceIdForDriver(driver), driver] as const,
7572
),
76-
...(options?.includeConfiguredInstances === true
77-
? Object.entries(providerInstances).flatMap(([instanceId, instance]) =>
78-
TEXT_GENERATION_FALLBACK_DRIVERS.includes(instance.driver)
79-
? [[ProviderInstanceId.make(instanceId), instance.driver] as const]
80-
: [],
81-
)
82-
: []),
73+
...Object.entries(providerInstances).flatMap(([instanceId, instance]) =>
74+
TEXT_GENERATION_FALLBACK_DRIVERS.includes(instance.driver)
75+
? [[ProviderInstanceId.make(instanceId), instance.driver] as const]
76+
: [],
77+
),
8378
];
8479
const match = candidates.find(([instanceId, driver]) => isEnabled(instanceId, driver));
8580
if (match === undefined) return null;

0 commit comments

Comments
 (0)