Skip to content

Commit 26a15ee

Browse files
committed
fix(responses): leave the compact wire format out of the id backfill
The compact endpoint returns `{ type: "compaction", encrypted_content }`, which is its own wire contract and carries no id. The Responses id backfill treated it as an output item and synthesized one, changing a body that clients compare exactly. This only surfaced once the backfill and the compact endpoint were on the same tree, which is why the integration branch is built and tested before anything merges rather than trusting per-branch CI. The backfill exists to satisfy strict Responses decoders; a shape those decoders never see is outside its remit.
1 parent 713dce9 commit 26a15ee

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/server/responses/responses-field-backfill.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,24 @@ function backfillContentArray(content: unknown): unknown {
111111
return changed ? repaired : content;
112112
}
113113

114+
/**
115+
* Item types that are NOT Responses output items and must be returned byte-for-byte.
116+
*
117+
* `compaction` is the `/v1/responses/compact` wire format, not a Responses output item. It has
118+
* no `id` in that contract, so synthesizing one changes a response body the client compares
119+
* exactly. The backfill exists to satisfy strict Responses decoders; a shape those decoders
120+
* never see is outside its remit.
121+
*/
122+
const NON_RESPONSES_ITEM_TYPES: ReadonlySet<string> = new Set(["compaction"]);
123+
114124
/**
115125
* Walk an output item and backfill output_text parts in its content.
116126
* Also backfills a missing required id on the item itself.
117127
* Returns the same object reference if nothing changed.
118128
*/
119129
function backfillOutputItem(item: unknown, slot: ItemIdSlot): unknown {
120130
if (!isPlainObject(item)) return item;
131+
if (typeof item.type === "string" && NON_RESPONSES_ITEM_TYPES.has(item.type)) return item;
121132
const content = item.content;
122133
const repaired = backfillContentArray(content);
123134
const withId = backfillItemId(item, slot);

‎tests/responses-field-backfill.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,22 @@ describe("responses-field-backfill", () => {
402402
});
403403
expect(new Set(ids).size).toBe(2);
404404
});
405+
406+
// `compaction` is the /v1/responses/compact wire format, not a Responses output item: it
407+
// carries no id in that contract, and clients compare the body exactly. Synthesizing an id
408+
// here changed a response that had nothing to do with strict Responses decoding — a defect
409+
// that only appeared once this backfill and the compact endpoint were on the same tree.
410+
test("a compaction item is returned byte-for-byte", () => {
411+
const response = {
412+
id: "resp_1",
413+
object: "response",
414+
status: "completed",
415+
output: [{ type: "compaction", encrypted_content: "gAAAAAB-test-opaque" }],
416+
};
417+
const result = JSON.parse(backfillResponsesFieldsJson(JSON.stringify(response))) as {
418+
output: Record<string, unknown>[];
419+
};
420+
expect(result.output[0]).toEqual({ type: "compaction", encrypted_content: "gAAAAAB-test-opaque" });
421+
expect(result.output[0]).not.toHaveProperty("id");
422+
});
405423
});

0 commit comments

Comments
 (0)