diff --git a/packages/paperclip-runner/src/live/terminal-call-freshness.test.ts b/packages/paperclip-runner/src/live/terminal-call-freshness.test.ts index 53b3066b94d..cb2b4ce26de 100644 --- a/packages/paperclip-runner/src/live/terminal-call-freshness.test.ts +++ b/packages/paperclip-runner/src/live/terminal-call-freshness.test.ts @@ -41,6 +41,17 @@ describe("unseenReturnedToolCalls", () => { }); }); +it("forgets calls of a provider turn lost on restore once a new turn starts (restart chaos K2 t110)", () => { + const commands = [{ type: "semantic_tool.result", payload: { callId: "lost", operationId: "read_agent_instructions" } }]; + const finish = started("f", "paperclip_finish"); + const events = [ + event("turn.started", {}), started("lost", "read_agent_instructions"), + event("turn.failed", { error: { code: "provider_turn_lost_on_restore" } }), + event("turn.started", {}), started("r", "read_document"), result("r"), completed("r", "read_document"), finish, + ]; + expect(unseenReturnedToolCalls(events, commands, { terminalSourceEventId: finish.sourceEventId, turnId: "turn-1" })).toEqual([]); +}); + it("counts the controller's semantic_tool.result command as the returned result", () => { const block = started("b", "paperclip_block"); const commands = [{ type: "semantic_tool.result", payload: { callId: "w", operationId: "write_document" } }]; diff --git a/packages/paperclip-runner/src/live/terminal-call-freshness.ts b/packages/paperclip-runner/src/live/terminal-call-freshness.ts index b64827dc6ca..ef19cc97724 100644 --- a/packages/paperclip-runner/src/live/terminal-call-freshness.ts +++ b/packages/paperclip-runner/src/live/terminal-call-freshness.ts @@ -46,6 +46,10 @@ export function unseenReturnedToolCalls( if (input.turnId && typeof event.turnId === "string" && event.turnId !== input.turnId) continue; const payload = record(event.payload); const type = event.eventType; + if (type === "turn.started") { + calls.clear(); + continue; + } if ((type === "tool.execution.started" || type === "tool.execution.completed") && payload.transport === "dynamic") { const id = typeof payload.executionId === "string" ? payload.executionId : null; if (!id) continue;