Skip to content

Commit 4573635

Browse files
authored
Let Codex use newly available account models before catalog refresh (#127394)
* Let Codex run newly available account models without host credentials * Keep authored provider routes ahead of native account authentication * Keep native Codex account discovery consistent with model availability * Preserve advanced reasoning for newly discovered Codex models
1 parent 0b85966 commit 4573635

11 files changed

Lines changed: 171 additions & 4 deletions

‎extensions/codex/harness.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ describe("Codex agent harness supports()", () => {
262262
).toEqual({ supported: true, priority: 100 });
263263
});
264264

265+
it("lets explicit Codex model discovery run before auth has been prepared", () => {
266+
expect(
267+
harness.supports({
268+
provider: "openai",
269+
modelId: "gpt-future",
270+
requestedRuntime: "codex",
271+
modelProvider: { requestTransportOverrides: "none" },
272+
}),
273+
).toEqual({ supported: true, priority: 100 });
274+
});
275+
265276
it.each([
266277
{
267278
label: "automatic runtime selection",

‎extensions/codex/harness.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ export function createCodexAppServerAgentHarness(
210210
provider === "openai" &&
211211
ctx.requestedRuntime === "codex" &&
212212
Boolean(ctx.modelId?.trim()) &&
213-
preparedAuth?.source === "harness" &&
214-
preparedAuth.mode === undefined &&
215-
preparedAuth.requirement === undefined &&
213+
(preparedAuth === undefined || preparedAuth.source === "harness") &&
214+
preparedAuth?.mode === undefined &&
215+
preparedAuth?.requirement === undefined &&
216216
ctx.modelProvider?.api === undefined &&
217217
ctx.modelProvider?.baseUrl === undefined &&
218218
ctx.modelProvider?.azureApiVersion === undefined &&

‎extensions/openai/openai-chatgpt-provider.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ function resolveCodexForwardCompatModel(ctx: ProviderResolveDynamicModelContext)
327327
maxTokens: OPENAI_CODEX_GPT_54_MAX_TOKENS,
328328
cost: OPENAI_CODEX_GPT_54_MINI_COST,
329329
};
330+
} else if (
331+
ctx.agentRuntimeId === "codex" &&
332+
ctx.authProfileId === undefined &&
333+
ctx.authProfileMode === undefined &&
334+
ctx.providerConfig?.auth === undefined
335+
) {
336+
// Codex owns its account-scoped model catalog. When that catalog is not yet
337+
// available, keep the requested identity intact and let the native runtime
338+
// decide whether the account can actually use it.
339+
templateIds = OPENAI_CODEX_GPT_56_MODEL_IDS;
340+
patch = {
341+
reasoning: true,
342+
input: ["text", "image"],
343+
thinkingLevelMap: OPENAI_CODEX_GPT_56_THINKING_LEVEL_MAP,
344+
compat: {
345+
supportsReasoningEffort: true,
346+
supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
347+
},
348+
};
330349
} else {
331350
return undefined;
332351
}
@@ -365,6 +384,8 @@ function resolveCodexForwardCompatModel(ctx: ProviderResolveDynamicModelContext)
365384
contextWindow: patch?.contextWindow ?? DEFAULT_CONTEXT_TOKENS,
366385
contextTokens: patch?.contextTokens,
367386
maxTokens: patch?.maxTokens ?? DEFAULT_CONTEXT_TOKENS,
387+
...(patch?.thinkingLevelMap ? { thinkingLevelMap: patch.thinkingLevelMap } : {}),
388+
...(patch?.compat ? { compat: patch.compat } : {}),
368389
} as ProviderRuntimeModel)
369390
);
370391
}

‎extensions/openai/openai-provider.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,74 @@ describe("buildOpenAIProvider", () => {
17661766
).toEqual({ effort: "high", transport: "sse" });
17671767
});
17681768

1769+
it("delegates an unlisted first-party model to its explicitly selected Codex runtime", () => {
1770+
const provider = buildOpenAIProvider();
1771+
const model = provider.resolveDynamicModel?.({
1772+
provider: "openai",
1773+
modelId: "gpt-future",
1774+
modelRegistry: { find: () => null },
1775+
agentRuntimeId: "codex",
1776+
} as never);
1777+
1778+
expect(model).toMatchObject({
1779+
provider: "openai",
1780+
id: "gpt-future",
1781+
api: "openai-chatgpt-responses",
1782+
baseUrl: "https://chatgpt.com/backend-api/codex",
1783+
compat: { supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"] },
1784+
});
1785+
expect(
1786+
provider
1787+
.resolveThinkingProfile?.({
1788+
provider: "openai",
1789+
modelId: "gpt-future",
1790+
agentRuntime: "codex",
1791+
api: model?.api,
1792+
compat: model?.compat,
1793+
} as never)
1794+
?.levels.map((level) => level.id),
1795+
).toContain("max");
1796+
expect(
1797+
provider
1798+
.resolveThinkingProfile?.({
1799+
provider: "openai",
1800+
modelId: "gpt-future",
1801+
agentRuntime: "codex",
1802+
} as never)
1803+
?.levels.map((level) => level.id),
1804+
).toEqual(expect.arrayContaining(["xhigh", "max"]));
1805+
});
1806+
1807+
it("does not invent an unlisted model for authored Platform credentials", () => {
1808+
const provider = buildOpenAIProvider();
1809+
1810+
expect(
1811+
provider.resolveDynamicModel?.({
1812+
provider: "openai",
1813+
modelId: "gpt-future",
1814+
modelRegistry: { find: () => null },
1815+
agentRuntimeId: "codex",
1816+
authProfileId: "openai:platform",
1817+
authProfileMode: "api_key",
1818+
providerConfig: {
1819+
auth: "api-key",
1820+
api: "openai-responses",
1821+
baseUrl: "https://api.openai.com/v1",
1822+
},
1823+
} as never),
1824+
).toBeUndefined();
1825+
expect(
1826+
provider
1827+
.resolveThinkingProfile?.({
1828+
provider: "openai",
1829+
modelId: "gpt-future",
1830+
agentRuntime: "codex",
1831+
api: "openai-responses",
1832+
} as never)
1833+
?.levels.map((level) => level.id),
1834+
).not.toContain("max");
1835+
});
1836+
17691837
it("restores gpt-5.3-codex-spark only through ChatGPT/Codex OAuth routing", () => {
17701838
const provider = buildOpenAIProvider();
17711839

‎extensions/openai/thinking-policy.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ function buildOpenAIThinkingProfile(params: {
110110
(agentRuntime === "openclaw" ||
111111
agentRuntime === "auto" ||
112112
(agentRuntime === "codex" && codexSupportsUltra));
113+
const nativeCodexNeedsAccountEffortValidation =
114+
agentRuntime === "codex" &&
115+
params.compat?.supportedReasoningEfforts === undefined &&
116+
(params.api === undefined || params.api === "openai-chatgpt-responses") &&
117+
!matchesExactOrPrefix(params.modelId, params.xhighModelIds) &&
118+
!modelId.startsWith("gpt-5.6");
113119
const defaultLevel = isGpt56Variant ? "medium" : undefined;
114120
const fallbackLevels: ProviderThinkingProfile["levels"] = [
115121
...OPENAI_THINKING_BASE_LEVELS,
@@ -118,6 +124,9 @@ function buildOpenAIThinkingProfile(params: {
118124
: []),
119125
...(supportsMax ? [{ id: "max" as const }] : []),
120126
...(supportsUltra ? [{ id: "ultra" as const }] : []),
127+
...(nativeCodexNeedsAccountEffortValidation
128+
? [{ id: "xhigh" as const }, { id: "max" as const }]
129+
: []),
121130
];
122131
const levels =
123132
agentRuntime === "codex" && resolvedCodexEfforts !== undefined

‎src/agents/model-auth-availability.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,15 @@ describe("createModelAuthAvailabilityResolver", () => {
875875
expect(result).not.toHaveProperty("selectedRoute");
876876
});
877877

878+
it("keeps one unconfigured Codex route indeterminate until native account validation", () => {
879+
expect(
880+
evaluate({
881+
resolution: { ...dualRoutes, routes: [subscriptionRoute] },
882+
syntheticAuthProviderRefs: ["codex"],
883+
}),
884+
).toMatchObject({ availability: undefined, evidence: "synthetic" });
885+
});
886+
878887
it("does not let invalid automatic profile evidence block synthetic Codex ownership", () => {
879888
expect(
880889
evaluate({

‎src/agents/model-auth-availability.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,10 @@ export function createModelAuthAvailabilityResolver(
11061106
sourcePlan,
11071107
configuredAuthMode: automaticRouteAuthMode,
11081108
...(syntheticCodexOwnsAuth ? { runtimeAuthOwner: { id: "codex" } } : {}),
1109+
...(syntheticCodexOwnsAuth &&
1110+
resolveMergedModelProviderConfig(params.cfg, provider) === undefined
1111+
? { allowNativeAuthOnSingleRoute: true }
1112+
: {}),
11091113
});
11101114
if (routeAuthDecision.kind === "deferred" && syntheticCodexOwnsAuth) {
11111115
return { availability: undefined, routeResolution, evidence: "synthetic" };

‎src/agents/openai-model-routes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function selectOpenAIModelRouteAuth(params: {
5959
sourcePlan: ProviderModelAuthSourcePlan;
6060
configuredAuthMode?: string;
6161
runtimeAuthOwner?: { id: string };
62+
allowNativeAuthOnSingleRoute?: boolean;
6263
}) {
6364
return selectProviderModelRouteAuth({ provider: OPENAI_PROVIDER_ID, ...params });
6465
}

‎src/agents/provider-model-route-auth.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,36 @@ describe("provider model route auth", () => {
336336
});
337337
});
338338

339+
it("lets an explicit native owner authenticate its sole compatible route", () => {
340+
expect(
341+
selectProviderModelRouteAuth({
342+
provider: "openai",
343+
resolution: { ...routes, routes: [routes.routes[1]] },
344+
runtimeAuthOwner: { id: "codex" },
345+
allowNativeAuthOnSingleRoute: true,
346+
sourcePlan: buildProviderModelAuthSourcePlan({ profiles: [] }),
347+
}),
348+
).toEqual({
349+
kind: "deferred",
350+
reason: "runtime-auth-owner",
351+
routeSupport: {
352+
requestTransportOverrides: "none",
353+
runtimePolicy: { compatibleIds: ["openclaw", "codex"] },
354+
},
355+
});
356+
});
357+
358+
it("does not infer native ownership for an explicitly authored single route", () => {
359+
expect(
360+
selectProviderModelRouteAuth({
361+
provider: "openai",
362+
resolution: { ...routes, routes: [routes.routes[1]] },
363+
runtimeAuthOwner: { id: "codex" },
364+
sourcePlan: buildProviderModelAuthSourcePlan({ profiles: [] }),
365+
}),
366+
).toMatchObject({ kind: "rejected", reason: "configured-auth" });
367+
});
368+
339369
it.each([
340370
["Platform", routes.routes[0], profile("openai:chatgpt", "oauth", "ready")],
341371
["subscription", routes.routes[1], profile("openai:platform", "api_key", "ready")],

‎src/agents/provider-model-route-auth.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export function selectProviderModelRouteAuth(params: {
285285
configuredAuthMode?: string;
286286
/** Explicit native auth owner allowed to defer an otherwise unowned route. */
287287
runtimeAuthOwner?: { id: string };
288+
/** True only when no provider transport or credentials were authored. */
289+
allowNativeAuthOnSingleRoute?: boolean;
288290
}): ProviderModelRouteAuthDecision {
289291
const requiredProfile =
290292
params.sourcePlan.kind === "required" && params.sourcePlan.source.kind === "profile"
@@ -412,7 +414,16 @@ export function selectProviderModelRouteAuth(params: {
412414
const runtimeAuthOwnerIsCompatible =
413415
Boolean(normalizedRuntimeAuthOwner) &&
414416
routeSupport.runtimePolicy.compatibleIds.includes(normalizedRuntimeAuthOwner ?? "");
415-
if (params.resolution.routes.length > 1 && runtimeAuthOwnerIsCompatible && !configuredRoute) {
417+
const hostHasNoCredentialToHonor =
418+
params.allowNativeAuthOnSingleRoute === true &&
419+
params.sourcePlan.kind === "automatic" &&
420+
params.sourcePlan.orderedProfiles.length === 0 &&
421+
params.sourcePlan.fallback === undefined;
422+
if (
423+
runtimeAuthOwnerIsCompatible &&
424+
!configuredRoute &&
425+
(params.resolution.routes.length > 1 || hostHasNoCredentialToHonor)
426+
) {
416427
return { kind: "deferred", reason: "runtime-auth-owner", routeSupport };
417428
}
418429
return reject(

0 commit comments

Comments
 (0)