From 60c0063301fc126a2328b7061eb6e7f1dc2ce3c4 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 29 Oct 2026 13:30:08 +0000 Subject: [PATCH 1/3] test(server): reproduce #26962 text generation using a missing provider Adds a "not installed" case to the text generation preflight test: the selected Codex instance's snapshot is enabled but installed: false with status "error", while a Claude instance is ready. Generation should go to Claude; on main it still invokes the missing Codex instance. Co-Authored-By: Claude Opus 5.5 --- .../src/textGeneration/CodexTextGeneration.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/server/src/textGeneration/CodexTextGeneration.test.ts b/apps/server/src/textGeneration/CodexTextGeneration.test.ts index 04ae83952b3c4..737a1551a936a 100644 --- a/apps/server/src/textGeneration/CodexTextGeneration.test.ts +++ b/apps/server/src/textGeneration/CodexTextGeneration.test.ts @@ -444,7 +444,9 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => { ); }); -it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhausted) => +const PREFLIGHT_PRIMARY_STATES = ["ready", "exhausted", "not installed"] 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"); @@ -468,7 +470,10 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus models: [], slashCommands: [], skills: [], - ...(exhausted && instanceId === primary + ...(primaryState === "not installed" && instanceId === primary + ? { installed: false, status: "error", auth: { status: "unknown" } } + : {}), + ...(primaryState === "exhausted" && instanceId === primary ? { usageLimits: { checkedAt: "1970-01-01T00:00:00Z", @@ -526,7 +531,7 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus }), ).toEqual({ title: "Generated title" }); expect(calls).toEqual([ - exhausted + primaryState !== "ready" ? { instanceId: fallback, model: From 43d7bf2e2441262ae05df1661d3e6b92c96ce5eb Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 29 Oct 2026 13:36:10 +0000 Subject: [PATCH 2/3] fix(server): text generation falls back when the selected provider's CLI is missing Thread titles and other text generation stayed on the selected provider even when its CLI could not be found, so every attempt failed. The preflight that already switches away from an exhausted usage window now also switches when the selected snapshot is enabled but not installed with an error status. A not-yet-checked (pending) snapshot keeps the selection. Fixes pingdotgg/t3code#26962 Co-Authored-By: Claude Opus 5.5 --- .../src/textGeneration/CodexTextGeneration.test.ts | 7 +++++-- apps/server/src/textGeneration/TextGeneration.ts | 11 +++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/server/src/textGeneration/CodexTextGeneration.test.ts b/apps/server/src/textGeneration/CodexTextGeneration.test.ts index 737a1551a936a..b4d71ef2e9234 100644 --- a/apps/server/src/textGeneration/CodexTextGeneration.test.ts +++ b/apps/server/src/textGeneration/CodexTextGeneration.test.ts @@ -444,7 +444,7 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => { ); }); -const PREFLIGHT_PRIMARY_STATES = ["ready", "exhausted", "not installed"] as const; +const PREFLIGHT_PRIMARY_STATES = ["ready", "pending", "exhausted", "not installed"] as const; it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (primaryState) => Effect.gen(function* () { @@ -470,6 +470,9 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima models: [], slashCommands: [], skills: [], + ...(primaryState === "pending" && instanceId === primary + ? { installed: false, status: "warning", auth: { status: "unknown" } } + : {}), ...(primaryState === "not installed" && instanceId === primary ? { installed: false, status: "error", auth: { status: "unknown" } } : {}), @@ -531,7 +534,7 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima }), ).toEqual({ title: "Generated title" }); expect(calls).toEqual([ - primaryState !== "ready" + primaryState === "exhausted" || primaryState === "not installed" ? { instanceId: fallback, model: diff --git a/apps/server/src/textGeneration/TextGeneration.ts b/apps/server/src/textGeneration/TextGeneration.ts index fc8d0fb68da31..374dcf1921f59 100644 --- a/apps/server/src/textGeneration/TextGeneration.ts +++ b/apps/server/src/textGeneration/TextGeneration.ts @@ -86,12 +86,11 @@ 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); + // A pending snapshot is also not installed, but only a failed probe reports an error. + const missing = + selected?.enabled === true && !selected.installed && selected.status === "error"; + if (missing || exhaustedUsageWindow(selected, now, selection.model)) { const settings = yield* serverSettings.getSettings.pipe( Effect.mapError( (cause) => From 411943c752a8830de71abfec7eaa0173e3cd776a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 29 Oct 2026 13:54:43 +0000 Subject: [PATCH 3/3] fix(server): text generation fallback respects project-disabled providers The fallback for a missing or exhausted text generation provider only checked whether each candidate was enabled machine-wide, so a project's thread title, branch name, commit message, PR content or review guide could go to a provider the user had disabled for that project. Text generation inputs now carry an optional projectId, every caller that knows the project passes it, and the fallback rejects candidates disabled for that project. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/git/GitManager.ts | 5 ++ .../orchestration-v2/ThreadLaunchService.ts | 1 + .../ThreadTitleRegenerationService.ts | 1 + .../PullRequestReviewGuideService.ts | 1 + .../CodexTextGeneration.test.ts | 21 ++++++- .../src/textGeneration/TextGeneration.ts | 57 ++++++++++--------- .../src/server/textGeneration.ts | 6 ++ 7 files changed, 64 insertions(+), 28 deletions(-) diff --git a/apps/server/src/git/GitManager.ts b/apps/server/src/git/GitManager.ts index 53d0b4f5853ff..41427acb01762 100644 --- a/apps/server/src/git/GitManager.ts +++ b/apps/server/src/git/GitManager.ts @@ -113,6 +113,7 @@ export type GitBranchPullRequest = NonNullable & { interface SourceControlTextGenerationSettings { readonly modelSelection: ModelSelection; + readonly projectId: ProjectId | null; readonly style: SourceControlWritingStyleSettings; } @@ -2092,6 +2093,7 @@ export const make = Effect.gen(function* () { ...(input.includeBranch ? { includeBranch: true } : {}), ...(policy ? { policy } : {}), modelSelection: input.settings.modelSelection, + projectId: input.settings.projectId, }) .pipe(Effect.map((result) => sanitizeCommitMessage(result))); @@ -2294,6 +2296,7 @@ export const make = Effect.gen(function* () { ...(threadContext ? { threadContext } : {}), ...(policy ? { policy } : {}), modelSelection: settings.modelSelection, + projectId: settings.projectId, }); const bodyFile = path.join( @@ -3077,6 +3080,7 @@ export const make = Effect.gen(function* () { settings.sourceControlWriterModelSelection === null ? Effect.succeed({ modelSelection: settings.textGenerationModelSelection, + projectId, style: settings.sourceControlWritingStyle, }) : providerRegistry.getProviders.pipe( @@ -3086,6 +3090,7 @@ export const make = Effect.gen(function* () { providers, projectId, ), + projectId, style: settings.sourceControlWritingStyle, })), ), diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.ts index 7a45a54a312f4..56abd5161bfe2 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.ts @@ -360,6 +360,7 @@ const make = Effect.gen(function* () { attachments: message.attachments, ...(message.context ? { context: message.context } : {}), modelSelection, + projectId: input.projectId, }) .pipe( Effect.map((result) => ({ diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts index b73f6a2ab061a..e329edf7e2731 100644 --- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts +++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts @@ -164,6 +164,7 @@ const make = Effect.gen(function* () { ...(inherited === undefined ? {} : { forkSource: inherited }), instructions: settings.threadTitleInstructions, modelSelection: settings.textGenerationModelSelection, + projectId: projection.thread.projectId, }); const generatedTitle = result.title.trim(); return generatedTitle === "New thread" || diff --git a/apps/server/src/pullRequest/PullRequestReviewGuideService.ts b/apps/server/src/pullRequest/PullRequestReviewGuideService.ts index e0dc7309289b6..8ae61b11ccb06 100644 --- a/apps/server/src/pullRequest/PullRequestReviewGuideService.ts +++ b/apps/server/src/pullRequest/PullRequestReviewGuideService.ts @@ -390,6 +390,7 @@ const make = Effect.gen(function* () { ...reviewGuideInputFromPullRequest(detail, activity, checkout.baseCommit), cwd: checkout.path, modelSelection, + projectId: input.projectId, instructions: projectSettings.reviewGuideInstructions, stack: checkout.stack, }), diff --git a/apps/server/src/textGeneration/CodexTextGeneration.test.ts b/apps/server/src/textGeneration/CodexTextGeneration.test.ts index b4d71ef2e9234..a840a8659cea8 100644 --- a/apps/server/src/textGeneration/CodexTextGeneration.test.ts +++ b/apps/server/src/textGeneration/CodexTextGeneration.test.ts @@ -1,5 +1,6 @@ import { DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER, + ProjectId, ProviderDriverKind, type ModelSelection, type ServerProvider, @@ -444,12 +445,20 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => { ); }); -const PREFLIGHT_PRIMARY_STATES = ["ready", "pending", "exhausted", "not installed"] as const; +const PREFLIGHT_PRIMARY_STATES = [ + "ready", + "pending", + "exhausted", + "not installed", + "not installed, fallback disabled for project", +] 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"); + const projectId = ProjectId.make("project-a"); + const primaryMissing = primaryState.startsWith("not installed"); const selection = { instanceId: primary, model: "chat-model", @@ -473,7 +482,7 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima ...(primaryState === "pending" && instanceId === primary ? { installed: false, status: "warning", auth: { status: "unknown" } } : {}), - ...(primaryState === "not installed" && instanceId === primary + ...(primaryMissing && instanceId === primary ? { installed: false, status: "error", auth: { status: "unknown" } } : {}), ...(primaryState === "exhausted" && instanceId === primary @@ -518,6 +527,13 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima providerInstances: { [fallback]: { driver: ProviderDriverKind.make("claudeAgent"), config: {} }, }, + ...(primaryState === "not installed, fallback disabled for project" + ? { + projectSettingsOverrides: { + [projectId]: { providerInstances: { [fallback]: { enabled: false } } }, + }, + } + : {}), }), Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({ resolveLink: () => Effect.die("unused"), @@ -531,6 +547,7 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima message: "hello", linkedContext: "", modelSelection: selection, + projectId, }), ).toEqual({ title: "Generated title" }); expect(calls).toEqual([ diff --git a/apps/server/src/textGeneration/TextGeneration.ts b/apps/server/src/textGeneration/TextGeneration.ts index 374dcf1921f59..84fe9938e359e 100644 --- a/apps/server/src/textGeneration/TextGeneration.ts +++ b/apps/server/src/textGeneration/TextGeneration.ts @@ -1,7 +1,7 @@ import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; -import type { ModelSelection, ProviderInstanceId } from "@t3tools/contracts"; +import type { ModelSelection, ProjectId, ProviderInstanceId } from "@t3tools/contracts"; import { isProviderAvailable, isProviderTextGenerationCapable, @@ -74,7 +74,10 @@ export const make = Effect.gen(function* () { const serverSettings = yield* ServerSettings.ServerSettingsService; const generate = Effect.fn("TextGeneration.generate")(function* ( operation: TextGenerationOp, - selection: ModelSelection, + input: { + readonly modelSelection: ModelSelection; + readonly projectId?: ProjectId | null | undefined; + }, invoke: ( service: ProviderTextGeneration, modelSelection: ModelSelection, @@ -86,6 +89,7 @@ export const make = Effect.gen(function* () { ), ); const now = DateTime.toEpochMillis(yield* DateTime.now); + let selection = input.modelSelection; const selected = snapshots.find((provider) => provider.instanceId === selection.instanceId); // A pending snapshot is also not installed, but only a failed probe reports an error. const missing = @@ -109,7 +113,11 @@ export const make = Effect.gen(function* () { return ( instanceId !== selection.instanceId && provider?.enabled === true && - resolveProjectProviderInstanceEnabled(settings, null, instanceId) && + resolveProjectProviderInstanceEnabled( + settings, + input.projectId ?? null, + instanceId, + ) && provider.installed && provider.auth.status !== "unauthenticated" && isProviderAvailable(provider) && @@ -127,45 +135,42 @@ export const make = Effect.gen(function* () { }); return TextGeneration.of({ generateCommitMessage: Effect.fn("TextGeneration.generateCommitMessage")(function (input) { - return generate("generateCommitMessage", input.modelSelection, (service, modelSelection) => + return generate("generateCommitMessage", input, (service, modelSelection) => service.generateCommitMessage({ ...input, modelSelection }), ); }), generatePrContent: Effect.fn("TextGeneration.generatePrContent")(function (input) { - return generate("generatePrContent", input.modelSelection, (service, modelSelection) => + return generate("generatePrContent", input, (service, modelSelection) => service.generatePrContent({ ...input, modelSelection }), ); }), generateBranchName: Effect.fn("TextGeneration.generateBranchName")(function (input) { - return generate("generateBranchName", input.modelSelection, (service, modelSelection) => + return generate("generateBranchName", input, (service, modelSelection) => service.generateBranchName({ ...input, modelSelection }), ); }), generateReviewGuide: Effect.fn("TextGeneration.generateReviewGuide")(function (input) { - return generate("generateReviewGuide", input.modelSelection, (service, modelSelection) => + return generate("generateReviewGuide", input, (service, modelSelection) => service.generateReviewGuide({ ...input, modelSelection }), ); }), generateThreadTitle: Effect.fn("TextGeneration.generateThreadTitle")(function (input) { - return generate( - "generateThreadTitle", - input.modelSelection, - (textGeneration, modelSelection) => - Effect.gen(function* () { - const linkedContext = - input.linkedContext ?? - (yield* ThreadTitleLinks.resolveThreadTitleLinks(input).pipe( - Effect.provideService( - SourceControlProviderRegistry.SourceControlProviderRegistry, - sourceControl, - ), - )); - return yield* textGeneration.generateThreadTitle({ - ...input, - linkedContext, - modelSelection, - }); - }), + return generate("generateThreadTitle", input, (textGeneration, modelSelection) => + Effect.gen(function* () { + const linkedContext = + input.linkedContext ?? + (yield* ThreadTitleLinks.resolveThreadTitleLinks(input).pipe( + Effect.provideService( + SourceControlProviderRegistry.SourceControlProviderRegistry, + sourceControl, + ), + )); + return yield* textGeneration.generateThreadTitle({ + ...input, + linkedContext, + modelSelection, + }); + }), ); }), }); diff --git a/packages/provider-core/src/server/textGeneration.ts b/packages/provider-core/src/server/textGeneration.ts index 3a80457cad0bf..ff4feaa2d64e8 100644 --- a/packages/provider-core/src/server/textGeneration.ts +++ b/packages/provider-core/src/server/textGeneration.ts @@ -2,6 +2,7 @@ import type { BranchNamingOptions, ChatAttachment, ModelSelection, + ProjectId, PullRequestReviewGuide, TextGenerationError, } from "@t3tools/contracts"; @@ -18,6 +19,7 @@ export interface CommitMessageGenerationInput { includeBranch?: boolean; policy?: TextGenerationPolicy | undefined; modelSelection: ModelSelection; + projectId?: ProjectId | null | undefined; } export interface CommitMessageGenerationResult { @@ -37,6 +39,7 @@ export interface PrContentGenerationInput { threadContext?: string | undefined; policy?: TextGenerationPolicy | undefined; modelSelection: ModelSelection; + projectId?: ProjectId | null | undefined; } export interface PrContentGenerationResult { @@ -50,6 +53,7 @@ export interface BranchNameGenerationInput { message: string; attachments?: ReadonlyArray | undefined; modelSelection: ModelSelection; + projectId?: ProjectId | null | undefined; } export interface BranchNameGenerationResult { @@ -65,6 +69,7 @@ export interface ThreadTitleGenerationInput { attachments?: ReadonlyArray | undefined; instructions?: string | undefined; modelSelection: ModelSelection; + projectId?: ProjectId | null | undefined; } export interface ThreadTitleGenerationResult { @@ -90,6 +95,7 @@ export interface ReviewGuideGenerationInput { instructions?: string | undefined; stack?: ReadonlyArray | undefined; modelSelection: ModelSelection; + projectId?: ProjectId | null | undefined; } export type ReviewGuideGenerationResult = Omit<