Skip to content

Commit 90d1ef4

Browse files
robin-main-hubRobin Choiclaude
authored
fix(responses): strip mismatched agent_message item ids before passthrough (#215)
Routed threads can replay agent_message items whose ids lost their amsg_ prefix (dialect-mixed histories). The ChatGPT Responses backend validates the id prefix per item type and 400s the whole request -- Invalid 'input[N].id': 'msg_...'. Expected an ID that begins with 'amsg'. -- which bricks the thread on every retry. stripInvalidItemIds already covers message/reasoning/function_call/ custom_tool_call/tool_search_call/web_search_call; add the missing agent_message -> amsg_ mapping so mismatched ids are stripped like every other item type. Co-authored-by: Robin Choi <robin@Robinui-MacBookPro.local> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 304a1ea commit 90d1ef4

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

src/adapters/openai-responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function stripInvalidItemIds(body: unknown): unknown {
5757

5858
const validPrefixes: Record<string, string> = {
5959
message: "msg_",
60+
agent_message: "amsg_",
6061
reasoning: "rs_",
6162
function_call: "fc_",
6263
custom_tool_call: "ctc_",

tests/openai-responses-passthrough.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ describe("OpenAI Responses passthrough sanitization", () => {
4141
{ item: { type: "tool_search_call", id: "tsc_1", call_id: "call_5", execution: "client", arguments: {} }, expectedId: "tsc_1" },
4242
{ item: { type: "web_search_call", id: "fc_wrong", status: "completed" }, expectedId: undefined },
4343
{ item: { type: "web_search_call", id: "ws_valid", status: "completed" }, expectedId: "ws_valid" },
44+
{ item: { type: "agent_message", id: "msg_wrong-dialect", content: [{ type: "output_text", text: "routed reply" }] }, expectedId: undefined },
45+
{ item: { type: "agent_message", id: "amsg_1", content: [{ type: "output_text", text: "routed reply" }] }, expectedId: "amsg_1" },
4446
];
4547
const input = cases.map(({ item }) => item);
4648
const request = adapter.buildRequest({

0 commit comments

Comments
 (0)