π OpenHands: AI-Driven Development
feat(acp): render running tool-call cards (pairs with SDK source dedup) (#1027)
simonrosenberg3122fa9a5623
diff --git a/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.ts b/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.tsnew file mode 100644index 0000000000..da4628ca76--- /dev/null+++ b/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.ts@@ -0,0 +1,52 @@+import { describe, expect, it } from "vitest";+import { getACPToolCallResult } from "#/components/conversation-events/chat/event-content-helpers/get-observation-result";+import { ACPToolCallEvent } from "#/types/agent-server/core/events/acp-tool-call-event";++const makeACPEvent = (+ overrides: Partial<ACPToolCallEvent> = {},+): ACPToolCallEvent => ({+ id: "acp-1",+ kind: "ACPToolCallEvent",+ timestamp: "2024-01-01T00:00:00Z",+ source: "agent",+ tool_call_id: "tc-1",+ title: "Run command",+ status: "completed",+ tool_kind: "execute",+ raw_input: { command: "ls" },+ raw_output: "file.txt",+ content: null,+ is_error: false,+ ...overrides,+});++describe("getACPToolCallResult", () => {+ it("maps completed β success", () => {+ expect(getACPToolCallResult(makeACPEvent({ status: "completed" }))).toBe(+ "success",+ );+ });++ it("maps failed β error", () => {+ expect(getACPToolCallResult(makeACPEvent({ status: "failed" }))).toBe(+ "error",+ );+ });++ it("maps is_error β error even when status is completed", () => {+ expect(+ getACPToolCallResult(makeACPEvent({ status: "completed", is_error: true })),+ ).toBe("error");+ });++ it.each(["pending", "in_progress"] as const)(+ "maps non-terminal status %s β undefined (running card)",+ (status) => {+ expect(getACPToolCallResult(makeACPEvent({ status }))).toBeUndefined();+ },+ );++ it("maps null status β undefined (running card)", () => {+ expect(getACPToolCallResult(makeACPEvent({ status: null }))).toBeUndefined();+ });+});diff --git a/__tests__/components/conversation-events/chat/event-content-helpers/should-render-event.test.ts b/__tests__/components/conversation-events/chat/event-content-helpers/should-render-event.test.tsindex 34f825360f..188a80ad09 100644--- a/__tests__/components/conversation-events/chat/event-content-helpers/should-render-event.test.ts+++ b/__tests__/components/conversation-events/chat/event-content-helpers/should-render-event.test.ts@@ -61,13 +61,21 @@ describe("shouldRenderEvent - PlanningFileEditorAction", () => {});describe("shouldRenderEvent - ACPToolCallEvent", () => {- it("hides in_progress events so the card doesn't flash half-formed", () => {- // ACP streams multiple events per ``tool_call_id``; the partially-- // populated in-flight ones have to stay off-screen, otherwise the- // user watches the card update in place mid-stream β visibly noisy.+ it("renders the early in_progress 'started' card", () => {+ // The SDK now persists exactly one ``started`` (in_progress) event and+ // one terminal event per ``tool_call_id`` β the action->observation pair.+ // The started event renders the card as "running"; ``handleEventForUI``+ // then replaces it in place when the terminal event arrives. The old+ // half-formed flashing came from the now-removed per-progress fan-out.const event = makeACPEvent({ status: "in_progress", raw_input: {} });- expect(shouldRenderEvent(event)).toBe(false);+ expect(shouldRenderEvent(event)).toBe(true);+ });++ it("renders pending 'started' cards", () => {+ const event = makeACPEvent({ status: "pending" });++ expect(shouldRenderEvent(event)).toBe(true);});it("renders completed events", () => {@@ -82,17 +90,13 @@ describe("shouldRenderEvent - ACPToolCallEvent", () => {expect(shouldRenderEvent(event)).toBe(true);});- it("hides events with null status β treated as in-flight, not legacy", () => {- // ``null`` used to be allowed for backwards compat with old agent-- // server builds (before the field was required). Canvas's pinned- // agent-server always sets a status, so a ``null`` we see today is- // a streaming intermediate the SDK hasn't filled yet. Treating it- // as in-flight matches the "wait for terminal" rule and stops the- // pre-stream half-rendered card. If we ever need to reach an older- // build, the right knob is to bump the pin, not loosen this gate.+ it("renders events with null status as a running card", () => {+ // A ``null`` status (legacy builds before the field was required) renders+ // as "running" via the absent check mark rather than being hidden β better+ // a card than a silently dropped tool call.const event = makeACPEvent({ status: null });- expect(shouldRenderEvent(event)).toBe(false);+ expect(shouldRenderEvent(event)).toBe(true);});});diff --git a/src/components/conversation-events/chat/event-content-helpers/get-observation-result.ts b/src/components/conversation-events/chat/event-content-helpers/get-observation-result.tsindex 08eb27361a..860181592f 100644--- a/src/components/conversation-events/chat/event-content-helpers/get-observation-result.ts+++ b/src/components/conversation-events/chat/event-content-helpers/get-observation-result.ts@@ -5,11 +5,11 @@ export type ObservationResultStatus = "success" | "error" | "timeout";/*** Map an ACPToolCallEvent's lifecycle + error flags to the same- * success/error status the rest of the UI uses. An ``in_progress`` call- * returns ``undefined`` so the SuccessIndicator renders nothing β the- * card shows as "running" via the absence of a check mark, matching how- * regular ActionEvents are displayed before their ObservationEvent- * arrives.+ * success/error status the rest of the UI uses. A non-terminal call+ * (``pending`` / ``in_progress``) falls through to ``undefined`` so the+ * SuccessIndicator renders nothing β the card shows as "running" via the+ * absence of a check mark, matching how regular ActionEvents are displayed+ * before their ObservationEvent arrives.*/export const getACPToolCallResult = (event: ACPToolCallEvent,diff --git a/src/components/conversation-events/chat/event-content-helpers/should-render-event.ts b/src/components/conversation-events/chat/event-content-helpers/should-render-event.tsindex 18efbbb4e8..cc2e06e53b 100644--- a/src/components/conversation-events/chat/event-content-helpers/should-render-event.ts+++ b/src/components/conversation-events/chat/event-content-helpers/should-render-event.ts@@ -73,20 +73,19 @@ export const shouldRenderEvent = (event: OpenHandsEvent) => {return true;}- // Render ACP sub-agent tool call events only once they've reached a- // terminal status. ACP servers stream multiple events per- // ``tool_call_id`` as the call progresses (status flips- // ``in_progress`` β ``completed`` / ``failed``); during streaming the- // event's ``raw_input`` / ``raw_output`` / ``title`` may still be- // partially populated, so rendering an in-flight event flashes a- // half-formed card that then updates in place β visibly noisy.- // ``null`` (older agent-server builds, before the field was required)- // is also treated as in-flight: better to wait for the terminal event- // than to render a card with no status. ``handleEventForUI`` already- // replaces in place by ``tool_call_id``, so the terminal event lands- // at the original position once it arrives.+ // Render ACP sub-agent tool call events at every lifecycle stage. The SDK+ // now persists exactly two events per ``tool_call_id`` β one early+ // ``started`` event (``pending`` / ``in_progress``) and one terminal+ // (``completed`` / ``failed``) event β the action->observation pair for a+ // tool call. The ``started`` event renders the card as "running" (no check+ // mark; see ``getACPToolCallResult``) and ``handleEventForUI`` replaces it+ // in place by ``tool_call_id`` once the terminal event arrives, mirroring+ // how an ObservationEvent supersedes its ActionEvent. The old terminal-only+ // gate existed because the source fanned out one cumulative-output frame per+ // ``ToolCallProgress``, which flashed half-formed cards mid-stream; that+ // fan-out is gone, so the running card is now a single clean event.if (isACPToolCallEvent(event)) {- return event.status === "completed" || event.status === "failed";+ return true;}// Don't render any other event types (system events, etc.)diff --git a/src/types/agent-server/core/events/acp-tool-call-event.ts b/src/types/agent-server/core/events/acp-tool-call-event.tsindex 4574c08347..5adcb10970 100644--- a/src/types/agent-server/core/events/acp-tool-call-event.ts+++ b/src/types/agent-server/core/events/acp-tool-call-event.ts@@ -8,11 +8,17 @@ import { BaseEvent } from "../base/event";export type ACPToolKind = "execute" | "edit" | "read" | "fetch" | "other";/**- * Status of an ACP tool call. Future ACP streaming (software-agent-sdk#2866)- * will emit multiple events for the same ``tool_call_id`` as the status- * transitions from ``in_progress`` to a terminal value.+ * Status of an ACP tool call. The SDK persists two events per+ * ``tool_call_id``: an early ``started`` event (``pending`` / ``in_progress``)+ * and one terminal event (``completed`` / ``failed``) β the+ * action->observation pair. Non-terminal statuses render the card as+ * "running"; see ``getACPToolCallResult``.*/-export type ACPToolCallStatus = "in_progress" | "completed" | "failed";+export type ACPToolCallStatus =+ | "pending"+ | "in_progress"+ | "completed"+ | "failed";/*** An ACP content block as surfaced on ``ACPToolCallEvent.content``. ACPdiff --git a/src/utils/handle-event-for-ui.ts b/src/utils/handle-event-for-ui.tsindex 8298c7dff5..d3541b085e 100644--- a/src/utils/handle-event-for-ui.ts+++ b/src/utils/handle-event-for-ui.ts@@ -9,9 +9,12 @@ import {* Replaces actions with observations when they arrive (so UI shows observation instead of action)* Exception: ThinkAction is NOT replaced because the thought content is in the action, not in the observation*- * ACPToolCallEvent dedup: multiple events share a ``tool_call_id`` as an ACP- * tool call progresses (in_progress β completed / failed). Collapse them to- * the latest state at the original position so the card updates in place.+ * ACPToolCallEvent merge: the SDK emits two events per ``tool_call_id`` β an+ * early ``started`` event (``pending`` / ``in_progress``) and one terminal+ * (completed / failed) event, the action->observation pair for a tool call.+ * Replace the started entry in place with the terminal one so a single card+ * updates from running to its result, exactly like an observation superseding+ * its action below.*/export const handleEventForUI = (event: OpenHandsEvent,