Skip to content

Commit 8e82453

Browse files
committed
Let Codex run newly available account models without host credentials
1 parent 0e374f8 commit 8e82453

6 files changed

Lines changed: 111 additions & 4 deletions

File tree

‎extensions/codex/harness.test.ts‎

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

136+
it("lets explicit Codex model discovery run before auth has been prepared", () => {
137+
expect(
138+
harness.supports({
139+
provider: "openai",
140+
modelId: "gpt-future",
141+
requestedRuntime: "codex",
142+
modelProvider: { requestTransportOverrides: "none" },
143+
}),
144+
).toEqual({ supported: true, priority: 100 });
145+
});
146+
136147
it.each([
137148
{
138149
label: "automatic runtime selection",

‎extensions/codex/harness.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export function createCodexAppServerAgentHarness(options: {
141141
provider === "openai" &&
142142
ctx.requestedRuntime === "codex" &&
143143
Boolean(ctx.modelId?.trim()) &&
144-
preparedAuth?.source === "harness" &&
145-
preparedAuth.mode === undefined &&
146-
preparedAuth.requirement === undefined &&
144+
(preparedAuth === undefined || preparedAuth.source === "harness") &&
145+
preparedAuth?.mode === undefined &&
146+
preparedAuth?.requirement === undefined &&
147147
ctx.modelProvider?.api === undefined &&
148148
ctx.modelProvider?.baseUrl === undefined &&
149149
ctx.modelProvider?.azureApiVersion === undefined &&

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@ function resolveCodexForwardCompatModel(ctx: ProviderResolveDynamicModelContext)
333333
maxTokens: OPENAI_CODEX_GPT_54_MAX_TOKENS,
334334
cost: OPENAI_CODEX_GPT_54_MINI_COST,
335335
};
336+
} else if (
337+
ctx.agentRuntimeId === "codex" &&
338+
ctx.authProfileId === undefined &&
339+
ctx.authProfileMode === undefined &&
340+
ctx.providerConfig?.auth === undefined
341+
) {
342+
// Codex owns its account-scoped model catalog. When that catalog is not yet
343+
// available, keep the requested identity intact and let the native runtime
344+
// decide whether the account can actually use it.
345+
templateIds = OPENAI_CODEX_GPT_56_MODEL_IDS;
346+
patch = {
347+
reasoning: true,
348+
input: ["text", "image"],
349+
thinkingLevelMap: OPENAI_CODEX_GPT_56_THINKING_LEVEL_MAP,
350+
compat: {
351+
supportsReasoningEffort: true,
352+
supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
353+
},
354+
};
336355
} else {
337356
return undefined;
338357
}
@@ -371,6 +390,8 @@ function resolveCodexForwardCompatModel(ctx: ProviderResolveDynamicModelContext)
371390
contextWindow: patch?.contextWindow ?? DEFAULT_CONTEXT_TOKENS,
372391
contextTokens: patch?.contextTokens,
373392
maxTokens: patch?.maxTokens ?? DEFAULT_CONTEXT_TOKENS,
393+
...(patch?.thinkingLevelMap ? { thinkingLevelMap: patch.thinkingLevelMap } : {}),
394+
...(patch?.compat ? { compat: patch.compat } : {}),
374395
} as ProviderRuntimeModel)
375396
);
376397
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,55 @@ describe("buildOpenAIProvider", () => {
17231723
).toEqual({ effort: "high", transport: "sse" });
17241724
});
17251725

1726+
it("delegates an unlisted first-party model to its explicitly selected Codex runtime", () => {
1727+
const provider = buildOpenAIProvider();
1728+
const model = provider.resolveDynamicModel?.({
1729+
provider: "openai",
1730+
modelId: "gpt-future",
1731+
modelRegistry: { find: () => null },
1732+
agentRuntimeId: "codex",
1733+
} as never);
1734+
1735+
expect(model).toMatchObject({
1736+
provider: "openai",
1737+
id: "gpt-future",
1738+
api: "openai-chatgpt-responses",
1739+
baseUrl: "https://chatgpt.com/backend-api/codex",
1740+
compat: { supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"] },
1741+
});
1742+
expect(
1743+
provider
1744+
.resolveThinkingProfile?.({
1745+
provider: "openai",
1746+
modelId: "gpt-future",
1747+
agentRuntime: "codex",
1748+
api: model?.api,
1749+
compat: model?.compat,
1750+
} as never)
1751+
?.levels.map((level) => level.id),
1752+
).toContain("max");
1753+
});
1754+
1755+
it("does not invent an unlisted model for authored Platform credentials", () => {
1756+
const provider = buildOpenAIProvider();
1757+
1758+
expect(
1759+
provider.resolveDynamicModel?.({
1760+
provider: "openai",
1761+
modelId: "gpt-future",
1762+
modelRegistry: { find: () => null },
1763+
agentRuntimeId: "codex",
1764+
authProfileId: "openai:platform",
1765+
authProfileMode: "api_key",
1766+
providerConfig: {
1767+
auth: "api-key",
1768+
api: "openai-responses",
1769+
baseUrl: "https://api.openai.com/v1",
1770+
},
1771+
} as never),
1772+
).toBeUndefined();
1773+
});
1774+
17261775
it("restores gpt-5.3-codex-spark only through ChatGPT/Codex OAuth routing", () => {
17271776
const provider = buildOpenAIProvider();
17281777

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,24 @@ describe("provider model route auth", () => {
331331
});
332332
});
333333

334+
it("lets an explicit native owner authenticate its sole compatible route", () => {
335+
expect(
336+
selectProviderModelRouteAuth({
337+
provider: "openai",
338+
resolution: { ...routes, routes: [routes.routes[1]] },
339+
runtimeAuthOwner: { id: "codex" },
340+
sourcePlan: buildProviderModelAuthSourcePlan({ profiles: [] }),
341+
}),
342+
).toEqual({
343+
kind: "deferred",
344+
reason: "runtime-auth-owner",
345+
routeSupport: {
346+
requestTransportOverrides: "none",
347+
runtimePolicy: { compatibleIds: ["openclaw", "codex"] },
348+
},
349+
});
350+
});
351+
334352
it.each([
335353
["Platform", routes.routes[0], profile("openai:chatgpt", "oauth", "ready")],
336354
["subscription", routes.routes[1], profile("openai:platform", "api_key", "ready")],

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,15 @@ export function selectProviderModelRouteAuth(params: {
392392
const runtimeAuthOwnerIsCompatible =
393393
Boolean(normalizedRuntimeAuthOwner) &&
394394
routeSupport.runtimePolicy.compatibleIds.includes(normalizedRuntimeAuthOwner ?? "");
395-
if (params.resolution.routes.length > 1 && runtimeAuthOwnerIsCompatible && !configuredRoute) {
395+
const hostHasNoCredentialToHonor =
396+
params.sourcePlan.kind === "automatic" &&
397+
params.sourcePlan.orderedProfiles.length === 0 &&
398+
params.sourcePlan.fallback === undefined;
399+
if (
400+
runtimeAuthOwnerIsCompatible &&
401+
!configuredRoute &&
402+
(params.resolution.routes.length > 1 || hostHasNoCredentialToHonor)
403+
) {
396404
return { kind: "deferred", reason: "runtime-auth-owner", routeSupport };
397405
}
398406
return reject(

0 commit comments

Comments
 (0)