Skip to content
Closed
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
48 changes: 39 additions & 9 deletions apps/server/src/textGeneration/CodexTextGeneration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ const PREFLIGHT_PRIMARY_STATES = [
"disabled",
"disabled, thread default model cannot generate text",
"disabled, fallback disabled for project",
"project-disabled",
"project-disabled, fallback disabled for project",
"enabled only by another project",
] as const;

it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (primaryState) =>
Expand Down Expand Up @@ -792,15 +795,35 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
driver: ProviderDriverKind.make("claudeAgent"),
config: { customModels: [threadDefault.model] },
},
...(primaryState === "enabled only by another project"
? { [primary]: { driver: ProviderDriverKind.make("codex"), enabled: false } }
: {}),
},
defaultModelSelection: threadDefault,
...(primaryState.endsWith("fallback disabled for project")
? {
projectSettingsOverrides: {
[projectId]: { providerInstances: { [fallback]: { enabled: false } } },
},
}
: {}),
projectSettingsOverrides: {
...(primaryState === "enabled only by another project"
? {
[ProjectId.make("project-b")]: {
providerInstances: { [primary]: { enabled: true } },
},
}
: {}),
...(primaryState.startsWith("project-disabled") ||
primaryState.endsWith("fallback disabled for project")
? {
[projectId]: {
providerInstances: {
...(primaryState.startsWith("project-disabled")
? { [primary]: { enabled: false } }
: {}),
...(primaryState.endsWith("fallback disabled for project")
? { [fallback]: { enabled: false } }
: {}),
},
},
}
: {}),
},
}),
Layer.mock(TextGenerators.TextGenerators)({ runner: () => Effect.undefined }),
Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
Expand All @@ -819,11 +842,18 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
primaryState === "disabled, thread default model cannot generate text"
? threadDefault
: selection,
projectId,
projectId: primaryState === "enabled only by another project" ? null : projectId,
})
.pipe(Effect.exit);
if (primaryState === "disabled, fallback disabled for project") {
if (
primaryState === "disabled, fallback disabled for project" ||
primaryState === "project-disabled, fallback disabled for project"
) {
expect(Exit.isFailure(generated)).toBe(true);
expect(Exit.isFailure(generated) && Cause.squash(generated.cause)).toMatchObject({
_tag: "TextGenerationError",
detail: expect.stringContaining("No text generation provider is available"),
});
expect(calls).toEqual([]);
return;
}
Expand Down
33 changes: 18 additions & 15 deletions apps/server/src/textGeneration/TextGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const make = Effect.gen(function* () {
) => Effect.Effect<A, TextGenerationError>,
) {
const textGenerator = yield* textGenerators.runner(selection.instanceId);
const selectedInstanceId = selection.instanceId;
// A review guide reaches a text generator only through a fallback; it needs an agent instead.
const textGeneratorId = selection.instanceId;
const textGeneratorCannotRun =
textGenerator !== undefined && operation === "generateReviewGuide";
if (textGenerator !== undefined && !textGeneratorCannotRun) {
Expand All @@ -103,8 +103,21 @@ export const make = Effect.gen(function* () {
),
);
const now = DateTime.toEpochMillis(yield* DateTime.now);
const selected = snapshots.find((provider) => provider.instanceId === selection.instanceId);
const selectedDisabled = selected?.enabled === false;
const selected = snapshots.find((provider) => provider.instanceId === selectedInstanceId);
const settings = yield* serverSettings.getSettings.pipe(
Effect.mapError(
(cause) =>
new TextGenerationError({
operation,
detail: "Could not read provider settings.",
cause,
}),
),
);
// A snapshot stays enabled while any project enables its instance, so check settings too.
const selectedDisabled =
selected?.enabled === false ||
!resolveProjectProviderInstanceEnabled(settings, projectId ?? null, selectedInstanceId);
// Only a failed probe counts: a pending one is also not installed yet.
const unusable =
textGeneratorCannotRun ||
Expand All @@ -116,16 +129,6 @@ export const make = Effect.gen(function* () {
(selected.status === "error" &&
(!selected.installed || selected.auth.status === "unauthenticated"))));
if (unusable || exhaustedUsageWindow(selected, now, selection.model)) {
const settings = yield* serverSettings.getSettings.pipe(
Effect.mapError(
(cause) =>
new TextGenerationError({
operation,
detail: "Could not read fallback model settings.",
cause,
}),
),
);
const rejected = selection;
const fallbackWhere = (sameInstance: boolean) =>
fallbackTextGenerationModelSelection(
Expand All @@ -152,14 +155,14 @@ export const make = Effect.gen(function* () {
// Another instance first; the rejected instance's other models only when none qualifies.
selection = fallbackWhere(false) ?? fallbackWhere(true) ?? selection;
}
if (textGeneratorCannotRun && selection.instanceId === textGeneratorId) {
if (textGeneratorCannotRun && selection.instanceId === selectedInstanceId) {
return yield* new TextGenerationError({
operation,
detail:
"Review guides need a coding agent that can read the checkout. None is ready. Pick Codex or Claude as the review guide model in Settings → Source control & issues.",
});
}
if (selectedDisabled && selection.instanceId === selected.instanceId) {
if (selectedDisabled && selection.instanceId === selectedInstanceId) {
return yield* new TextGenerationError({
operation,
detail:
Expand Down
Loading