From 4df5307eaab6b22d06fe54a45c68211b3413f45c Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:14:46 +0000 Subject: [PATCH] fix: keep failed ACP tools valid in conversation history (#9467) Co-authored-by: Tianyu Yang --- .../src/server/acp-internal/connection.ts | 4 +- packages/plugin/src/server/acp.test.ts | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/packages/plugin/src/server/acp-internal/connection.ts b/packages/plugin/src/server/acp-internal/connection.ts index 6c8ac31b7..570d3cd4c 100644 --- a/packages/plugin/src/server/acp-internal/connection.ts +++ b/packages/plugin/src/server/acp-internal/connection.ts @@ -1527,7 +1527,9 @@ function toolTimelineItem(snapshot: AcpToolCallSnapshot): ToolCallTimelineItem { name: snapshot.name ?? snapshot.title, detail, }; - if (status === "failed") return { ...base, status, error: snapshot.output }; + if (status === "failed") { + return { ...base, status, error: snapshot.output ?? { message: "Tool failed" } }; + } return { ...base, status, error: null }; } diff --git a/packages/plugin/src/server/acp.test.ts b/packages/plugin/src/server/acp.test.ts index b022e0a5e..ee96f3eb0 100644 --- a/packages/plugin/src/server/acp.test.ts +++ b/packages/plugin/src/server/acp.test.ts @@ -9,6 +9,7 @@ import { } from "@agentclientprotocol/sdk"; import type { ProviderConnection, ProviderEvent, ProviderInput } from "./provider.js"; import { afterEach, describe, expect, it } from "vitest"; +import { AgentTimelineItemPayloadSchema } from "@getpaseo/protocol/messages"; import { runAcpProvider, type AcpStreamMessage } from "./acp.js"; const temporaryDirectories: string[] = []; @@ -890,6 +891,72 @@ lines.on("line", (line) => { }, ); + it.each([ + { status: "failed", output: undefined, error: { message: "Tool failed" } }, + { status: "failed", output: null, error: { message: "Tool failed" } }, + { + status: "failed", + output: { message: "File not found" }, + error: { message: "File not found" }, + }, + { status: "failed", output: "Permission denied", error: "Permission denied" }, + { status: "completed", output: null, error: null }, + ] as const)( + "keeps a $status ACP tool with output $output valid on the history wire", + async ({ status, output, error }) => { + const harness = connectorHarness({ + promptUpdates: () => [ + { + sessionUpdate: "tool_call", + toolCallId: "read-1", + title: "Read file", + kind: "read", + status: "in_progress", + }, + { sessionUpdate: "tool_call_update", toolCallId: "read-1", status, rawOutput: output }, + ], + }); + const registration = runAcpProvider({ + id: "tool-history-acp", + label: "Tool history ACP", + connector: harness.connector, + }); + const connection = await registration.connect({ + versions: [1], + capabilities: ["prompt.message"], + }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + await connection.send(openInput()); + await waitForEvent(events, (event) => event.type === "session.ready"); + await connection.send({ + type: "session.prompt", + sessionId: "session-1", + prompt: { + clientMessageId: "first", + delivery: "auto", + input: { type: "message", content: [{ type: "text", text: "Read a file" }] }, + }, + }); + await waitForEvent( + events, + (event) => event.type === "session.turn" && event.state === "completed", + ); + const rows = events.flatMap((event) => + event.type === "timeline.item" && event.item.id === "read-1" ? [event.item] : [], + ); + expect(rows).toHaveLength(2); + for (const row of rows) { + expect(AgentTimelineItemPayloadSchema.safeParse(row).success).toBe(true); + } + expect(rows.at(-1)).toMatchObject({ type: "tool_call", status, error }); + } finally { + await connection.close(); + } + }, + ); + it("serializes configuration mutations", async () => { let releaseMutation: (() => void) | null = null; const configOptions = [