Skip to content

Commit 4acb884

Browse files
committed
fix(codex): stabilize Daybreak wire requests
1 parent 5c303a6 commit 4acb884

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

‎src/server/responses/core.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,30 @@ type CodexPoolAccountRetryResult =
536536
authCtx: Extract<CodexAuthContext, { kind: "pool" | "main-pool" }>;
537537
};
538538

539+
const CODEX_ACCOUNT_GATED_CANONICAL_WIRE_MODELS: ReadonlyMap<string, string> = new Map([
540+
// The authenticated catalog currently advertises Daybreak Blue, while successful responses
541+
// identify the serving model as gpt-5.6-sol. Sending the selector itself is shard-dependent:
542+
// live traffic can receive the exact unsupported-model 400 repeatedly from the same entitled
543+
// account. Keep Daybreak as the admission/catalog identity, but use the stable serving id on
544+
// the credential-bearing wire after entitlement selection has completed.
545+
["gpt-daybreak-blue-latest", "gpt-5.6-sol"],
546+
]);
547+
548+
function applyCodexAccountGatedWireNormalization(parsed: OcxParsedRequest, route: RouteResult): void {
549+
if (!isCanonicalOpenAiForwardProvider(route.provider)) return;
550+
const wireModel = CODEX_ACCOUNT_GATED_CANONICAL_WIRE_MODELS.get(route.modelId);
551+
if (!wireModel) return;
552+
553+
parsed.modelId = wireModel;
554+
if (!parsed._rawBody || typeof parsed._rawBody !== "object") return;
555+
const raw = parsed._rawBody as Record<string, unknown>;
556+
raw.model = wireModel;
557+
// Daybreak's authenticated catalog does not advertise retention support, and the upstream
558+
// rejects this optional Codex hint before model execution. Removing it preserves request
559+
// semantics while avoiding an otherwise terminal pre-stream 400.
560+
delete raw.prompt_cache_retention;
561+
}
562+
539563
/**
540564
* Workspace-denial evidence for a 403, read from the upstream body.
541565
*
@@ -2164,6 +2188,7 @@ async function handleResponsesInner(
21642188
}
21652189

21662190
route.provider = applyCodexAuthContextToProvider(route.provider, authCtx, route.codexAccountMode);
2191+
applyCodexAccountGatedWireNormalization(parsed, route);
21672192
logCtx.provider = route.codexAccountNamespace
21682193
? `${route.providerName}-${route.codexAccountNamespace}`
21692194
: formatCodexProviderForLog(route.providerName, codexLogAccountId(authCtx), config);

‎structure/08_openai-provider-tiers.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ preserving a stale one would block every later migration.
126126
exact rejection and fresh grant before each later send; otherwise ordinary eligible-account
127127
failover applies.
128128

129+
- `gpt-daybreak-blue-latest` remains the catalog and entitlement identity, but the canonical
130+
ChatGPT wire uses `gpt-5.6-sol`, the serving id reported by successful Daybreak responses.
131+
The optional `prompt_cache_retention` hint is removed on this route because Daybreak's
132+
authenticated catalog does not advertise it and upstream rejects it before execution.
133+
134+
[Decision Log]
135+
- 목적과 의도: Preserve the account-gated Daybreak UX while avoiding shard-dependent selector
136+
rejection and the unsupported prompt-cache retention parameter.
137+
- 기존 구현 및 제약 조건: The authenticated roster grants Daybreak, but live successful
138+
responses report `gpt-5.6-sol`; the selector can still fail eight consecutive times.
139+
- 검토한 주요 대안: Increase retries indefinitely, hide Daybreak entirely, or canonicalize only
140+
the credential-bearing wire model after entitlement selection.
141+
- 선택한 방식: Keep Daybreak for visibility and account authorization, then send the stable
142+
serving id and remove only the unsupported optional retention hint.
143+
- 다른 대안 대신 이 방식을 선택한 이유: It keeps fail-closed entitlement checks and avoids
144+
unbounded duplicate requests while preserving the user-facing model choice.
145+
- 장점, 단점 및 영향: Requests become deterministic and cheaper; this relies on the serving id
146+
observed from successful upstream responses and must be revisited if the roster exposes a
147+
first-class wire id later.
148+
129149
[Decision Log]
130150
- 목적과 의도: Prevent account-gated native models from being shown or dispatched through a
131151
ChatGPT account that upstream does not authorize.

‎tests/server-auth.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type PoolRetryHarness = {
163163
model?: string;
164164
path?: "/v1/responses" | "/v1/responses/compact";
165165
callerBearer?: boolean;
166+
extraBody?: Record<string, unknown>;
166167
}) => Promise<Response>;
167168
restoreFetch: () => void;
168169
server: ReturnType<typeof startServer>;
@@ -309,13 +310,14 @@ async function startPoolRetryHarness(
309310
model = POOL_RETRY_MODEL,
310311
path = "/v1/responses",
311312
callerBearer = true,
313+
extraBody = {},
312314
} = {}) => originalGlobalFetch(new URL(path, server.url), {
313315
method: "POST",
314316
headers: {
315317
"content-type": "application/json",
316318
...(callerBearer ? { authorization: "Bearer inbound-token" } : {}),
317319
},
318-
body: JSON.stringify({ model, input: path.endsWith("/compact") ? [] : "hello", stream }),
320+
body: JSON.stringify({ model, input: path.endsWith("/compact") ? [] : "hello", stream, ...extraBody }),
319321
signal,
320322
}),
321323
};
@@ -2142,6 +2144,33 @@ describe("server local API auth", () => {
21422144
}
21432145
});
21442146

2147+
test("#2097: Daybreak keeps its entitlement identity but uses the stable wire model", async () => {
2148+
const model = "gpt-daybreak-blue-latest";
2149+
let upstreamBody: Record<string, unknown> | undefined;
2150+
const harness = await startPoolRetryHarness(
2151+
async (_accountId, request) => {
2152+
upstreamBody = await request.json() as Record<string, unknown>;
2153+
return Response.json({ id: "canonical-wire-success", status: "completed", output: [] });
2154+
},
2155+
{
2156+
secondAccount: false,
2157+
modelRosterByAccount: { "acct-pool-a": ["gpt-5.6-sol", model] },
2158+
},
2159+
);
2160+
try {
2161+
const response = await harness.request({
2162+
model,
2163+
extraBody: { prompt_cache_retention: "24h" },
2164+
});
2165+
expect(response.status).toBe(200);
2166+
expect(upstreamBody?.model).toBe("gpt-5.6-sol");
2167+
expect(upstreamBody).not.toHaveProperty("prompt_cache_retention");
2168+
expect(harness.dispatches).toEqual(["acct-pool-a"]);
2169+
} finally {
2170+
await stopPoolRetryHarness(harness);
2171+
}
2172+
});
2173+
21452174
test("#2097: a confirmed entitled account survives two transient unsupported-model 400s in place", async () => {
21462175
const model = "gpt-daybreak-blue-latest";
21472176
let attempts = 0;

0 commit comments

Comments
 (0)