fix(codex): preserve qualified model ids in selection and generation (#9921)

This commit is contained in:
maria authored and GitHub committed 2026-09-11 20:25:59 -03:00
1 parent cd64ad384e
commit a92161a050
8 files changed
+128 -14

No files matched your search

@@ -186,7 +186,6 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
environment: processEnv,
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
});
const textGeneration = yield* makeCodexTextGeneration(effectiveConfig, processEnv);
// Build a managed snapshot whose settings never change — mutations come
// in as instance rebuilds from the registry rather than in-place
@@ -242,6 +241,11 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
}),
),
);
const textGeneration = yield* makeCodexTextGeneration(
effectiveConfig,
processEnv,
snapshot.getSnapshot.pipe(Effect.map((value) => value.models)),
);
const snapshotForCwd = (cwd: string) =>
!effectiveConfig.enabled
? snapshot.getSnapshot
@@ -127,6 +127,23 @@ it("prefers sol over terra when both are available", () => {
assert.deepStrictEqual(models.find((model) => model.isDefault)?.slug, "gpt-5.6-sol");
});
it("ranks qualified Codex models while preserving their wire ids", () => {
const models = applyPreferredCodexDefaultModel([
{
slug: "openai.gpt-5.6-luna",
name: "Luna",
isCustom: false,
isDefault: true,
capabilities: null,
},
{ slug: "openai.gpt-5.6-sol", name: "Sol", isCustom: false, capabilities: null },
]);
assert.deepStrictEqual(
models.filter((model) => model.isDefault).map((model) => model.slug),
["openai.gpt-5.6-sol"],
);
});
it("keeps Codex's own default when no preferred model is available", () => {
const models = applyPreferredCodexDefaultModel([
{ slug: "gpt-5.5", name: "GPT-5.5", isCustom: false, capabilities: null },
@@ -25,7 +25,11 @@ import type {
} from "@t3tools/contracts";
import { PREFERRED_DEFAULT_CODEX_MODELS, ServerSettingsError } from "@t3tools/contracts";
import { createModelCapabilities, readCustomModelEntries } from "@t3tools/shared/model";
import {
codexModelFamily,
createModelCapabilities,
readCustomModelEntries,
} from "@t3tools/shared/model";
import { resolveSpawnCommand } from "@t3tools/shared/shell";
import { codexAppServerArgs, resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
import {
@@ -232,9 +236,9 @@ function parseCodexModelListResponse(
export function applyPreferredCodexDefaultModel(
models: ReadonlyArray<ServerProviderModel>,
): ReadonlyArray<ServerProviderModel> {
const preferredSlug = PREFERRED_DEFAULT_CODEX_MODELS.find((slug) =>
models.some((model) => model.slug === slug && !model.isCustom),
);
const preferredSlug = PREFERRED_DEFAULT_CODEX_MODELS.flatMap((slug) =>
models.filter((model) => !model.isCustom && codexModelFamily(model.slug) === slug),
)[0]?.slug;
if (!preferredSlug) {
return models;
}
@@ -38,6 +38,20 @@ const model = (overrides: Partial<ServerProviderModel>): ServerProviderModel =>
});
describe("classifyModels", () => {
it("classifies qualified Codex families without changing their wire ids", () => {
const manifest: ModelManifestData = { version: 1, currentModels: { codex: ["gpt-test"] } };
const models = [
model({ slug: "openai.gpt-test", isLegacy: true }),
model({ slug: "openai.gpt-old" }),
];
assert.deepStrictEqual(
classifyModels(models, manifest, CODEX).map((entry) => [entry.slug, entry.isLegacy ?? false]),
[
["openai.gpt-test", false],
["openai.gpt-old", true],
],
);
});
it("flags non-current models, clears stale flags, and skips custom models", () => {
const manifest: ModelManifestData = {
version: 1,
@@ -64,6 +78,21 @@ describe("classifyModels", () => {
});
describe("applyManifestDefault", () => {
it("resolves the manifest default to the qualified live model", () => {
const manifest: ModelManifestData = {
version: 1,
currentModels: {},
providers: { codex: { models: [], profiles: {}, defaults: { chat: "gpt-test" } } },
};
const models = [
model({ slug: "openai.gpt-old", isDefault: true }),
model({ slug: "openai.gpt-test" }),
];
assert.strictEqual(
applyManifestDefault(models, manifest, CODEX).find((entry) => entry.isDefault)?.slug,
"openai.gpt-test",
);
});
it("moves the default flag and its aliases to the manifest's chat default", () => {
const driver = ProviderDriverKind.make("antigravity");
const manifest: ModelManifestData = {
+18 -6
View File
@@ -19,6 +19,7 @@ import {
type ProviderDriverKind,
type ServerProviderModel,
} from "@t3tools/contracts";
import { codexModelFamily } from "@t3tools/shared/model";
import * as Clock from "effect/Clock";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
@@ -212,13 +213,15 @@ function isLegacyModel(
driverKind: ProviderDriverKind,
slug: string,
): boolean {
const catalogModel = manifest.providers?.[driverKind]?.models.find(
(model) => model.slug === slug,
);
const family = driverKind === "codex" ? codexModelFamily(slug) : slug;
const catalog = manifest.providers?.[driverKind]?.models;
const catalogModel =
catalog?.find((model) => model.slug === slug) ??
catalog?.find((model) => model.slug === family);
if (catalogModel) return catalogModel.status === "legacy";
const currentModels = manifest.currentModels[driverKind];
if (!currentModels) return false;
return !currentModels.includes(slug);
return !currentModels.includes(slug) && !currentModels.includes(family);
}
/**
@@ -260,8 +263,17 @@ export function applyManifestDefault(
manifest: ModelManifestData,
driverKind: ProviderDriverKind,
): ReadonlyArray<ServerProviderModel> {
const slug = manifestDefaultModel(manifest, driverKind);
if (slug === undefined || !models.some((model) => model.slug === slug)) return models;
const requestedSlug = manifestDefaultModel(manifest, driverKind);
if (requestedSlug === undefined) return models;
const slug =
models.find((model) => model.slug === requestedSlug)?.slug ??
(driverKind === "codex"
? models.find(
(model) =>
!model.isCustom && codexModelFamily(model.slug) === codexModelFamily(requestedSlug),
)?.slug
: undefined);
if (slug === undefined) return models;
const previous = models.find((model) => model.isDefault && model.slug !== slug);
if (!previous) return models;
const movedAliases = previous.aliases ?? [];
@@ -134,6 +134,7 @@ function withFakeCodexEnv<A, E, R>(
input: FakeCodexInput & {
launchArgs?: string;
environment?: NodeJS.ProcessEnv;
models?: ReadonlyArray<string>;
},
effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,
) {
@@ -142,12 +143,44 @@ function withFakeCodexEnv<A, E, R>(
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-codex-text-" });
const codexPath = yield* makeFakeCodexBinary(tempDir, input);
const config = decodeCodexSettings({ binaryPath: codexPath, launchArgs: input.launchArgs });
const textGeneration = yield* makeCodexTextGeneration(config, input.environment);
const textGeneration = yield* makeCodexTextGeneration(
config,
input.environment,
Effect.succeed(
(input.models ?? []).map((slug) => ({
slug,
name: slug,
isCustom: false,
capabilities: null,
})),
),
);
return yield* effectFn(textGeneration);
}).pipe(Effect.scoped);
}
it.layer(CodexTextGenerationTestLayer)("CodexTextGeneration", (it) => {
for (const selectedModel of ["gpt-5.6-luna", "openai.gpt-5.6-luna"]) {
it.effect(`dispatches the qualified live model for ${selectedModel}`, () =>
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",
},
(textGeneration) =>
Effect.gen(function* () {
const result = yield* textGeneration.generateThreadTitle({
cwd: process.cwd(),
message: "Describe this change",
modelSelection: createModelSelection(ProviderInstanceId.make("codex"), selectedModel),
});
expect(result.title).toBe("Bedrock title");
}),
),
);
}
it.effect("generates and sanitizes commit messages without branch by default", () =>
withFakeCodexEnv(
{
@@ -11,6 +11,7 @@ import {
type CodexSettings,
DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
type ModelSelection,
type ServerProviderModel,
TextGenerationError,
} from "@t3tools/contracts";
import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git";
@@ -34,7 +35,7 @@ import {
sanitizeThreadTitle,
toJsonSchemaObject,
} from "./TextGenerationUtils.ts";
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
import { codexModelFamily, getModelSelectionStringOptionValue } from "@t3tools/shared/model";
import { getCodexServiceTierOptionValue } from "../codexModelOptions.ts";
const CODEX_TIMEOUT_MS = 180_000;
@@ -46,6 +47,7 @@ const encodeJsonString = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknow
export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(function* (
codexConfig: CodexSettings,
environment?: NodeJS.ProcessEnv,
getModels: Effect.Effect<ReadonlyArray<ServerProviderModel>> = Effect.succeed([]),
) {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
@@ -178,6 +180,14 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
const outputPath = yield* writeTempFile(operation, "codex-output", "");
const runCodexCommand = Effect.fn("runCodexJson.runCodexCommand")(function* () {
const models = yield* getModels;
const requestedModel = modelSelection.model;
const model =
models.find((candidate) => candidate.slug === requestedModel)?.slug ??
models.find(
(candidate) => !candidate.isCustom && codexModelFamily(candidate.slug) === requestedModel,
)?.slug ??
requestedModel;
const launchArgs = resolveCodexLaunchArgs(codexConfig.launchArgs, resolvedEnvironment);
const reasoningEffort =
getModelSelectionStringOptionValue(modelSelection, "reasoningEffort") ??
@@ -193,7 +203,7 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
"-s",
"read-only",
"--model",
modelSelection.model,
model,
"--config",
`model_reasoning_effort="${reasoningEffort}"`,
...(serviceTier ? ["--config", `service_tier="${serviceTier}"`] : []),
+5
View File
@@ -225,6 +225,11 @@ export function isClaudeUltrathinkPrompt(text: string | null | undefined): boole
return typeof text === "string" && /\bultrathink\b/i.test(text);
}
/** Compare Codex model families without changing provider-owned dispatch identifiers. */
export function codexModelFamily(slug: string): string {
return slug.startsWith("openai.gpt-") ? slug.slice("openai.".length) : slug;
}
export function normalizeModelSlug(
model: string | null | undefined,
provider: ProviderDriverKind = DEFAULT_PROVIDER_DRIVER_KIND,