fix(agents): harden openai ws tool call id handling

This commit is contained in:
Peter Steinberger
2026-03-03 00:43:24 +00:00
parent 596621919c
commit 6649c22471
5 changed files with 179 additions and 6 deletions

View File

@@ -424,6 +424,41 @@ describe("convertMessagesToInputItems", () => {
});
});
it("drops tool result messages with empty tool call id", () => {
const msg = {
role: "toolResult" as const,
toolCallId: " ",
toolName: "test_tool",
content: [{ type: "text", text: "output" }],
isError: false,
timestamp: 0,
};
const items = convertMessagesToInputItems([msg] as Parameters<
typeof convertMessagesToInputItems
>[0]);
expect(items).toEqual([]);
});
it("falls back to toolUseId when toolCallId is missing", () => {
const msg = {
role: "toolResult" as const,
toolUseId: "call_from_tool_use",
toolName: "test_tool",
content: [{ type: "text", text: "ok" }],
isError: false,
timestamp: 0,
};
const items = convertMessagesToInputItems([msg] as Parameters<
typeof convertMessagesToInputItems
>[0]);
expect(items).toHaveLength(1);
expect(items[0]).toMatchObject({
type: "function_call_output",
call_id: "call_from_tool_use",
output: "ok",
});
});
it("converts a full multi-turn conversation", () => {
const messages: FakeMessage[] = [
userMsg("Run ls"),
@@ -454,6 +489,14 @@ describe("convertMessagesToInputItems", () => {
expect(items[0]?.type).toBe("function_call");
});
it("drops assistant tool calls with empty ids", () => {
const msg = assistantMsg([], [{ id: " ", name: "read", args: { path: "/tmp/a" } }]);
const items = convertMessagesToInputItems([msg] as Parameters<
typeof convertMessagesToInputItems
>[0]);
expect(items).toEqual([]);
});
it("skips thinking blocks in assistant messages", () => {
const msg = {
role: "assistant" as const,