Skip to content
TypeScript

fix(server): thread titles no longer fail when the text generation provider can't run (#29607)

medric6b84d2caaebb
diff --git a/apps/server/src/textGeneration/CodexTextGeneration.test.ts b/apps/server/src/textGeneration/CodexTextGeneration.test.ts
index 926f17053fb..0c309e99e93 100644
--- a/apps/server/src/textGeneration/CodexTextGeneration.test.ts
+++ b/apps/server/src/textGeneration/CodexTextGeneration.test.ts
@@ -519,7 +519,16 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
);
});
-it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhausted) =>
+const PREFLIGHT_PRIMARY_STATES = [
+ "ready",
+ "pending",
+ "exhausted",
+ "not installed",
+ "signed out",
+ "signed out, fallback failed",
+] as const;
+
+it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (primaryState) =>
Effect.gen(function* () {
const primary = ProviderInstanceId.make("codex");
const fallback = ProviderInstanceId.make("claude_work");
@@ -543,7 +552,19 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus
models: [],
slashCommands: [],
skills: [],
- ...(exhausted && instanceId === primary
+ ...(primaryState === "pending" && instanceId === primary
+ ? { installed: false, status: "warning", auth: { status: "unknown" } }
+ : {}),
+ ...(primaryState === "not installed" && instanceId === primary
+ ? { installed: false, status: "error", auth: { status: "unknown" } }
+ : {}),
+ ...(primaryState.startsWith("signed out") && instanceId === primary
+ ? { status: "error", auth: { status: "unauthenticated" } }
+ : {}),
+ ...(primaryState === "signed out, fallback failed" && instanceId === fallback
+ ? { status: "error", auth: { status: "unknown" } }
+ : {}),
+ ...(primaryState === "exhausted" && instanceId === primary
? {
usageLimits: {
checkedAt: "1970-01-01T00:00:00Z",
@@ -602,13 +623,15 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus
}),
).toEqual({ title: "Generated title" });
expect(calls).toEqual([
- exhausted
- ? {
+ primaryState === "ready" ||
+ primaryState === "pending" ||
+ primaryState === "signed out, fallback failed"
+ ? selection
+ : {
instanceId: fallback,
model:
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
- }
- : selection,
+ },
]);
}),
);
diff --git a/apps/server/src/textGeneration/TextGeneration.ts b/apps/server/src/textGeneration/TextGeneration.ts
index b6f588d5445..ac1aa545250 100644
--- a/apps/server/src/textGeneration/TextGeneration.ts
+++ b/apps/server/src/textGeneration/TextGeneration.ts
@@ -89,12 +89,13 @@ export const make = Effect.gen(function* () {
),
);
const now = DateTime.toEpochMillis(yield* DateTime.now);
- const limited = exhaustedUsageWindow(
- snapshots.find((provider) => provider.instanceId === selection.instanceId),
- now,
- selection.model,
- );
- if (limited) {
+ const selected = snapshots.find((provider) => provider.instanceId === selection.instanceId);
+ // Only a failed probe counts: a pending one is also not installed yet.
+ const unusable =
+ selected?.enabled === true &&
+ 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) =>
@@ -116,6 +117,7 @@ export const make = Effect.gen(function* () {
resolveProjectProviderInstanceEnabled(settings, null, instanceId) &&
provider.installed &&
provider.auth.status !== "unauthenticated" &&
+ provider.status !== "error" &&
isProviderAvailable(provider) &&
isProviderTextGenerationCapable(provider) &&
(operation !== "generateReviewGuide" || INVESTIGATING_DRIVERS.has(driver)) &&