Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions apps/server/src/textGeneration/CodexTextGeneration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER,
ProjectId,
ProviderDriverKind,
type ModelSelection,
Expand Down Expand Up @@ -660,11 +661,13 @@ const PREFLIGHT_PRIMARY_STATES = [
"exhausted",
"not installed",
"not installed, fallback disabled for project",
"not installed, fallback model cannot generate text",
"signed out",
"signed out, fallback failed",
"cannot generate text",
"model cannot generate text",
"disabled",
"disabled, thread default model cannot generate text",
"disabled, fallback disabled for project",
] as const;

Expand Down Expand Up @@ -726,6 +729,21 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
],
}
: {}),
...((primaryState === "not installed, fallback model cannot generate text" ||
primaryState === "disabled, thread default model cannot generate text") &&
instanceId === fallback
? {
models: [
{
slug: threadDefault.model,
name: threadDefault.model,
isCustom: true,
supportsTextGeneration: false,
capabilities: null,
},
],
}
: {}),
...(primaryState.startsWith("disabled") && instanceId === primary
? { enabled: false, status: "disabled" }
: {}),
Expand Down Expand Up @@ -797,7 +815,10 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
cwd: "/tmp",
message: "hello",
linkedContext: "",
modelSelection: selection,
modelSelection:
primaryState === "disabled, thread default model cannot generate text"
? threadDefault
: selection,
projectId,
})
.pipe(Effect.exit);
Expand All @@ -813,7 +834,14 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
primaryState === "not installed, fallback disabled for project" ||
primaryState === "signed out, fallback failed"
? selection
: threadDefault,
: primaryState === "not installed, fallback model cannot generate text" ||
primaryState === "disabled, thread default model cannot generate text"
? {
instanceId: fallback,
model:
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
}
: threadDefault,
]);
}),
);
Expand Down
11 changes: 8 additions & 3 deletions apps/server/src/textGeneration/TextGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,31 @@ export const make = Effect.gen(function* () {
}),
),
);
selection =
const rejected = selection;
const fallbackWhere = (sameInstance: boolean) =>
fallbackTextGenerationModelSelection(
settings.providerInstances,
(instanceId, driver, model) => {
const provider = snapshots.find((candidate) => candidate.instanceId === instanceId);
return (
instanceId !== selection.instanceId &&
(sameInstance ? model !== rejected.model : instanceId !== rejected.instanceId) &&
provider?.enabled === true &&
resolveProjectProviderInstanceEnabled(settings, projectId ?? null, instanceId) &&
provider.installed &&
provider.auth.status !== "unauthenticated" &&
provider.status !== "error" &&
isProviderAvailable(provider) &&
isProviderTextGenerationCapable(provider) &&
provider.models.find((candidate) => candidate.slug === model)
?.supportsTextGeneration !== false &&
(operation !== "generateReviewGuide" || INVESTIGATING_DRIVERS.has(driver)) &&
!exhaustedUsageWindow(provider, now, model)
);
},
{ defaultModelSelection: settings.defaultModelSelection },
) ?? selection;
);
// Another instance first; the rejected instance's other models only when none qualifies.
selection = fallbackWhere(false) ?? fallbackWhere(true) ?? selection;
}
if (textGeneratorCannotRun && selection.instanceId === textGeneratorId) {
return yield* new TextGenerationError({
Expand Down
Loading