Skip to content

Commit 1bbb63b

Browse files
olddonkeyclaude
andcommitted
fix(responses): strip output-only reasoning status unconditionally
The cross-backend fix kept `status` on any reasoning item that forwarded its `encrypted_content`, to honour "an item whose blob is forwarded is not otherwise modified". That invariant was defensive rather than observed, and it broke the cold-record recovery path. With no provenance record — after a restart, TTL expiry or eviction — the blob is retained, so `status` is retained too, and OpenAI rejects the request on the field before it ever validates the blob: 400 Unknown parameter: 'input[1].status'. The opaque-blob recovery correctly does not match that error, so the conversation stayed broken. Measured against the live backends: - OpenAI never mints `status` on a reasoning item (keys are content, encrypted_content, id, summary, type), so the retain branch could only ever fire for an item minted elsewhere — the exact item OpenAI then rejects. It never protected an OpenAI-minted item. - Grok accepts its own 1707-char blob with `status` removed: 200. - With `status` removed, that same item replayed to gpt-5.6-sol returns 200 and the usage log records sendCount=2, recoveryKinds=['opaque-blob-rejection'] — removing the field is what lets the request reach the blob check the recovery is armed for. The `content` rule is untouched: blanking predates this and is required by ChatGPT's input contract. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 3927a43 commit 1bbb63b

4 files changed

Lines changed: 48 additions & 30 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export function sanitizeReasoningInputContent(
6565
const hasEncryptedContent = Object.prototype.hasOwnProperty.call(rec, "encrypted_content");
6666
const stripEncryptedContent = hasOcxEnvelope
6767
|| (opts?.stripEncryptedContent === true && hasEncryptedContent);
68-
const retainsEncryptedContent = hasEncryptedContent && !stripEncryptedContent;
6968
// Codex serializes an absent reasoning content channel as `"content": null`. The field is
7069
// optional and null carries nothing, but a strict gateway rejects the item on its declared type
7170
// — xAI answers `Could not decode the compaction blob`, naming the sibling `encrypted_content`
@@ -75,17 +74,16 @@ export function sanitizeReasoningInputContent(
7574
// Gated to routed destinations. An OpenAI-operated backend binds the blob to the item's exact
7675
// shape, so deleting a field there invalidates it (`The encrypted content ... could not be
7776
// verified`); the two requirements are exactly opposed, and a live regression proved it. That
78-
// gate is also why this drop may touch an item that keeps its blob, which the status invariant
79-
// below forbids: xAI demonstrably accepts its own blob without the null channel, and the
80-
// destinations that bind blobs to item shape never reach this branch.
77+
// gate is also why this drop may touch an item that keeps its blob: xAI demonstrably accepts its
78+
// own blob without the null channel, and the destinations that bind blobs to item shape never
79+
// reach this branch. This is independent of the output-only status removal below.
8180
const dropNullContentChannel = opts?.dropNullContentChannel === true
8281
&& "content" in rec && !Array.isArray(rec.content);
83-
// Invariant for fields newly stripped by this cross-backend layer: an item whose
84-
// encrypted_content is forwarded keeps status because OpenAI-operated backends bind opaque
85-
// reasoning blobs to the item shape. Content blanking predates this invariant and remains
86-
// required by ChatGPT's input contract; a native blob plus raw content is a known unresolved
87-
// shape conflict, not an oversight to resolve by preserving content here.
88-
const stripOutputStatus = hasOutputStatus && !retainsEncryptedContent;
82+
// `status` is output-only. Measured OpenAI reasoning items never contain it, and Grok accepts
83+
// its own encrypted_content with status removed. Keeping a foreign status beside a retained
84+
// blob makes OpenAI reject the field before blob validation, starving the provenance recovery
85+
// of the opaque-blob error it needs. Content blanking remains the separate pre-existing rule.
86+
const stripOutputStatus = hasOutputStatus;
8987
const blankContent = !dropNullContentChannel
9088
&& !opts?.preserveRawReasoningContent
9189
&& (hasRawContent || hasOcxEnvelope);

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -549,20 +549,22 @@ replays are explicit and receive the same repair.
549549
These compatibility guards are covered by focused tests and should stay close to the adapters that
550550
need them.
551551

552-
Responses passthrough keeps output-only `status` on any `reasoning` input item that retains opaque
553-
`encrypted_content` because OpenAI-operated backends may bind the blob to that field. The established
554-
raw-`content` rule remains separate: ChatGPT accepts reasoning input only with empty `content`, so a
555-
native blob plus raw content keeps the blob and `status` but still blanks `content`. That shape is a
556-
known unresolved contract conflict, not evidence that either existing rule is safe to broaden. The
557-
blob is kept unless the in-process thread record proves that the current provider, destination,
558-
adapter, model, or credential differs from the route recorded for the prior request on that client
559-
thread. On a proven change the blob and `status` are removed while the reasoning item and its summary
560-
survive; `status` is also removed from blobless reasoning items. Missing, expired, or evicted identity
561-
state is unknown. The comparison uses the durable destination and credential identities with the
562-
provider, adapter, and model, so OAuth token-generation refreshes do not look like backend changes;
563-
when either durable dimension is unavailable it refuses to record rather than falling back to a
564-
volatile identity. This deterministic pre-flight is the primary path and covers threads the process
565-
has served while their record remains inside the TTL/LRU bounds. Missing, expired, evicted, and
552+
Responses passthrough always removes output-only `status` from `reasoning` input items, including
553+
items that retain opaque `encrypted_content`. The prior retains-blob-keeps-status invariant was
554+
defensive rather than observed: measured OpenAI reasoning items never contain `status`, and Grok
555+
accepts its own blob with `status` removed. Keeping it on a cold cross-backend replay instead made
556+
OpenAI reject the unknown field before validating the blob, starving opaque-blob recovery of the
557+
provenance error it needs. The established raw-`content` rule remains separate: ChatGPT accepts
558+
reasoning input only with empty `content`, so a native blob plus raw content keeps the blob but still
559+
blanks `content`. The blob is kept unless the in-process thread record proves that the current
560+
provider, destination, adapter, model, or credential differs from the route recorded for the prior
561+
request on that client thread. On a proven change the blob is removed while the reasoning item and
562+
its summary survive; `status` has already been removed on every path. Missing, expired, or evicted
563+
identity state is unknown. The comparison uses the durable destination and credential identities
564+
with the provider, adapter, and model, so OAuth token-generation refreshes do not look like backend
565+
changes; when either durable dimension is unavailable it refuses to record rather than falling back
566+
to a volatile identity. This deterministic pre-flight is the primary path and covers threads the
567+
process has served while their record remains inside the TTL/LRU bounds. Missing, expired, evicted, and
566568
pre-process history stays fail-soft on the first send. If a Responses upstream then returns its own
567569
self-identifying opaque-blob 4xx (`invalid_encrypted_content`, or xAI's two `invalid-argument`
568570
decoder errors), the proxy rebuilds once through the same sanitation path: reasoning
@@ -589,9 +591,9 @@ conversation's last-serving identity and cause a later main-model turn to strip
589591
- 목적과 의도: Keep same-backend opaque reasoning replay while preventing backend-private blobs and output-only fields from breaking the first turn after a route change.
590592
- 기존 구현 및 제약 조건: Reasoning-input sanitation already handled raw content and `ocxr1:` envelopes; the replay cache already supplied a bounded, thread-scoped physical-route identity, but no record connected that identity to native `encrypted_content` provenance.
591593
- 검토한 주요 대안: Strip every opaque blob, persist provenance across restarts, trust generic 4xx prose, rely only on a retry, or combine deterministic route comparison with a narrowly identified recovery.
592-
- 선택한 방식: Preserve `status` whenever its blob is forwarded without changing the pre-existing raw-`content` blanking rule; otherwise remove output-only `status`, compare and update a 64-entry/256 KiB/one-hour in-process serving-identity record using durable destination and credential dimensions at request time, pass a proven change into the Responses adapter before the first send, and use one self-identified opaque-blob recovery only when provenance was unknown.
593-
- 다른 대안 대신 이 방식을 선택한 이유: Unknown provenance can still be valid after restart, durable storage is unnecessary for this bounded compatibility hint, and deterministic pre-flight avoids the extra paid or stateful upstream attempt whenever the process has evidence. The upstream's narrow error identity supplies authoritative evidence only for histories the process could not observe.
594-
- 장점, 단점 및 영향: Same-route and unknown replay retain cached reasoning on the first send, known cross-route replay keeps the reasoning item without its undecodable blob, and a cold cross-route replay recovers with one extra round trip and one degraded-reasoning turn. A repeated rejection is surfaced unchanged after exactly one recovery attempt.
594+
- 선택한 방식: Remove output-only `status` from every reasoning input item without changing the pre-existing raw-`content` blanking rule; compare and update a 64-entry/256 KiB/one-hour in-process serving-identity record using durable destination and credential dimensions at request time, pass a proven change into the Responses adapter before the first send, and use one self-identified opaque-blob recovery only when provenance was unknown.
595+
- 다른 대안 대신 이 방식을 선택한 이유: The former blob/status coupling was defensive rather than observed, and live backends showed that removing `status` preserves same-backend Grok replay while allowing cold cross-backend requests to reach blob validation. Unknown provenance can still be valid after restart, durable storage is unnecessary for this bounded compatibility hint, and deterministic pre-flight avoids the extra paid or stateful upstream attempt whenever the process has evidence. The upstream's narrow error identity supplies authoritative evidence only for histories the process could not observe.
596+
- 장점, 단점 및 영향: Same-route and unknown replay retain cached reasoning on the first send without replaying an output-only field, known cross-route replay keeps the reasoning item without its undecodable blob, and a cold cross-route replay can reach opaque-blob recovery instead of failing early on `status`. A repeated blob rejection is surfaced unchanged after exactly one recovery attempt.
595597

596598
DeepSeek's stateless Responses compatibility pass normalizes only unambiguous tool-call batches.
597599
Calls emitted before the first matched output stay together as one assistant batch, followed by

‎tests/deepseek-reasoning-replay.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ function inputOf(result: unknown): Record<string, unknown>[] {
2929
}
3030

3131
describe("sanitizeReasoningInputContent scoping", () => {
32+
test("retains native encrypted content while stripping output-only status", () => {
33+
const out = inputOf(sanitizeReasoningInputContent({
34+
model: "m",
35+
input: [reasoningItem({ encrypted_content: "native-blob", status: "completed" })],
36+
}));
37+
expect(out[0]).toEqual({
38+
type: "reasoning",
39+
id: "rs_1",
40+
content: [],
41+
encrypted_content: "native-blob",
42+
});
43+
});
44+
3245
test("default behavior still blanks reasoning content (ChatGPT backend rule)", () => {
3346
const out = inputOf(sanitizeReasoningInputContent({ model: "m", input: [reasoningItem()] }));
3447
expect(out[0]!.content).toEqual([]);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ describe("OpenAI Responses passthrough sanitization", () => {
781781
});
782782
});
783783

784-
test("keeps a blob-bearing reasoning item byte-identical when the route is unchanged", () => {
784+
test("keeps a blob-bearing reasoning item but strips output-only status when the route is unchanged", () => {
785785
const adapter = createResponsesPassthroughAdapter(provider);
786786
const reasoningItem = {
787787
type: "reasoning",
@@ -804,7 +804,13 @@ describe("OpenAI Responses passthrough sanitization", () => {
804804
}, { headers: new Headers({ authorization: "Bearer token" }) });
805805
const body = JSON.parse(request.body) as { input: Record<string, unknown>[] };
806806

807-
expect(JSON.stringify(body.input[0])).toBe(JSON.stringify(reasoningItem));
807+
expect(body.input[0]).toEqual({
808+
type: "reasoning",
809+
id: "rs_same_backend",
810+
summary: [{ type: "summary_text", text: "summary" }],
811+
encrypted_content: "backend-minted-blob",
812+
content: [],
813+
});
808814
});
809815

810816
test("keeps a native blob while blanking its raw reasoning content", () => {
@@ -829,7 +835,6 @@ describe("OpenAI Responses passthrough sanitization", () => {
829835

830836
expect(body.input[0]).toEqual({
831837
type: "reasoning",
832-
status: "completed",
833838
summary: [],
834839
encrypted_content: "native-backend-blob",
835840
content: [],

0 commit comments

Comments
 (0)