Skip to content

Commit 1d547fe

Browse files
Ingwannulidge-jun
authored andcommitted
fix(openai): strip unsupported forward cache options
1 parent 913f844 commit 1d547fe

5 files changed

Lines changed: 90 additions & 23 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ function stripUnsupportedReasoningParams(body: unknown): unknown {
318318
}
319319

320320
/**
321-
* GPT-5.6 replaced the legacy 24-hour retention field with `prompt_cache_options.ttl`, and the
322-
* ChatGPT backend 400s the whole request when the retired field is present (issue #2092).
321+
* GPT-5.6 retired the legacy 24-hour retention field, and the ChatGPT backend 400s the whole
322+
* request when that field is present (issue #2092).
323323
*
324324
* The retired field is NOT translated to the replacement: 5.6 carries a different TTL contract,
325325
* and implicit caching still applies when the caller sent no replacement options. Inventing a
@@ -339,6 +339,18 @@ function stripDeprecatedPromptCacheRetention(body: unknown, modelId: unknown): u
339339
return rest;
340340
}
341341

342+
/**
343+
* Public Responses clients can send `prompt_cache_options`, but the canonical ChatGPT Codex
344+
* backend rejects the top-level field before inference (issue #2765). Custom forward gateways and
345+
* API-key Responses providers own different wire contracts, so the caller applies this only after
346+
* the canonical destination predicate succeeds.
347+
*/
348+
function stripCanonicalForwardPromptCacheOptions(body: unknown): unknown {
349+
if (!isPlainObject(body) || !Object.hasOwn(body, "prompt_cache_options")) return body;
350+
const { prompt_cache_options: _options, ...rest } = body;
351+
return rest;
352+
}
353+
342354
/**
343355
* A false model capability prevents Codex from emitting summary fields after the catalog refresh.
344356
* Strip them here as well so an already-running client with a stale catalog cannot keep sending an
@@ -2001,6 +2013,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
20012013
// third-party forward gateway may still accept it, so this must not be widened.
20022014
if (isCanonicalOpenAiForwardProvider(provider)) {
20032015
outBody = stripDeprecatedPromptCacheRetention(outBody, parsed.modelId);
2016+
outBody = stripCanonicalForwardPromptCacheOptions(outBody);
20042017
outBody = normalizeCanonicalForwardPromptEnvelope(outBody);
20052018
outBody = normalizeCanonicalForwardContinuationEnvelope(outBody);
20062019
}

‎src/compatibility/openai-responses.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const FIXTURE_ID = "openai-codex-forward-gpt56-sol-v1";
99
export const OPENAI_CODEX_FORWARD_GPT56_SOL_MANIFEST = defineCompatibilityManifest({
1010
schemaVersion: 1,
1111
id: "openai.codex-forward.gpt-5-6-sol.responses",
12-
version: "1.2.0",
12+
version: "1.3.0",
1313
subject: {
1414
providerId: "openai",
1515
baseUrl: "https://chatgpt.com/backend-api/codex",
@@ -109,5 +109,13 @@ export const OPENAI_CODEX_FORWARD_GPT56_SOL_MANIFEST = defineCompatibilityManife
109109
limitation: "The field is removed without inventing a replacement prompt_cache_options value.",
110110
evidence: [{ kind: "fixture", id: FIXTURE_ID, assertionIds: ["prompt-cache-retention-removed"] }],
111111
},
112+
{
113+
id: "prompt-cache-options",
114+
feature: "request.prompt_cache_options",
115+
disposition: "unsupported",
116+
summary: "The ChatGPT Codex forward route does not receive public prompt cache options.",
117+
limitation: "The field is removed only for the canonical forward destination; public and custom Responses providers keep it.",
118+
evidence: [{ kind: "fixture", id: FIXTURE_ID, assertionIds: ["prompt-cache-options-removed"] }],
119+
},
112120
],
113121
} as const);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ engine. Direct short-circuits that engine before pool state is read or mutated a
1818
current caller/main-login bearer. Neither mode may fall through to `openai-apikey`, and the API
1919
provider may not fall through to Codex-login credentials.
2020

21+
The two routes also keep separate request-compatibility contracts. The canonical ChatGPT Codex
22+
forward destination removes public `prompt_cache_options` because that backend rejects the field
23+
before inference; `prompt_cache_key` remains supported. `openai-apikey` and noncanonical/custom
24+
Responses destinations preserve caller-provided options because their upstream contracts may
25+
support them.
26+
27+
[Decision Log]
28+
- 목적과 의도: Let public Responses clients use the Codex-login route without one unsupported prompt-cache extension failing the whole turn.
29+
- 기존 구현 및 제약 조건: Parsing already preserves unknown top-level fields in `_rawBody`, and the canonical backend rejects `prompt_cache_options`; API-key and custom providers may accept the same field.
30+
- 검토한 주요 대안: Add the field to the Zod schema; strip it for every Responses provider; translate it to a legacy retention hint; remove it only at the canonical destination boundary.
31+
- 선택한 방식: Keep parser passthrough unchanged and strip the caller field only after `isCanonicalOpenAiForwardProvider` succeeds.
32+
- 다른 대안 대신 이 방식을 선택한 이유: Schema admission does not change `_rawBody`, global stripping would remove supported public API behavior, and translation would invent cache policy.
33+
- 장점, 단점 및 영향: VS Code and other public-shape clients avoid the canonical backend rejection while API-key/custom routes retain their wire options; canonical callers cannot request this cache option through OpenCodex.
34+
2135
Pool affinity preserves the existing `x-codex-parent-thread-id` supplied by ordinary Codex clients.
2236
The parent id is trimmed and bounded under the same 512-byte component limit as the Desktop
2337
fallback. When Codex Desktop omits it or sends an unusable value, the complete bounded `session-id`

‎tests/fixtures/compatibility/openai-codex-forward-gpt56-sol-v1.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"reasoning": { "effort": "low" },
4646
"prompt_cache_key": "project-cache-v1",
4747
"prompt_cache_retention": "24h",
48+
"prompt_cache_options": { "ttl": 3600 },
4849
"tools": [
4950
{
5051
"type": "custom",
@@ -91,7 +92,8 @@
9192
{ "id": "unstored-item-reference-removed", "operator": "absent", "path": "/body/input/1" },
9293
{ "id": "previous-response-id-removed", "operator": "absent", "path": "/body/previous_response_id" },
9394
{ "id": "prompt-cache-key-preserved", "operator": "equals", "path": "/body/prompt_cache_key", "expected": "project-cache-v1" },
94-
{ "id": "prompt-cache-retention-removed", "operator": "absent", "path": "/body/prompt_cache_retention" }
95+
{ "id": "prompt-cache-retention-removed", "operator": "absent", "path": "/body/prompt_cache_retention" },
96+
{ "id": "prompt-cache-options-removed", "operator": "absent", "path": "/body/prompt_cache_options" }
9597
]
9698
},
9799
{

‎tests/openai-responses-passthrough.test.ts‎

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,27 +1754,57 @@ describe("OpenAI Responses passthrough sanitization", () => {
17541754
},
17551755
);
17561756

1757-
test("keeps caller-sent prompt_cache_options while dropping the retired retention", () => {
1758-
const adapter = createResponsesPassthroughAdapter(provider);
1759-
const request = adapter.buildRequest({
1760-
modelId: "gpt-5.6-sol",
1761-
context: { messages: [] },
1762-
stream: true,
1763-
options: {},
1764-
_rawBody: {
1765-
model: "gpt-5.6-sol",
1766-
input: "hi",
1767-
prompt_cache_retention: "24h",
1768-
prompt_cache_options: { ttl: "30m" },
1757+
test.each(["gpt-5.5", "gpt-5.6-luna"])(
1758+
"drops caller-sent prompt_cache_options for canonical forward model %s",
1759+
modelId => {
1760+
const adapter = createResponsesPassthroughAdapter(provider);
1761+
const request = adapter.buildRequest({
1762+
modelId,
1763+
context: { messages: [] },
1764+
stream: true,
1765+
options: {},
1766+
_rawBody: {
1767+
model: modelId,
1768+
input: "hi",
1769+
prompt_cache_options: { ttl: "30m" },
1770+
},
1771+
}, { headers: new Headers({ authorization: "Bearer token" }) });
1772+
const body = JSON.parse(request.body) as { prompt_cache_options?: { ttl?: string } };
1773+
1774+
expect(body.prompt_cache_options).toBeUndefined();
1775+
},
1776+
);
1777+
1778+
test("keeps prompt_cache_options for noncanonical forward and API-key providers", () => {
1779+
for (const configuredProvider of [
1780+
{
1781+
adapter: "openai-responses",
1782+
baseUrl: "https://gateway.example/v1",
1783+
authMode: "forward" as const,
17691784
},
1770-
}, { headers: new Headers({ authorization: "Bearer token" }) });
1771-
const body = JSON.parse(request.body) as {
1772-
prompt_cache_retention?: string;
1773-
prompt_cache_options?: { ttl?: string };
1774-
};
1785+
{
1786+
adapter: "openai-responses",
1787+
baseUrl: "https://api.openai.com/v1",
1788+
authMode: "key" as const,
1789+
apiKey: "test-key",
1790+
},
1791+
]) {
1792+
const adapter = createResponsesPassthroughAdapter(configuredProvider);
1793+
const request = adapter.buildRequest({
1794+
modelId: "gpt-5.6-sol",
1795+
context: { messages: [] },
1796+
stream: true,
1797+
options: {},
1798+
_rawBody: {
1799+
model: "gpt-5.6-sol",
1800+
input: "hi",
1801+
prompt_cache_options: { ttl: "30m" },
1802+
},
1803+
}, { headers: new Headers({ authorization: "Bearer token" }) });
1804+
const body = JSON.parse(request.body) as { prompt_cache_options?: { ttl?: string } };
17751805

1776-
expect(body.prompt_cache_retention).toBeUndefined();
1777-
expect(body.prompt_cache_options).toEqual({ ttl: "30m" });
1806+
expect(body.prompt_cache_options).toEqual({ ttl: "30m" });
1807+
}
17781808
});
17791809

17801810
test("a near-miss model id is not swept up by the gpt-5.6 family match", () => {

0 commit comments

Comments
 (0)