Skip to content

Commit 71128e9

Browse files
committed
fix(codex): gate gpt-5.6 native models by entitlement
Sol/Terra/Luna shipped as static native rows, so an account without upstream entitlement saw them advertised (Codex catalog, Claude gateway discovery, management rows) and every request died upstream with "model is not supported when using Codex with a ChatGPT account", relaid to Claude Code as repeated 502 stream truncations. Add the GPT-5.6 family to ACCOUNT_GATED_NATIVE_OPENAI_MODELS so the existing per-account /models roster evidence gates catalog projection, gateway discovery, and Pool/Direct dispatch — the same mechanism #2097 shipped for Daybreak Blue. Unconfirmed rosters fail closed. Tests reworked to seed rosters where they exercise window/effort/toggle mechanics rather than gating, and to use ungated stand-ins where the slug was only an ordinary-native fixture. Refs #2548
1 parent e1fb675 commit 71128e9

31 files changed

Lines changed: 388 additions & 161 deletions

‎src/codex/catalog/native-models.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export const NATIVE_DAYBREAK_BLUE_MODEL = "gpt-daybreak-blue-latest";
33

44
/** Native ChatGPT/Codex ids whose availability is proven per authenticated account. */
55
export const ACCOUNT_GATED_NATIVE_OPENAI_MODELS: ReadonlySet<string> = new Set([
6+
"gpt-5.6-sol",
7+
"gpt-5.6-terra",
8+
"gpt-5.6-luna",
69
NATIVE_DAYBREAK_BLUE_MODEL,
710
]);
811

@@ -58,8 +61,8 @@ export function nativeOpenAiCapabilitySourceSlug(slug: string): string {
5861
* discover it on a clean install.
5962
*
6063
* Availability is not static: catalog sync and Pool routing require the account's authenticated
61-
* `/models` roster to contain the slug. An unconfirmed or unentitled account never receives the
62-
* request. `disabledModels` remains the independent user visibility control.
64+
* `/models` roster to contain account-gated slugs. An unconfirmed or unentitled account never
65+
* receives the request. `disabledModels` remains the independent user visibility control.
6366
*
6467
* Devlog: 260816_codexrs_multiagent_v2_and_history_perf/011 §4-bis.
6568
*/

‎tests/agent-task-recovery.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ describe("agent task recovery (opt-in, default off)", () => {
540540

541541
const response = await post(
542542
routedConfig(),
543-
"gpt-5.6-sol",
543+
"gpt-5.5",
544544
encryptedInput(),
545545
codexHeaders(),
546546
);

‎tests/bearer-admission-routed-provider.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function mixedConfig(): OcxConfig {
5757
baseUrl: "https://chatgpt.com/backend-api/codex",
5858
authMode: "forward",
5959
codexAccountMode: "direct",
60-
defaultModel: "gpt-5.6-luna",
60+
defaultModel: "gpt-5.5",
6161
},
6262
gateway: {
6363
adapter: "openai-chat",
@@ -153,7 +153,7 @@ describe("#2132 bearer admission does not require a ChatGPT credential for route
153153

154154
const server = startServer(0);
155155
try {
156-
const response = await postResponses(server.url, "gpt-5.6-luna");
156+
const response = await postResponses(server.url, "gpt-5.5");
157157

158158
// This is the #1686 guarantee and it must survive: a native route genuinely needs the
159159
// stored credential, so it fails BEFORE any upstream I/O rather than forwarding ours.
@@ -175,7 +175,7 @@ describe("#2132 bearer admission does not require a ChatGPT credential for route
175175

176176
const server = startServer(0);
177177
try {
178-
const response = await postResponses(server.url, "gpt-5.6-luna");
178+
const response = await postResponses(server.url, "gpt-5.5");
179179

180180
expect(response.status).toBe(200);
181181
expect(nativeAuth).toEqual([`Bearer ${stored}`]);
@@ -213,7 +213,7 @@ describe("an admission bearer never reaches a canonical ChatGPT transport, whate
213213
adapter: "openai-responses",
214214
baseUrl: "https://chatgpt.com/backend-api/codex",
215215
authMode: "forward",
216-
defaultModel: "gpt-5.6-luna",
216+
defaultModel: "gpt-5.5",
217217
},
218218
},
219219
} as OcxConfig;
@@ -225,7 +225,7 @@ describe("an admission bearer never reaches a canonical ChatGPT transport, whate
225225

226226
const server = startServer(0);
227227
try {
228-
const response = await postResponses(server.url, "mirror/gpt-5.6-luna");
228+
const response = await postResponses(server.url, "mirror/gpt-5.5");
229229

230230
// Fail-before-I/O is the contract (src/codex/auth-context.ts): the only two acceptable
231231
// outcomes for an admission bearer are replaced-with-stored-main, or refused. Reaching
@@ -247,7 +247,7 @@ describe("an admission bearer never reaches a canonical ChatGPT transport, whate
247247

248248
const server = startServer(0);
249249
try {
250-
await postResponses(server.url, "mirror/gpt-5.6-luna");
250+
await postResponses(server.url, "mirror/gpt-5.5");
251251

252252
expect(nativeAuth.join("|")).not.toContain(ADMISSION_SECRET);
253253
for (const sent of nativeAuth) expect(sent).toBe(`Bearer ${stored}`);

‎tests/claude-desktop-native-context.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { join } from "node:path";
55
import { buildClaudeDesktopState } from "../src/server/management/shared";
66
import { nativeOpenAiContextWindow, visibleNativeSlugs } from "../src/codex/catalog";
77
import { generateDesktop3pModels } from "../src/claude/desktop-3p";
8+
import {
9+
resetCodexModelEntitlementCacheForTests,
10+
seedCodexModelEntitlementsForTests,
11+
} from "../src/codex/model-entitlements";
812
import type { OcxConfig } from "../src/types";
913

1014
/**
@@ -24,6 +28,8 @@ const config = {
2428
} as unknown as OcxConfig;
2529

2630
test("buildClaudeDesktopState gives native rows their real context window", async () => {
31+
// Sol/Terra/Luna are account-gated; this test is about window metadata, so confirm them.
32+
seedCodexModelEntitlementsForTests("main", ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"]);
2733
const home = tempHome();
2834
const prev = process.env.OPENCODEX_CLAUDE_DESKTOP_CONFIG_DIR;
2935
process.env.OPENCODEX_CLAUDE_DESKTOP_CONFIG_DIR = home;
@@ -44,6 +50,7 @@ test("buildClaudeDesktopState gives native rows their real context window", asyn
4450
if (prev === undefined) delete process.env.OPENCODEX_CLAUDE_DESKTOP_CONFIG_DIR;
4551
else process.env.OPENCODEX_CLAUDE_DESKTOP_CONFIG_DIR = prev;
4652
rmSync(home, { recursive: true, force: true });
53+
resetCodexModelEntitlementCacheForTests();
4754
}
4855
});
4956

‎tests/claude-models-discovery.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import { saveConfig } from "../src/config";
6+
import {
7+
resetCodexModelEntitlementCacheForTests,
8+
} from "../src/codex/model-entitlements";
69
import { handleManagementAPI } from "../src/server/management-api";
710
import { startServer } from "../src/server";
811
import type { OcxConfig } from "../src/types";
@@ -25,6 +28,7 @@ beforeEach(() => {
2528
});
2629

2730
afterEach(() => {
31+
resetCodexModelEntitlementCacheForTests();
2832
if (previousHome === undefined) delete process.env.OPENCODEX_HOME;
2933
else process.env.OPENCODEX_HOME = previousHome;
3034
isolatedCodexHome?.restore();
@@ -159,6 +163,23 @@ test("OpenAI list shape and Codex catalog shape stay unchanged", async () => {
159163
});
160164

161165
test("Codex discovery applies the OpenAI context cap to native rows (#1430)", async () => {
166+
writeFileSync(join(isolatedCodexHome!.path, "auth.json"), JSON.stringify({
167+
tokens: { access_token: "context-cap-access", account_id: "context-cap-account" },
168+
}), "utf8");
169+
const originalFetch = globalThis.fetch;
170+
globalThis.fetch = (async (input, init) => {
171+
const request = new Request(input, init);
172+
const url = new URL(request.url);
173+
if (request.method === "GET" && url.pathname === "/backend-api/codex/models") {
174+
const entitled = request.headers.get("authorization") === "Bearer context-cap-access"
175+
&& request.headers.get("chatgpt-account-id") === "context-cap-account";
176+
const slugs = entitled ? ["gpt-5.6-sol"] : [];
177+
return Response.json({
178+
models: slugs.map(slug => ({ slug, supported_in_api: true, visibility: "list" })),
179+
});
180+
}
181+
return originalFetch(request);
182+
}) as typeof fetch;
162183
const config = configWithStaticModels();
163184
config.providers.openai = {
164185
adapter: "openai-responses",
@@ -186,6 +207,7 @@ test("Codex discovery applies the OpenAI context cap to native rows (#1430)", as
186207
});
187208
} finally {
188209
await server.stop(true);
210+
globalThis.fetch = originalFetch;
189211
}
190212
});
191213

‎tests/codex-auth-api.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3485,7 +3485,7 @@ describe("codex-auth API", () => {
34853485
listOpenAiForwardSidecarCandidates(config),
34863486
new Headers(),
34873487
config,
3488-
{ exactAccount: { accountId: "pool-delete", modelId: "gpt-5.6-sol" } },
3488+
{ exactAccount: { accountId: "pool-delete", modelId: "gpt-5.5" } },
34893489
);
34903490
expect(exactSidecar?.authContext).toMatchObject({
34913491
accountId: "pool-delete",

‎tests/codex-auth-context.test.ts‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ describe("Codex auth context", () => {
450450
});
451451
let discoveries = 0;
452452
await expect(resolveCodexAuthContext(new Headers(), config(), "pool", {
453-
modelId: "gpt-5.6-sol",
453+
modelId: "gpt-5.5",
454454
resolveCodexModelEntitlements: async () => {
455455
discoveries += 1;
456456
throw new Error("must not run");
@@ -479,7 +479,7 @@ describe("Codex auth context", () => {
479479

480480
const exactContext = await resolveCodexAuthContext(headers, cfg, "direct", {
481481
accountId: "pool-a",
482-
modelId: "gpt-5.6-sol",
482+
modelId: "gpt-5.5",
483483
});
484484
expect(exactContext).toMatchObject({
485485
kind: "pool",
@@ -493,7 +493,7 @@ describe("Codex auth context", () => {
493493
_codexAccountOverride: { accessToken: "fixed_pool_token", chatgptAccountId: "fixed_pool_acc" },
494494
});
495495
expect(cfg.activeCodexAccountId).toBe("pool-b");
496-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-sol" }))
496+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.5" }))
497497
.resolves.toMatchObject({ kind: "pool", accountId: "pool-b" });
498498
});
499499

@@ -706,15 +706,15 @@ describe("Codex auth context", () => {
706706

707707
// The pool path honors the order: pool-b outranks pool-a, so an unbound request
708708
// prefers pool-b.
709-
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", { modelId: "gpt-5.6-sol" }))
709+
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", { modelId: "gpt-5.5" }))
710710
.resolves.toMatchObject({ kind: "pool", accountId: "pool-b" });
711711

712712
// An exact selector names pool-a: it must resolve to pool-a even though pool-b is
713713
// ordered earlier. Selection order is a tiebreak inside the eligible pool, never a
714714
// way to redirect a request that already named its account.
715715
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", {
716716
accountId: "pool-a",
717-
modelId: "gpt-5.6-sol",
717+
modelId: "gpt-5.5",
718718
})).resolves.toMatchObject({
719719
kind: "pool",
720720
accountId: "pool-a",
@@ -735,7 +735,7 @@ describe("Codex auth context", () => {
735735

736736
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", {
737737
accountId: MAIN_CODEX_ACCOUNT_ID,
738-
modelId: "gpt-5.6-sol",
738+
modelId: "gpt-5.5",
739739
})).resolves.toMatchObject({
740740
kind: "main-pool",
741741
accountId: MAIN_CODEX_ACCOUNT_ID,
@@ -841,7 +841,7 @@ describe("Codex auth context", () => {
841841
expect(isCodexAuthContextUsable(captured, cfg)).toBe(true);
842842
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", {
843843
accountId: "pool-a",
844-
modelId: "gpt-5.6-sol",
844+
modelId: "gpt-5.5",
845845
})).rejects.toThrow("Selected Codex account is unavailable");
846846
expect(cfg.activeCodexAccountId).toBe("pool-a");
847847
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool"))
@@ -868,7 +868,7 @@ describe("Codex auth context", () => {
868868

869869
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", {
870870
accountId: "pool-a",
871-
modelId: "gpt-5.6-sol",
871+
modelId: "gpt-5.5",
872872
})).rejects.toThrow("Selected Codex account needs reauthentication");
873873
expect(cfg.activeCodexAccountId).toBe("pool-b");
874874
});
@@ -885,7 +885,7 @@ describe("Codex auth context", () => {
885885

886886
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", {
887887
accountId: "pool-a",
888-
modelId: "gpt-5.6-sol",
888+
modelId: "gpt-5.5",
889889
})).rejects.toThrow("Selected Codex account is unavailable");
890890
expect(cfg.activeCodexAccountId).toBe("pool-a");
891891
});
@@ -905,18 +905,18 @@ describe("Codex auth context", () => {
905905
recordCodexUpstreamOutcome(cfg, "pool-a", 429, {
906906
resetAt: Math.floor((now + 60 * 60_000) / 1_000),
907907
now,
908-
modelId: "gpt-5.6-sol",
908+
modelId: "gpt-5.5",
909909
fixedAccount: true,
910910
});
911911
Date.now = () => now + CODEX_QUOTA_PROBE_INTERVAL_MS;
912912

913913
await expect(resolveCodexAuthContext(new Headers(), cfg, "pool", {
914914
accountId: "pool-a",
915-
modelId: "gpt-5.6-sol",
915+
modelId: "gpt-5.5",
916916
})).rejects.toBeInstanceOf(CodexAccountCooldownError);
917917

918918
const ordinaryProbe = await resolveCodexAuthContext(new Headers(), cfg, "pool", {
919-
modelId: "gpt-5.6-sol",
919+
modelId: "gpt-5.5",
920920
});
921921
expect(ordinaryProbe).toMatchObject({ kind: "pool", accountId: "pool-a" });
922922
expect(ordinaryProbe.kind === "pool" ? ordinaryProbe.probeLeaseId : undefined).toBeTruthy();
@@ -1079,20 +1079,20 @@ describe("Codex auth context", () => {
10791079
});
10801080

10811081
// Spark owns a separate quota, so Terra can use the same account.
1082-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-terra" }))
1082+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.4" }))
10831083
.resolves.toMatchObject({ kind: "pool", accountId: "pool-a" });
10841084
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.3-codex-spark" }))
10851085
.rejects.toBeInstanceOf(CodexAccountCooldownError);
10861086

10871087
recordCodexUpstreamOutcome(cfg, "pool-a", 429, {
10881088
now,
10891089
resetAt,
1090-
modelId: "gpt-5.6-terra",
1090+
modelId: "gpt-5.4",
10911091
});
10921092

10931093
// Terra and Luna stay in the shared native quota group, while Spark keeps
10941094
// its independent cooldown instead of being overwritten by Terra's 429.
1095-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-luna" }))
1095+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.4-mini" }))
10961096
.rejects.toBeInstanceOf(CodexAccountCooldownError);
10971097
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.3-codex-spark" }))
10981098
.rejects.toBeInstanceOf(CodexAccountCooldownError);
@@ -1104,7 +1104,7 @@ describe("Codex auth context", () => {
11041104
retryAfter: "60",
11051105
modelId: "gpt-5.3-codex-spark",
11061106
});
1107-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-terra" }))
1107+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.4" }))
11081108
.rejects.toBeInstanceOf(CodexAccountCooldownError);
11091109
} finally {
11101110
Date.now = originalNow;
@@ -1137,7 +1137,7 @@ describe("Codex auth context", () => {
11371137
Date.now = () => now;
11381138
// Establish the shared-scope binding first. The Spark fallback below must
11391139
// create a second binding rather than replacing this one.
1140-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-terra" }))
1140+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.4" }))
11411141
.resolves.toMatchObject({ kind: "pool", accountId: "pool-a" });
11421142

11431143
recordCodexUpstreamOutcome(cfg, "pool-a", 429, {
@@ -1149,7 +1149,7 @@ describe("Codex auth context", () => {
11491149
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.3-codex-spark" }))
11501150
.resolves.toMatchObject({ kind: "pool", accountId: "pool-b" });
11511151
expect(cfg.activeCodexAccountId).toBe("pool-a");
1152-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-terra" }))
1152+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.4" }))
11531153
.resolves.toMatchObject({ kind: "pool", accountId: "pool-a" });
11541154
// This second Spark request proves routing retained the peer choice for
11551155
// the Spark affinity instead of relying on an auth-layer substitution.
@@ -1182,7 +1182,7 @@ describe("Codex auth context", () => {
11821182
recordCodexUpstreamOutcome(cfg, "pool-a", 429, {
11831183
now,
11841184
resetAt,
1185-
modelId: "gpt-5.6-terra",
1185+
modelId: "gpt-5.4",
11861186
});
11871187

11881188
const probeAt = now + CODEX_QUOTA_PROBE_INTERVAL_MS;
@@ -1205,7 +1205,7 @@ describe("Codex auth context", () => {
12051205
Date.now = () => probeAt + 1;
12061206
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.3-codex-spark" }))
12071207
.resolves.toMatchObject({ kind: "pool", accountId: "pool-a" });
1208-
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.6-luna" }))
1208+
await expect(resolveCodexAuthContext(headers, cfg, "pool", { modelId: "gpt-5.4-mini" }))
12091209
.resolves.toMatchObject({ kind: "pool", probeQuotaScope: "shared" });
12101210
} finally {
12111211
Date.now = originalNow;

‎tests/codex-catalog-restore.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ describe("Codex catalog restore", () => {
270270

271271
const r = runScript(codexHome, opencodexHome, `
272272
const { syncCatalogModels } = require("./src/codex/catalog");
273+
const { seedCodexModelEntitlementsForTests } = require("./src/codex/model-entitlements");
274+
seedCodexModelEntitlementsForTests("__main__", ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"]);
273275
(async () => {
274276
const result = await syncCatalogModels({
275277
port: 10100,
@@ -291,6 +293,9 @@ describe("Codex catalog restore", () => {
291293
test("sync advertises documented Codex-native additions omitted by the bundled catalog", () => {
292294
const catalogPath = join(codexHome, "catalog.json");
293295
writeFileSync(join(codexHome, "config.toml"), 'model_catalog_json = "catalog.json"\n', "utf8");
296+
writeFileSync(join(codexHome, "auth.json"), JSON.stringify({
297+
tokens: { access_token: "catalog-main-access", account_id: "catalog-main-account" },
298+
}), "utf8");
294299
writeFileSync(catalogPath, JSON.stringify({
295300
models: [
296301
{
@@ -314,6 +319,19 @@ describe("Codex catalog restore", () => {
314319

315320
const r = runScript(codexHome, opencodexHome, `
316321
const { syncCatalogModels } = require("./src/codex/catalog");
322+
globalThis.fetch = async (input, init) => {
323+
const request = new Request(input, init);
324+
const url = new URL(request.url);
325+
if (request.method !== "GET" || url.pathname !== "/backend-api/codex/models") {
326+
throw new Error("unexpected fetch: " + request.method + " " + url.href);
327+
}
328+
const entitled = request.headers.get("authorization") === "Bearer catalog-main-access"
329+
&& request.headers.get("chatgpt-account-id") === "catalog-main-account";
330+
const slugs = entitled ? ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"] : [];
331+
return Response.json({
332+
models: slugs.map(slug => ({ slug, supported_in_api: true, visibility: "list" })),
333+
});
334+
};
317335
(async () => {
318336
const result = await syncCatalogModels({
319337
port: 10100,

0 commit comments

Comments
 (0)