Skip to content

Commit 613d19d

Browse files
committed
fix(responses): never send prompt_cache_retention to gpt-5.6 models
The ChatGPT codex backend rejects prompt_cache_retention with {"detail":"Unsupported parameter: prompt_cache_retention"} on gpt-5.6 models (gpt-5.6-luna / gpt-5.6-sol), aborting the whole agent turn mid-run. The parameter is emitted client-side by some Codex App builds - it does not exist anywhere in codex-rs - and request bodies are forwarded opaquely, so one bad field kills the turn (#2092). Strip the field on the forward path, scoped to gpt-5.6 model ids: the backend's cache handling is account-level and has provably varied by deployment (one accepted "24h" and echoed it back), so a global strip would silently drop a parameter a deployment honors. Non-gpt-5.6 models keep the existing preserve behavior.
1 parent e97fb26 commit 613d19d

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,28 @@ function stripUnsupportedForwardParams(body: unknown): unknown {
815815
return rest;
816816
}
817817

818+
/**
819+
* The ChatGPT codex backend rejects `prompt_cache_retention` with
820+
* `{"detail":"Unsupported parameter: prompt_cache_retention"}` on gpt-5.6
821+
* models (gpt-5.6-luna / gpt-5.6-sol), aborting the whole agent turn mid-run.
822+
* The parameter is emitted client-side by some Codex App builds - it does not
823+
* exist anywhere in codex-rs - and request bodies are forwarded opaquely, so
824+
* one bad field kills the turn (#2092).
825+
*
826+
* Other models keep the field: the backend's cache handling is account-level
827+
* and has provably varied by deployment (one accepted "24h" and echoed it
828+
* back), so stripping globally would silently drop a parameter a deployment
829+
* honors. Model-scoped, matching the report's invariant: never send it to
830+
* gpt-5.6.
831+
*/
832+
function stripPromptCacheRetentionForGpt56(body: unknown, modelId: string | undefined): unknown {
833+
if (modelId === undefined || !modelId.startsWith("gpt-5.6")) return body;
834+
if (!isPlainObject(body)) return body;
835+
if (!Object.prototype.hasOwnProperty.call(body, "prompt_cache_retention")) return body;
836+
const { prompt_cache_retention: _pcr, ...rest } = body;
837+
return rest;
838+
}
839+
818840
const IMAGE_GEN_NAMESPACE = "image_gen";
819841
const HOSTED_IMAGE_GENERATION_TOOL = "image_generation";
820842
const IMAGE_GEN_DOTTED_PREFIX = `${IMAGE_GEN_NAMESPACE}.`;
@@ -1382,6 +1404,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
13821404
}
13831405
if (forward) {
13841406
outBody = stripUnsupportedForwardParams(outBody);
1407+
outBody = stripPromptCacheRetentionForGpt56(outBody, parsed.modelId);
13851408
} else {
13861409
outBody = preferConfiguredHostedTools(
13871410
outBody,

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,49 @@ describe("OpenAI Responses forward-mode unsupported param stripping", () => {
19821982
expect(body.model).toBe("gpt-5.6-sol");
19831983
});
19841984

1985+
1986+
1987+
test("forward mode strips prompt_cache_retention for gpt-5.6 models (#2092)", () => {
1988+
const adapter = createResponsesPassthroughAdapter(provider);
1989+
for (const modelId of ["gpt-5.6-luna", "gpt-5.6-sol"]) {
1990+
const request = adapter.buildRequest({
1991+
modelId,
1992+
context: { messages: [] },
1993+
stream: true,
1994+
options: {},
1995+
_rawBody: {
1996+
model: modelId,
1997+
input: [{ role: "user", content: [{ type: "input_text", text: "ping" }] }],
1998+
stream: true,
1999+
store: false,
2000+
prompt_cache_retention: "24h",
2001+
},
2002+
}, meta);
2003+
const body = JSON.parse(request.body) as Record<string, unknown>;
2004+
expect(body).not.toHaveProperty("prompt_cache_retention");
2005+
expect(body.model).toBe(modelId);
2006+
}
2007+
});
2008+
2009+
test("forward mode keeps prompt_cache_retention for non-gpt-5.6 models (#2092)", () => {
2010+
const adapter = createResponsesPassthroughAdapter(provider);
2011+
const request = adapter.buildRequest({
2012+
modelId: "gpt-5.5",
2013+
context: { messages: [] },
2014+
stream: true,
2015+
options: {},
2016+
_rawBody: {
2017+
model: "gpt-5.5",
2018+
input: "hi",
2019+
prompt_cache_retention: "24h",
2020+
},
2021+
}, meta);
2022+
const body = JSON.parse(request.body) as Record<string, unknown>;
2023+
// The backend's cache handling varies by deployment and has accepted this
2024+
// field before; only gpt-5.6 provably rejects it, so it stays.
2025+
expect(body.prompt_cache_retention).toBe("24h");
2026+
});
2027+
19852028
test("forward mode is a no-op when neither field is present", () => {
19862029
const adapter = createResponsesPassthroughAdapter(provider);
19872030
const { max_output_tokens: _m, metadata: _d, ...codexBody } = rawBody;

0 commit comments

Comments
 (0)