TypeScript
fix(server): Codex titles no longer fail on ChatGPT accounts without gpt-6-luna (#30078)
Muzammil Hussainfba1997db443
diff --git a/apps/server/src/textGeneration/CodexTextGeneration.test.ts b/apps/server/src/textGeneration/CodexTextGeneration.test.tsindex 9dc4f176e30..926f17053fb 100644--- a/apps/server/src/textGeneration/CodexTextGeneration.test.ts+++ b/apps/server/src/textGeneration/CodexTextGeneration.test.ts@@ -163,6 +163,8 @@ function withFakeCodexEnv<A, E, R>(launchArgs?: string;environment?: NodeJS.ProcessEnv;models?: ReadonlyArray<string>;+ defaultModel?: string;+ customModels?: ReadonlyArray<string>;managedRuntime?: boolean;},effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,@@ -171,7 +173,11 @@ function withFakeCodexEnv<A, E, R>(const fs = yield* FileSystem.FileSystem;const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-codex-text-" });const codexPath = yield* makeFakeCodexBinary(tempDir, input);- const config = decodeCodexSettings({ binaryPath: codexPath, launchArgs: input.launchArgs });+ const config = decodeCodexSettings({+ binaryPath: codexPath,+ launchArgs: input.launchArgs,+ customModels: input.customModels,+ });const textGeneration = yield* makeCodexTextGeneration(config,input.environment === undefined ? undefined : { ...process.env, ...input.environment },@@ -180,6 +186,7 @@ function withFakeCodexEnv<A, E, R>(slug,name: slug,isCustom: false,+ ...(slug === input.defaultModel ? { isDefault: true } : {}),capabilities: null,})),),@@ -224,15 +231,40 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {}),);- it.effect.each(["gpt-5.6-luna", "openai.gpt-5.6-luna"])(- "dispatches the qualified live model for %s",- (selectedModel) =>+ it.effect.each([+ {+ selectedModel: "gpt-5.6-luna",+ models: ["openai.gpt-5.6-luna"],+ expected: "openai.gpt-5.6-luna",+ },+ {+ selectedModel: "openai.gpt-5.6-luna",+ models: ["openai.gpt-5.6-luna"],+ expected: "openai.gpt-5.6-luna",+ },+ {+ selectedModel: "openai.gpt-5.6-luna",+ models: ["gpt-6-astra", "gpt-5.6-luna"],+ defaultModel: "gpt-6-astra",+ expected: "gpt-5.6-luna",+ },+ {+ selectedModel: "gpt-6-luna",+ models: ["gpt-5.6-luna", "gpt-6-astra"],+ defaultModel: "gpt-6-astra",+ expected: "gpt-6-astra",+ },+ { selectedModel: "gpt-6-luna", models: ["gpt-5.6-luna"], expected: "gpt-5.6-luna" },+ { selectedModel: "gpt-6-luna", models: [], expected: "gpt-6-luna" },+ ])(+ "dispatches $expected for $selectedModel from $models",+ ({ selectedModel, models, defaultModel, expected }) =>withFakeCodexEnv({- output: JSON.stringify({ title: "Bedrock title" }),- models: ["openai.gpt-5.6-luna"],- requireArg: "--model openai.gpt-5.6-luna",- forbidArg: "--model gpt-5.6-luna",+ output: JSON.stringify({ title: "Live title" }),+ models,+ ...(defaultModel ? { defaultModel } : {}),+ requireArg: `--model ${expected}`,},(textGeneration) =>Effect.gen(function* () {@@ -241,11 +273,54 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {message: "Describe this change",modelSelection: createModelSelection(ProviderInstanceId.make("codex"), selectedModel),});- expect(result.title).toBe("Bedrock title");+ expect(result.title).toBe("Live title");}),),);+ it.effect("drops the requested model's options when falling back to another model", () =>+ withFakeCodexEnv(+ {+ output: JSON.stringify({ title: "Live title" }),+ models: ["gpt-6-astra"],+ requireArg: '--model gpt-6-astra --config model_reasoning_effort="low"',+ forbidArg: 'service_tier="priority"',+ },+ (textGeneration) =>+ textGeneration.generateThreadTitle({+ cwd: process.cwd(),+ message: "Describe this change",+ modelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-6-luna", [+ { id: "reasoningEffort", value: "none" },+ { id: "serviceTier", value: "priority" },+ ]),+ }),+ ),+ );++ it.effect("sends a configured custom model the managed snapshot leaves out", () =>+ withFakeCodexEnv(+ {+ output: JSON.stringify({ title: "Live title" }),+ models: ["gpt-6-astra", "gpt-5.6-luna"],+ defaultModel: "gpt-6-astra",+ customModels: ["gpt-5.6-luna-preview"],+ managedRuntime: true,+ requireArg: '--model gpt-5.6-luna-preview --config model_reasoning_effort="high"',+ },+ (textGeneration) =>+ textGeneration.generateThreadTitle({+ cwd: process.cwd(),+ message: "Describe this change",+ modelSelection: createModelSelection(+ ProviderInstanceId.make("codex"),+ "gpt-5.6-luna-preview",+ [{ id: "reasoningEffort", value: "high" }],+ ),+ }),+ ),+ );+it.effect("omits a persisted service tier for managed ChatGPT text generation", () =>withFakeCodexEnv({diff --git a/apps/server/src/textGeneration/CodexTextGeneration.ts b/apps/server/src/textGeneration/CodexTextGeneration.tsindex e17fa4c4c00..cbf095b303a 100644--- a/apps/server/src/textGeneration/CodexTextGeneration.ts+++ b/apps/server/src/textGeneration/CodexTextGeneration.ts@@ -24,7 +24,11 @@ import {normalizeCliError,toJsonSchemaObject,} from "@t3tools/provider-core/server/textGenerationUtils";-import { codexModelFamily, getModelSelectionStringOptionValue } from "@t3tools/shared/model";+import {+ codexModelFamily,+ getModelSelectionStringOptionValue,+ readCustomModelEntries,+} from "@t3tools/shared/model";import { getCodexServiceTierOptionValue } from "../codexModelOptions.ts";import * as HostProcess from "@t3tools/shared/HostProcess";@@ -245,17 +249,32 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(funcconst effectiveEnvironment = resolved?.environment ?? resolvedEnvironment;const models = yield* getModels;const requestedModel = modelSelection.model;- const model =+ const listed = models.filter((candidate) => !candidate.isCustom);+ // An unlisted slug is one this account can't run, e.g. gpt-6-luna on a ChatGPT login.+ const requestedFamily = codexModelFamily(requestedModel);+ const matchedModel =models.find((candidate) => candidate.slug === requestedModel)?.slug ??- models.find(- (candidate) => !candidate.isCustom && codexModelFamily(candidate.slug) === requestedModel,+ // Managed snapshots omit configured custom models; send those as requested.+ readCustomModelEntries(codexConfig.customModels).find(+ (entry) => entry.slug === requestedModel,)?.slug ??+ listed.find((candidate) => codexModelFamily(candidate.slug) === requestedFamily)?.slug;+ const model =+ matchedModel ??+ listed.find((candidate) => candidate.isDefault)?.slug ??+ listed.find((candidate) => !candidate.isLegacy)?.slug ??+ listed[0]?.slug ??requestedModel;+ // The selection's options were chosen for the requested model and may not fit a fallback.+ const fellBack = matchedModel === undefined && model !== requestedModel;const launchArgs = resolveCodexLaunchArgs(effectiveConfig.launchArgs, effectiveEnvironment);const reasoningEffort =- getModelSelectionStringOptionValue(modelSelection, "reasoningEffort") ??+ (fellBack+ ? undefined+ : getModelSelectionStringOptionValue(modelSelection, "reasoningEffort")) ??DEFAULT_TEXT_GENERATION_REASONING_EFFORT;- const serviceTier = resolved ? undefined : getCodexServiceTierOptionValue(modelSelection);+ const serviceTier =+ resolved || fellBack ? undefined : getCodexServiceTierOptionValue(modelSelection);const binary = effectiveConfig.binaryPath || "codex";const env = {...effectiveEnvironment,