fix(agents): enforce single-writer session files

This commit is contained in:
Peter Steinberger
2026-01-11 02:24:25 +00:00
parent 3a113b7752
commit 6668805aca
4 changed files with 220 additions and 69 deletions

View File

@@ -92,4 +92,25 @@ describe("sanitizeToolUseResultPairing", () => {
expect(results).toHaveLength(1);
expect(results[0]?.toolCallId).toBe("call_1");
});
it("drops orphan tool results that do not match any tool call", () => {
const input = [
{ role: "user", content: "hello" },
{
role: "toolResult",
toolCallId: "call_orphan",
toolName: "read",
content: [{ type: "text", text: "orphan" }],
isError: false,
},
{
role: "assistant",
content: [{ type: "text", text: "ok" }],
},
] satisfies AgentMessage[];
const out = sanitizeToolUseResultPairing(input);
expect(out.some((m) => m.role === "toolResult")).toBe(false);
expect(out.map((m) => m.role)).toEqual(["user", "assistant"]);
});
});