Skip to content

Commit 9a42f9e

Browse files
Galin IlievGalin Iliev
authored andcommitted
fix: drop unsafe copilot reasoning replay ids
1 parent 62575c1 commit 9a42f9e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/agents/openai-transport-stream.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ describe("openai transport stream", () => {
23832383
});
23842384
});
23852385

2386-
it("preserves oversized Responses reasoning replay item ids for provider boundary sanitizers", () => {
2386+
it("drops oversized GitHub Copilot Responses reasoning replay items before send", () => {
23872387
const model = {
23882388
id: "gpt-5.5",
23892389
name: "GPT-5.5",
@@ -2441,9 +2441,7 @@ describe("openai transport stream", () => {
24412441
}>;
24422442
};
24432443

2444-
const reasoningItem = params.input?.find((item) => item.type === "reasoning");
2445-
expect(reasoningItem?.id).toBe(longReasoningId);
2446-
expect(reasoningItem?.id?.length).toBeGreaterThan(64);
2444+
expect(params.input?.some((item) => item.type === "reasoning")).toBe(false);
24472445
});
24482446

24492447
it("strips encrypted reasoning replay when provenance does not match", () => {

src/agents/openai-transport-stream.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,14 @@ function normalizeResponsesReplayItemId(
954954
return `${prefix}_${shortHash(id)}`;
955955
}
956956

957+
function isSafeResponsesReplayItemId(id: unknown): id is string {
958+
return (
959+
typeof id === "string" &&
960+
id.length > 0 &&
961+
id.length <= OPENAI_RESPONSES_REPLAY_ITEM_ID_MAX_LENGTH
962+
);
963+
}
964+
957965
function encodeTextSignatureV1(id: string, phase?: "commentary" | "final_answer"): string {
958966
return JSON.stringify({ v: 1, id, ...(phase ? { phase } : {}) });
959967
}
@@ -1105,6 +1113,12 @@ function convertResponsesMessages(
11051113
if (!shouldReplayResponsesItemIds) {
11061114
delete replayableReasoningItem.id;
11071115
}
1116+
if (
1117+
model.provider === "github-copilot" &&
1118+
!isSafeResponsesReplayItemId(replayableReasoningItem.id)
1119+
) {
1120+
continue;
1121+
}
11081122
output.push(replayableReasoningItem as ResponseInputItem);
11091123
}
11101124
} else if (block.type === "text") {

0 commit comments

Comments
 (0)