Skip to content

Commit 3d11f6f

Browse files
olddonkeyclaude
andcommitted
fix(responses): stop reshaping reasoning items that carry encrypted_content
Codex replays the reasoning item it received in the next request's input, and a backend that issued `encrypted_content` verifies what comes back. The content-to-summary channel rewrite deletes `content` and substitutes a synthesized `summary`, so the client stored and replayed an item the issuer had never sent, and every later turn failed with "Could not decrypt the provided encrypted_content. Ensure the value is the unmodified encrypted_content from a previous response." No route change is needed to reach this: it fires on the second turn of a fresh session. The rewrite's replay round trip was verified against DeepSeek, which is `statelessResponses` and issues no blob — its reasoning replay goes through the proxy-side cache instead. Providers that do issue a blob joined the same route later through `preserveReasoningContentModels`, a flag whose own purpose is Chat-wire prompt-cache replay, and the verified premise did not follow them. Only the stored item is exempt. The `reasoning_text` delta events carry no blob and still route to the summary channel, so the expandable trace Codex renders for the live turn is unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 03735ec commit 3d11f6f

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

‎src/server/responses-reasoning-summary-rewrite.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ function reasoningTextOf(item: Record<string, unknown>): string {
3434
/** Move a reasoning item's content channel into the summary channel. */
3535
function reasoningItemToSummaryShape(item: Record<string, unknown>): Record<string, unknown> {
3636
if (item.type !== "reasoning") return item;
37+
// An item carrying `encrypted_content` is replayed verbatim by the client, and the backend that
38+
// issued the blob verifies the item it gets back ("Could not decrypt the provided
39+
// encrypted_content. Ensure the value is the unmodified encrypted_content from a previous
40+
// response."). Reshaping it here is a modification the client then replays on every later turn.
41+
// The delta rewrite still gives Codex the expandable trace for the live turn; only the stored
42+
// shape has to stay exactly as the upstream sent it. DeepSeek — the provider this rewrite was
43+
// verified against — is `statelessResponses` and issues no blob, so it is unaffected.
44+
if (typeof item.encrypted_content === "string" && item.encrypted_content.length > 0) return item;
3745
const text = reasoningTextOf(item);
3846
// Items that already use the summary channel (or carry no content text at
3947
// all) are left untouched: rewriting them could clear a valid summary.

‎structure/04_transports-and-sidecars.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,15 @@ Codex app, so tool cells group like native models — while the text still round
797797
`content[reasoning_text]` shape. Diagnosis and codex-rs grouping evidence:
798798
`devlog/_fin/260709_native_response_pattern/`.
799799

800+
The content-to-summary channel rewrite skips any reasoning item that carries a native
801+
`encrypted_content` blob. Codex replays the reasoning item it received, and a backend that issued
802+
that blob verifies what comes back, so reshaping the stored item makes every later turn fail with
803+
`Could not decrypt the provided encrypted_content`. The rewrite's round trip was verified against
804+
DeepSeek, which is `statelessResponses` and issues no blob; providers that do issue one joined the
805+
same route later through `preserveReasoningContentModels`. Only the stored item is exempt — the
806+
`reasoning_text` delta events carry no blob and still route to the summary channel, so the live
807+
expandable trace is unchanged.
808+
800809
The process-local raw-reasoning fallback is fail-closed unless a request has an explicit client
801810
thread plus an exact provider destination, wire adapter, final model, and physical credential
802811
identity. API-key material is represented only by a process-keyed HMAC; OAuth replay is bound to the

‎tests/responses-reasoning-summary-rewrite.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,52 @@ describe("responses reasoning summary channel rewrite", () => {
209209
expect(rewrite("not json")).toBe("not json");
210210
expect(rewrite("[1,2]")).toBe("[1,2]");
211211
});
212+
213+
// The client replays the reasoning item it received, and a backend that issued
214+
// `encrypted_content` rejects a reshaped item on that replay. This rewrite's round-trip was
215+
// verified against DeepSeek, which is stateless and issues no blob; providers that do issue one
216+
// joined later through `preserveReasoningContentModels`.
217+
describe("items carrying encrypted_content", () => {
218+
const blobItem = {
219+
type: "reasoning",
220+
id: "rs_1",
221+
status: "completed",
222+
encrypted_content: "gAAAAAB-upstream-issued-blob",
223+
content: [{ type: "reasoning_text", text: "thinking" }],
224+
summary: [],
225+
};
226+
227+
test("are returned byte-for-byte on output_item.done", () => {
228+
const payload = { type: "response.output_item.done", output_index: 0, item: blobItem };
229+
expect(apply(payload)).toEqual(payload);
230+
});
231+
232+
test("are returned byte-for-byte inside response.completed output", () => {
233+
const payload = {
234+
type: "response.completed",
235+
response: { id: "resp_1", output: [blobItem] },
236+
};
237+
expect(apply(payload)).toEqual(payload);
238+
});
239+
240+
test("are returned byte-for-byte through the non-streaming document rewrite", () => {
241+
const doc = { id: "resp_1", object: "response", output: [blobItem] };
242+
expect(rewriteReasoningSummaryInJson(doc)).toBe(doc);
243+
const json = JSON.stringify(doc);
244+
expect(rewriteReasoningSummaryInJsonString(json)).toBe(json);
245+
});
246+
247+
// Only the stored item is protected: the live trace Codex renders comes from the delta events,
248+
// which carry no blob and are still routed to the summary channel.
249+
test("do not disable the delta rewrite that renders the live trace", () => {
250+
expect(apply({
251+
type: "response.reasoning_text.delta",
252+
delta: "think",
253+
item_id: "rs_1",
254+
output_index: 0,
255+
})).toMatchObject({ type: "response.reasoning_summary_text.delta", delta: "think" });
256+
});
257+
});
212258
});
213259

214260
describe("routeUsesContentChannelReasoning", () => {

0 commit comments

Comments
 (0)