Skip to content

Commit fbecefa

Browse files
YotuAIluvs01
authored andcommitted
fix(responses): reject duplicate historical call ids
(cherry picked from commit dc948dc)
1 parent c7781bf commit fbecefa

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/responses/custom-tool-compat.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,11 @@ function rewriteHistoricalCustomItems(
319319
continue;
320320
}
321321
const existing = calls.get(item.call_id);
322-
if (existing && !sameHistoricalIdentity(existing, identity)) {
323-
throw new RoutedCustomToolCompatError("historical_item", "call_id");
322+
if (existing) {
323+
throw new RoutedCustomToolCompatError(
324+
"historical_item",
325+
sameHistoricalIdentity(existing, identity) ? "duplicate_call_id" : "call_id",
326+
);
324327
}
325328
calls.set(item.call_id, identity);
326329
if (item.type === "custom_tool_call") historicalCustomCallIds.add(item.call_id);

‎tests/responses/custom-tool-compat.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ describe("undeclared historical custom-tool replay", () => {
342342
}, false)).toThrow(/historical_collision: declared_function_name/);
343343
});
344344

345+
test("rejects duplicate call IDs even when the historical call identity matches", () => {
346+
expect(() => rewriteRoutedCustomToolsForUpstream({
347+
input: [
348+
{ type: "custom_tool_call", call_id: "call_dup", name: "exec", input: "a" },
349+
{ type: "custom_tool_call", call_id: "call_dup", name: "exec", input: "a" },
350+
],
351+
}, false)).toThrow(/historical_item: duplicate_call_id/);
352+
});
353+
345354
test("refuses call_id identity collisions", () => {
346355
expect(() => rewriteRoutedCustomToolsForUpstream({
347356
input: [

0 commit comments

Comments
 (0)