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
21 changes: 16 additions & 5 deletions apps/server/src/textGeneration/CodexTextGeneration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ const PREFLIGHT_PRIMARY_STATES = [
"signed out, fallback failed",
"cannot generate text",
"model cannot generate text",
"disabled",
"disabled, fallback disabled for project",
] as const;

it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (primaryState) =>
Expand Down Expand Up @@ -724,6 +726,9 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
],
}
: {}),
...(primaryState.startsWith("disabled") && instanceId === primary
? { enabled: false, status: "disabled" }
: {}),
...(primaryState === "exhausted" && instanceId === primary
? {
usageLimits: {
Expand Down Expand Up @@ -771,7 +776,7 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
},
},
defaultModelSelection: threadDefault,
...(primaryState === "not installed, fallback disabled for project"
...(primaryState.endsWith("fallback disabled for project")
? {
projectSettingsOverrides: {
[projectId]: { providerInstances: { [fallback]: { enabled: false } } },
Expand All @@ -787,15 +792,21 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
),
),
);
expect(
yield* service.generateThreadTitle({
const generated = yield* service
.generateThreadTitle({
cwd: "/tmp",
message: "hello",
linkedContext: "",
modelSelection: selection,
projectId,
}),
).toEqual({ title: "Generated title" });
})
.pipe(Effect.exit);
if (primaryState === "disabled, fallback disabled for project") {
expect(Exit.isFailure(generated)).toBe(true);
expect(calls).toEqual([]);
return;
}
expect(generated).toEqual(Exit.succeed({ title: "Generated title" }));
expect(calls).toEqual([
primaryState === "ready" ||
primaryState === "pending" ||
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/textGeneration/TextGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ 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;
// Only a failed probe counts: a pending one is also not installed yet.
const unusable =
textGeneratorCannotRun ||
selectedDisabled ||
(selected?.enabled === true &&
(!isProviderTextGenerationCapable(selected) ||
selected.models.find((model) => model.slug === selection.model)
Expand Down Expand Up @@ -152,6 +154,13 @@ export const make = Effect.gen(function* () {
"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) {
return yield* new TextGenerationError({
operation,
detail:
"No text generation provider is available. Enable a provider that can generate text in Settings → Providers.",
});
}
return yield* installationGate.execute(
selection.instanceId,
resolveInstance(registry, operation, selection.instanceId).pipe(
Expand Down
Loading