diff --git a/src/agents/pi-embedded-subscribe.test.ts b/src/agents/pi-embedded-subscribe.test.ts index 120b25089..d07691e90 100644 --- a/src/agents/pi-embedded-subscribe.test.ts +++ b/src/agents/pi-embedded-subscribe.test.ts @@ -635,6 +635,53 @@ describe("subscribeEmbeddedPiSession", () => { expect(onBlockReply).not.toHaveBeenCalled(); }); + it("does not suppress message_end replies when message tool reports error", () => { + let handler: ((evt: unknown) => void) | undefined; + const session: StubSession = { + subscribe: (fn) => { + handler = fn; + return () => {}; + }, + }; + + const onBlockReply = vi.fn(); + + subscribeEmbeddedPiSession({ + session: session as unknown as Parameters< + typeof subscribeEmbeddedPiSession + >[0]["session"], + runId: "run", + onBlockReply, + blockReplyBreak: "message_end", + }); + + const messageText = "Please retry the send."; + + handler?.({ + type: "tool_execution_start", + toolName: "message", + toolCallId: "tool-message-err", + args: { action: "send", to: "+1555", message: messageText }, + }); + + handler?.({ + type: "tool_execution_end", + toolName: "message", + toolCallId: "tool-message-err", + isError: false, + result: { details: { status: "error" } }, + }); + + const assistantMessage = { + role: "assistant", + content: [{ type: "text", text: messageText }], + } as AssistantMessage; + + handler?.({ type: "message_end", message: assistantMessage }); + + expect(onBlockReply).toHaveBeenCalledTimes(1); + }); + it("clears block reply state on message_start", () => { let handler: ((evt: unknown) => void) | undefined; const session: StubSession = {