🙌 OpenHands: AI-Driven Development
fix: resolve rejected and errored actions in event groups (#17995)
Denis Ermakovefa2e78a47ee
diff --git a/.pr/issue-17920/after.png b/.pr/issue-17920/after.pngnew file mode 100644index 0000000000..54f4164f03Binary files /dev/null and b/.pr/issue-17920/after.png differdiff --git a/.pr/issue-17920/after.webm b/.pr/issue-17920/after.webmnew file mode 100644index 0000000000..0dc4c9500cBinary files /dev/null and b/.pr/issue-17920/after.webm differdiff --git a/.pr/issue-17920/before.png b/.pr/issue-17920/before.pngnew file mode 100644index 0000000000..38d814be0bBinary files /dev/null and b/.pr/issue-17920/before.png differdiff --git a/.pr/issue-17920/before.webm b/.pr/issue-17920/before.webmnew file mode 100644index 0000000000..b59ab97111Binary files /dev/null and b/.pr/issue-17920/before.webm differdiff --git a/__tests__/components/conversation-events/chat/event-message-components/event-group.test.tsx b/__tests__/components/conversation-events/chat/event-message-components/event-group.test.tsxindex 264d5cb20c..6514e6500c 100644--- a/__tests__/components/conversation-events/chat/event-message-components/event-group.test.tsx+++ b/__tests__/components/conversation-events/chat/event-message-components/event-group.test.tsx@@ -5,8 +5,10 @@ import { renderWithProviders } from "test-utils";import { EventGroup } from "#/components/conversation-events/chat/event-message-components/event-group";import {ActionEvent,+ AgentErrorEvent,ObservationEvent,SecurityRisk,+ UserRejectObservation,} from "#/types/agent-server/core";import {ExecuteBashAction,@@ -66,6 +68,32 @@ const makeBashObservation = (},});+const makeUserRejectObservation = (+ id: string,+ actionId: string,+): UserRejectObservation => ({+ id,+ timestamp: new Date().toISOString(),+ source: "environment",+ tool_name: "execute_bash",+ tool_call_id: `call_${actionId}`,+ action_id: actionId,+ rejection_reason: "User rejected the action",+});++const makeAgentErrorEvent = (+ id: string,+ actionId: string,+): AgentErrorEvent => ({+ id,+ timestamp: new Date().toISOString(),+ kind: "AgentErrorEvent",+ source: "agent",+ tool_name: "execute_bash",+ tool_call_id: `call_${actionId}`,+ error: "boom",+});+describe("EventGroup", () => {it("returns null for an empty events array", () => {const { container } = renderWithProviders(@@ -195,6 +223,44 @@ describe("EventGroup", () => {expect(screen.queryByTestId("status-icon")).not.toBeInTheDocument();});+ it("titles a settled group after its rejected action", () => {+ const events = [+ makeBashObservation("o1", "a1", "ls"),+ makeUserRejectObservation("r2", "a2"),+ ];+ const allEvents = [makeBashAction("a2", "pwd"), ...events];++ renderWithProviders(+ <EventGroup events={events} allEvents={allEvents}>+ <div>child</div>+ </EventGroup>,+ );++ expect(screen.getByText(/ACTION_MESSAGE\$RUN/)).toBeInTheDocument();+ expect(+ screen.getByText("EVENT_GROUP$ACTIONS_COMPLETED"),+ ).toBeInTheDocument();+ });++ it("counts an action resolved by an AgentErrorEvent as resolved instead of running", () => {+ const events = [+ makeBashObservation("o1", "a1", "ls"),+ makeBashAction("a2", "pwd"),+ ];+ const allEvents = [...events, makeAgentErrorEvent("e2", "a2")];++ renderWithProviders(+ <EventGroup events={events} allEvents={allEvents}>+ <div>child</div>+ </EventGroup>,+ );++ expect(screen.queryByTestId("spinner-icon")).not.toBeInTheDocument();+ expect(+ screen.getByText("EVENT_GROUP$ACTIONS_COMPLETED"),+ ).toBeInTheDocument();+ });+it("updates accessibility state while toggling the group", async () => {const events = [makeBashObservation("o1", "a1", "ls"),diff --git a/__tests__/components/conversation-events/chat/group-events.test.ts b/__tests__/components/conversation-events/chat/group-events.test.tsindex b2bc99762f..028327cc61 100644--- a/__tests__/components/conversation-events/chat/group-events.test.ts+++ b/__tests__/components/conversation-events/chat/group-events.test.ts@@ -10,6 +10,7 @@ import {MessageEvent,ObservationEvent,SecurityRisk,+ UserRejectObservation,} from "#/types/agent-server/core";import { TextContent } from "#/types/agent-server/core/base/common";import {@@ -167,6 +168,19 @@ const makeAgentErrorEvent = (id: string): AgentErrorEvent => ({error: "boom",});+const makeUserRejectObservation = (+ id: string,+ actionId: string,+): UserRejectObservation => ({+ id,+ timestamp: new Date().toISOString(),+ source: "environment",+ tool_name: "execute_bash",+ tool_call_id: `call_${actionId}`,+ action_id: actionId,+ rejection_reason: "User rejected the action",+});+const makeHookExecutionEvent = (id: string): HookExecutionEvent => ({id,timestamp: new Date().toISOString(),@@ -337,6 +351,41 @@ describe("groupEvents", () => {}});+ it("keeps a rejected action in its group", () => {+ const events = [+ makeBashObservation("o1", "a1"),+ makeUserRejectObservation("r2", "a2"),+ ];++ const result = groupEvents(events);++ expect(result).toEqual([{ kind: "group", events, startIndex: 0 }]);+ });++ it("keeps a rejected markdown create outside the group", () => {+ const action = makeMarkdownFileEditorAction("a2");+ const events = [+ makeBashObservation("o1", "a1"),+ makeUserRejectObservation("r2", "a2"),+ ];++ const result = groupEvents(events, undefined, [action, ...events]);++ expect(result.map((item) => item.kind)).toEqual(["single", "single"]);+ });++ it("hoists the thought of a rejected action", () => {+ const action = makeBashAction("a1", [{ type: "text", text: "Let me try" }]);+ const rejection = makeUserRejectObservation("r1", "a1");++ const result = groupEvents([rejection], undefined, [action, rejection]);++ expect(result).toEqual([+ { kind: "thought", action, index: 0 },+ { kind: "single", event: rejection, index: 0 },+ ]);+ });+it("breaks the group when a non-groupable event interrupts", () => {const events = [makeBashObservation("o1", "a1"),diff --git a/__tests__/components/conversation-events/chat/messages-confirmation.test.tsx b/__tests__/components/conversation-events/chat/messages-confirmation.test.tsxindex 7eb84db8aa..5ddd144c10 100644--- a/__tests__/components/conversation-events/chat/messages-confirmation.test.tsx+++ b/__tests__/components/conversation-events/chat/messages-confirmation.test.tsx@@ -1,10 +1,20 @@import { describe, expect, it, vi, beforeEach } from "vitest";import { screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";import { Messages } from "#/components/conversation-events/chat/messages";import { useEventStore } from "#/stores/use-event-store";import { AgentState } from "#/types/agent-state";-import { ActionEvent, SecurityRisk } from "#/types/agent-server/core";+import {+ ActionEvent,+ ObservationEvent,+ OpenHandsEvent,+ SecurityRisk,+ UserRejectObservation,+} from "#/types/agent-server/core";import { ExecuteBashAction } from "#/types/agent-server/core/base/action";+import { ExecuteBashObservation } from "#/types/agent-server/core/base/observation";+import { shouldRenderEvent } from "#/components/conversation-events/chat/event-content-helpers/should-render-event";+import { handleEventForUI } from "#/utils/handle-event-for-ui";import { renderWithProviders } from "test-utils";vi.mock("#/hooks/query/use-config", () => ({@@ -61,6 +71,38 @@ const createBashActionEvent = (security_risk: SecurityRisk.HIGH,});+const createBashObservationEvent = (+ action: ActionEvent<ExecuteBashAction>,+): ObservationEvent<ExecuteBashObservation> => ({+ id: `observation-${action.id}`,+ timestamp: new Date().toISOString(),+ source: "environment",+ tool_name: action.tool_name,+ tool_call_id: action.tool_call_id,+ action_id: action.id,+ observation: {+ kind: "ExecuteBashObservation",+ content: [{ type: "text", text: "ok" }],+ command: action.action.command,+ exit_code: 0,+ error: false,+ timeout: false,+ metadata: {} as never,+ },+});++const createUserRejectObservation = (+ action: ActionEvent,+): UserRejectObservation => ({+ id: `rejection-${action.id}`,+ timestamp: new Date().toISOString(),+ source: "environment",+ tool_name: action.tool_name,+ tool_call_id: action.tool_call_id,+ action_id: action.id,+ rejection_reason: "User rejected the action",+});+describe("Messages confirmation prompt", () => {beforeEach(() => {useEventStore.setState({@@ -97,4 +139,28 @@ describe("Messages confirmation prompt", () => {expect(screen.getByTestId("action-reject-button")).toBeInTheDocument();expect(screen.getByTestId("action-confirm-button")).toBeInTheDocument();});++ it("settles the group and marks the action as rejected after the user rejects it", async () => {+ const user = userEvent.setup();+ const confirmed = createBashActionEvent("action-1", "echo first");+ const rejected = createBashActionEvent("action-2", "echo second");+ const allEvents: OpenHandsEvent[] = [+ confirmed,+ createBashObservationEvent(confirmed),+ rejected,+ createUserRejectObservation(rejected),+ ];+ // Same projection the live chat, shared route and transcript export use.+ const messages = allEvents+ .reduce<+ OpenHandsEvent[]+ >((uiEvents, event) => handleEventForUI(event, uiEvents), [])+ .filter(shouldRenderEvent);++ renderWithProviders(<Messages messages={messages} allEvents={allEvents} />);++ expect(screen.queryByTestId("spinner-icon")).not.toBeInTheDocument();+ await user.click(screen.getByTestId("event-group-toggle"));+ expect(screen.getByTestId("rejected-indicator")).toBeInTheDocument();+ });});diff --git a/__tests__/utils/handle-event-for-ui.test.ts b/__tests__/utils/handle-event-for-ui.test.tsindex 63182b53d3..065bc571dc 100644--- a/__tests__/utils/handle-event-for-ui.test.ts+++ b/__tests__/utils/handle-event-for-ui.test.ts@@ -5,6 +5,7 @@ import {MessageEvent,SecurityRisk,OpenHandsEvent,+ UserRejectObservation,} from "#/types/agent-server/core";import { ACPToolCallEvent } from "#/types/agent-server/core/events/acp-tool-call-event";import { StreamingDeltaEvent } from "#/types/agent-server/core/events/streaming-delta-event";@@ -154,6 +155,36 @@ describe("handleEventForUI", () => {expect(result).not.toBe(initialUiEvents); // Should return a new array});+ const makeRejection = (action: ActionEvent): UserRejectObservation => ({+ id: `rejection-${action.id}`,+ timestamp: Date.now().toString(),+ source: "environment",+ tool_name: action.tool_name,+ tool_call_id: action.tool_call_id,+ rejection_reason: "User rejected the action",+ action_id: action.id,+ });++ it("should replace corresponding action with its UserRejectObservation", () => {+ const rejection = makeRejection(mockActionEvent);+ const initialUiEvents = [mockMessageEvent, mockActionEvent];++ const result = handleEventForUI(rejection, initialUiEvents);++ expect(result).toEqual([mockMessageEvent, rejection]);+ });++ it("should NOT replace FinishAction with its UserRejectObservation", () => {+ const initialUiEvents = [mockMessageEvent, mockFinishActionEvent];++ const result = handleEventForUI(+ makeRejection(mockFinishActionEvent),+ initialUiEvents,+ );++ expect(result).toEqual(initialUiEvents);+ });+it("should add observation to end when corresponding action is not found", () => {const initialUiEvents = [mockMessageEvent];const result = handleEventForUI(mockObservationEvent, initialUiEvents);diff --git a/src/components/conversation-events/chat/event-content-helpers/get-event-content.tsx b/src/components/conversation-events/chat/event-content-helpers/get-event-content.tsxindex bb1ccff2ec..59d1dad0b8 100644--- a/src/components/conversation-events/chat/event-content-helpers/get-event-content.tsx+++ b/src/components/conversation-events/chat/event-content-helpers/get-event-content.tsx@@ -12,6 +12,7 @@ import {isObservationEvent,isACPToolCallEvent,isCanvasUIActionEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import { MonoComponent } from "../../../features/chat/mono-component";import { PathComponent } from "../../../features/chat/path-component";@@ -343,6 +344,18 @@ export const getEventContent = (resolveVisualizerBody(event, correspondingAction) ??getObservationContent(event);}+ } else if (isUserRejectObservation(event)) {+ // A rejected action never ran, so there is no result to show: keep the+ // action's own title and body, and let the card mark it as rejected.+ if (correspondingAction) {+ title = getActionEventTitle(correspondingAction);+ details =+ resolveVisualizerBody(correspondingAction) ??+ getActionContent(correspondingAction);+ } else {+ title = event.tool_name;+ details = event.rejection_reason;+ }} else if (isACPToolCallEvent(event)) {// ACP sub-agent tool calls reuse the same card shape as observations:// title is "Running/Editing/Reading …" via a translation key thatdiff --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 cfbe5b44f0..eab2513e6e 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@@ -10,6 +10,7 @@ import {isHookExecutionEvent,isACPToolCallEvent,isStreamingDeltaEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";// Prefixes of the SDK goal-loop re-prompts (FOLLOWUP_PROMPT / RESUME_PROMPT in@@ -114,6 +115,12 @@ export const shouldRenderEvent = (event: OpenHandsEvent) => {return true;}+ // Render the rejection that replaced a rejected action, so the action stays+ // in the chat marked as rejected instead of vanishing+ if (isUserRejectObservation(event)) {+ return true;+ }+// Render message events (user and assistant messages), except the goal loop's// injected re-prompts — the judge feedback they carry is shown in the goal// banner, so otherwise they leak into the chat as fake user turns — and thediff --git a/src/components/conversation-events/chat/event-message-components/event-group.tsx b/src/components/conversation-events/chat/event-message-components/event-group.tsxindex 4e4feb4321..eb2eea8875 100644--- a/src/components/conversation-events/chat/event-message-components/event-group.tsx+++ b/src/components/conversation-events/chat/event-message-components/event-group.tsx@@ -6,7 +6,9 @@ import ArrowUp from "#/icons/angle-up-solid.svg?react";import { OpenHandsEvent, ActionEvent } from "#/types/agent-server/core";import {isActionEvent,+ isAgentErrorEvent,isObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import { I18nKey } from "#/i18n/declaration";import { getEventContent } from "../event-content-helpers/get-event-content";@@ -19,8 +21,9 @@ interface EventGroupProps {/*** Full event history. Used to resolve the action that produced the latest* observation in the group so the summary title matches what the individual- * card would show (e.g. "Editing path/to/file"). Falls back to `events` when- * omitted.+ * card would show (e.g. "Editing path/to/file"), and to find the+ * `AgentErrorEvent` that resolved an action without an observation. Falls+ * back to `events` when omitted.*/allEvents?: OpenHandsEvent[];/**@@ -71,25 +74,39 @@ export function EventGroup({return null;}- // Each ObservationEvent in the group is a completed action. An ActionEvent- // that's still here (i.e. not yet replaced by its observation in the UI- // events array) is an action currently in flight.- const pendingAction = events.find((e): e is ActionEvent => isActionEvent(e));- const completedCount = events.filter(isObservationEvent).length;+ // Each ObservationEvent (or UserRejectObservation) in the group is a+ // resolved action. An ActionEvent that's still here (i.e. not yet replaced+ // in the UI events array) is an action currently in flight, unless an+ // AgentErrorEvent resolved it: that event carries no action id and renders+ // on its own, so it never replaces the action it answers.+ const lookupSource = allEvents ?? events;+ const unreplacedActions = events.filter(isActionEvent);+ const erroredToolCallIds =+ unreplacedActions.length > 0+ ? new Set(+ lookupSource.filter(isAgentErrorEvent).map((e) => e.tool_call_id),+ )+ : null;+ const pendingActions = unreplacedActions.filter(+ (action) => !erroredToolCallIds?.has(action.tool_call_id),+ );const totalCount = events.length;- const isRunning = !!pendingAction;+ const completedCount = totalCount - pendingActions.length;+ const isRunning = pendingActions.length > 0;// Title of the most recent groupable event. While running this is the- // pending action; otherwise it's the latest observation, with its- // originating action looked up so the title can be the action-style summary- // ("Editing path/to/file") instead of the observation default.+ // pending action; otherwise it's the latest observation (or rejection), with+ // its originating action looked up so the title can be the action-style+ // summary ("Editing path/to/file") instead of the observation default.const latestEvent = events[events.length - 1];let latestTitle: React.ReactNode = null;if (latestEvent) {if (isActionEvent(latestEvent)) {latestTitle = getEventContent(latestEvent).title;- } else if (isObservationEvent(latestEvent)) {- const lookupSource = allEvents ?? events;+ } else if (+ isObservationEvent(latestEvent) ||+ isUserRejectObservation(latestEvent)+ ) {const correspondingAction = lookupSource.find((e): e is ActionEvent =>isActionEvent(e) && e.id === latestEvent.action_id,diff --git a/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx b/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsxindex 77657e7039..859a7344f4 100644--- a/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx+++ b/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx@@ -1,3 +1,4 @@+import { useTranslation } from "react-i18next";import {OpenHandsEvent,ActionEvent,@@ -15,6 +16,7 @@ import {import {isACPToolCallEvent,isObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import {SkillReadyEvent,@@ -68,6 +70,7 @@ export function GenericEventMessageWrapper({event,correspondingAction,}: GenericEventMessageWrapperProps) {+ const { t } = useTranslation("openhands");const { title, details } = getEventContent(event, correspondingAction);// TaskTrackerObservation has its own rendering@@ -116,6 +119,16 @@ export function GenericEventMessageWrapper({success={success}initiallyExpanded={initiallyExpanded}timestamp={event.timestamp}+ titleTrailing={+ !isSkillReadyEvent(event) && isUserRejectObservation(event) ? (+ <span+ data-testid="rejected-indicator"+ className="ml-2 flex-shrink-0 text-danger"+ >+ {t(I18nKey.EVENT$REJECTED)}+ </span>+ ) : undefined+ }titleIcon={skillKnowledge ? (<SkillsIcon className="h-4 w-4 stroke-muted flex-shrink-0 mr-2" />diff --git a/src/components/conversation-events/chat/event-message.tsx b/src/components/conversation-events/chat/event-message.tsxindex 602d419111..fbd3ca44ba 100644--- a/src/components/conversation-events/chat/event-message.tsx+++ b/src/components/conversation-events/chat/event-message.tsx@@ -11,6 +11,7 @@ import {import {isActionEvent,isObservationEvent,+ isUserRejectObservation,isAgentErrorEvent,isUserMessageEvent,isPlanningFileEditorObservationEvent,@@ -370,6 +371,31 @@ function EventMessageComponent({);}+ // Rejected actions - render thought + the rejected action+ if (isUserRejectObservation(event)) {+ const correspondingAction = suppliedCorrespondingAction ?? undefined;+ const reasoningContent = correspondingAction+ ? getReasoningContent(correspondingAction)+ : "";++ return (+ <>+ {reasoningContent && <CollapsibleThinking content={reasoningContent} />}+ {!suppressThought && correspondingAction && (+ <ThoughtEventMessage+ event={correspondingAction}+ isFromPlanningAgent={isFromPlanningAgent}+ />+ )}+ <GenericEventMessageWrapper+ event={event}+ isLastMessage={isLastMessage}+ correspondingAction={correspondingAction}+ />+ </>+ );+ }+// Message events (user and assistant messages)if (!isActionEvent(event) && !isObservationEvent(event)) {const messageEvent = event as MessageEvent;diff --git a/src/components/conversation-events/chat/event-thought-helpers.ts b/src/components/conversation-events/chat/event-thought-helpers.tsindex 4f7a43c575..51d353060e 100644--- a/src/components/conversation-events/chat/event-thought-helpers.ts+++ b/src/components/conversation-events/chat/event-thought-helpers.ts@@ -3,6 +3,7 @@ import { ThinkingBlock } from "#/types/agent-server/core/base/event";import {isActionEvent,isObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";/**@@ -87,7 +88,8 @@ export const splitInlineThink = (/*** Find the `ActionEvent` whose thought should be rendered alongside the* given UI event. For an `ActionEvent` the thought belongs to itself; for- * an `ObservationEvent` we look up the matching action in `allEvents`.+ * an `ObservationEvent` (or the `UserRejectObservation` of a rejected+ * action) we look up the matching action in `allEvents`.** `ThinkAction` is intentionally excluded because its thought IS the* action body and is rendered through a separate codepath.@@ -101,7 +103,7 @@ export const getThoughtSourceAction = (return hasNonEmptyThought(event) ? event : null;}- if (isObservationEvent(event)) {+ if (isObservationEvent(event) || isUserRejectObservation(event)) {const action = allEvents.find((e): e is ActionEvent => isActionEvent(e) && e.id === event.action_id,);diff --git a/src/components/conversation-events/chat/group-events.ts b/src/components/conversation-events/chat/group-events.tsindex 44dab427d4..479beb1438 100644--- a/src/components/conversation-events/chat/group-events.ts+++ b/src/components/conversation-events/chat/group-events.ts@@ -3,6 +3,7 @@ import {isActionEvent,isObservationEvent,isPlanningFileEditorObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import { isMarkdownFileEditorEvent } from "#/components/features/chat/tool-visualizers/primitives/markdown-file-preview";import { getThoughtSourceAction } from "./event-thought-helpers";@@ -50,6 +51,12 @@ export const isGroupableEvent = (return true;}+ // A rejected action stays wherever the action itself was: in its run, or+ // on its own when the action is a group breaker.+ if (isUserRejectObservation(event)) {+ return correspondingAction ? isGroupableEvent(correspondingAction) : true;+ }+return false;};@@ -104,12 +111,13 @@ export const groupEvents = (};events.forEach((event, index) => {- const correspondingAction = isObservationEvent(event)- ? allEvents.find(- (candidate): candidate is ActionEvent =>- isActionEvent(candidate) && candidate.id === event.action_id,- )- : undefined;+ const correspondingAction =+ isObservationEvent(event) || isUserRejectObservation(event)+ ? allEvents.find(+ (candidate): candidate is ActionEvent =>+ isActionEvent(candidate) && candidate.id === event.action_id,+ )+ : undefined;if (isGroupableEvent(event, correspondingAction)) {const thoughtAction = getThoughtSourceAction(event, allEvents);if (thoughtAction && !emittedThoughtActionIds.has(thoughtAction.id)) {diff --git a/src/components/conversation-events/chat/messages.tsx b/src/components/conversation-events/chat/messages.tsxindex 9a1bceb2d6..91e85f391a 100644--- a/src/components/conversation-events/chat/messages.tsx+++ b/src/components/conversation-events/chat/messages.tsx@@ -3,6 +3,7 @@ import { ActionEvent, OpenHandsEvent } from "#/types/agent-server/core";import {isActionEvent,isObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import { EventMessage } from "./event-message";import { usePlanPreviewEvents } from "./hooks/use-plan-preview-events";@@ -85,7 +86,8 @@ export const Messages: React.FC<MessagesProps> = React.memo(key={event.id}event={event}correspondingAction={- isObservationEvent(event) && event.action_id+ (isObservationEvent(event) || isUserRejectObservation(event)) &&+ event.action_id? (actionById.get(event.action_id) ?? null): null}diff --git a/src/components/features/chat/typing-indicator.tsx b/src/components/features/chat/typing-indicator.tsxindex e5ea1837ed..130537b504 100644--- a/src/components/features/chat/typing-indicator.tsx+++ b/src/components/features/chat/typing-indicator.tsx@@ -1,11 +1,11 @@import { Trans } from "react-i18next";import type { OHEvent } from "#/stores/use-event-store";-import type { UserRejectObservation } from "#/types/agent-server/core";import {isACPToolCallEvent,isActionEvent,isAgentErrorEvent,isObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import {getACPToolCallTitleKey,@@ -62,11 +62,6 @@ const getLiveActionTitle = (event: OHEvent): EventTitleDescriptor | null => {: null;};-const isUserRejectObservation = (- event: OHEvent,-): event is UserRejectObservation =>- event.source === "environment" && "rejection_reason" in event;-export const deriveLiveActivity = (events: readonly OHEvent[],): EventTitleDescriptor => {diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 001d07a403..91e6971c58 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -1104,6 +1104,23 @@"uk": "Невідома подія","ca": "Esdeveniment desconegut"},+ "EVENT$REJECTED": {+ "en": "Rejected",+ "ja": "拒否済み",+ "zh-CN": "已拒绝",+ "zh-TW": "已拒絕",+ "ko-KR": "거부됨",+ "no": "Avvist",+ "it": "Rifiutata",+ "pt": "Rejeitada",+ "es": "Rechazada",+ "ar": "مرفوض",+ "fr": "Rejetée",+ "tr": "Reddedildi",+ "de": "Abgelehnt",+ "uk": "Відхилено",+ "ca": "Rebutjada"+ },"OBSERVATION$COMMAND_NO_OUTPUT": {"en": "[Command finished execution with no output]","ja": "[コマンドは出力なしで実行を終了しました]",diff --git a/src/types/agent-server/type-guards.ts b/src/types/agent-server/type-guards.tsindex d709e01ecf..a3150f9f5a 100644--- a/src/types/agent-server/type-guards.ts+++ b/src/types/agent-server/type-guards.ts@@ -22,7 +22,10 @@ import {CanvasUIAction,LaunchChildConversationAction,} from "./core";-import { AgentErrorEvent } from "./core/events/observation-event";+import {+ AgentErrorEvent,+ UserRejectObservation,+} from "./core/events/observation-event";import { MessageEvent } from "./core/events/message-event";import { ActionEvent } from "./core/events/action-event";import {@@ -77,6 +80,17 @@ export const isObservationEvent = (typeof event.observation === "object" &&"kind" in event.observation;+/**+ * Type guard function to check if an event is a user reject observation+ * (an action rejected in confirmation mode or blocked by a PreToolUse hook)+ */+export const isUserRejectObservation = (+ event: OpenHandsEvent,+): event is UserRejectObservation =>+ event.source === "environment" &&+ "action_id" in event &&+ "rejection_reason" in event;+/*** Type guard function to check if an event is an agent error event*/diff --git a/src/utils/handle-event-for-ui.ts b/src/utils/handle-event-for-ui.tsindex 444a482496..86a3ece432 100644--- a/src/utils/handle-event-for-ui.ts+++ b/src/utils/handle-event-for-ui.ts@@ -1,8 +1,10 @@import { OpenHandsEvent } from "#/types/agent-server/core";import {isACPToolCallEvent,+ isActionEvent,isObservationEvent,isStreamingDeltaEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import { StreamingDeltaEvent } from "#/types/agent-server/core/events/streaming-delta-event";import type {@@ -315,7 +317,27 @@ export const handleEventForUI = (if (event.observation.kind === "FinishObservation") {return newUiEvents;}+ }++ if (isUserRejectObservation(event)) {+ // Like their observations above, a rejection never replaces a ThinkAction+ // or FinishAction: the content to display is in the action itself+ const rejectedAction = newUiEvents.find(+ (uiEvent) => uiEvent.id === event.action_id,+ );+ if (+ rejectedAction &&+ isActionEvent(rejectedAction) &&+ (rejectedAction.action.kind === "ThinkAction" ||+ rejectedAction.action.kind === "FinishAction")+ ) {+ return newUiEvents;+ }+ }+ // A UserRejectObservation resolves its action just like an observation+ // does; left unreplaced, the rejected action would keep reading as in flight.+ if (isObservationEvent(event) || isUserRejectObservation(event)) {// Find and replace the corresponding action from uiEventsconst actionIndex = newUiEvents.findIndex((uiEvent) => uiEvent.id === event.action_id,diff --git a/src/utils/transcript-export/index.test.ts b/src/utils/transcript-export/index.test.tsindex e016432c50..8f1eeb346f 100644--- a/src/utils/transcript-export/index.test.ts+++ b/src/utils/transcript-export/index.test.ts@@ -4,6 +4,7 @@ import type {AgentErrorEvent,MessageEvent,ObservationEvent,+ UserRejectObservation,} from "#/types/agent-server/core";import type {ExecuteBashAction,@@ -28,6 +29,7 @@ vi.mock("#/i18n", () => ({ACTION_MESSAGE$ACP_TOOL: "Use tool",CHAT_INTERFACE$ASSISTANT: "Assistant",COMMON$ERROR: "Error",+ EVENT$REJECTED: "Rejected",TASK$QUERY: "Query",TASK$RESULT: "Result",TASK$SUBAGENT: "Subagent",@@ -191,6 +193,26 @@ describe("conversation transcript export", () => {expect(markdown).not.toContain("x".repeat(1001));});+ it("exports a rejected tool call as rejected with its reason", () => {+ const rejection: UserRejectObservation = {+ id: "rejection-1",+ timestamp,+ source: "environment",+ tool_name: "terminal",+ tool_call_id: "tool-1",+ action_id: "action-1",+ rejection_reason: "User rejected the action",+ };++ const markdown = eventsToMarkdown(+ [terminalAction, rejection],+ defaultOptions,+ );++ expect(markdown).toContain("Run the unit tests (Rejected)");+ expect(markdown).toContain("User rejected the action");+ });+it("exports assistant narration once when an observation replaces its action", () => {const narratedAction: ActionEvent<ExecuteBashAction> = {...terminalAction,diff --git a/src/utils/transcript-export/index.ts b/src/utils/transcript-export/index.tsindex 75570dc33a..d305a3a6d0 100644--- a/src/utils/transcript-export/index.ts+++ b/src/utils/transcript-export/index.ts@@ -17,6 +17,7 @@ import {isStreamingDeltaEvent,isSwitchLLMObservationEvent,isClassifyAndSwitchLLMObservationEvent,+ isUserRejectObservation,} from "#/types/agent-server/type-guards";import { handleEventForUI } from "#/utils/handle-event-for-ui";import { markdownFence } from "#/utils/markdown-fence";@@ -323,7 +324,7 @@ const buildTranscriptEntries = (try {const narrationAction = isActionEvent(event)? event- : isObservationEvent(event)+ : isObservationEvent(event) || isUserRejectObservation(event)? actionsById.get(event.action_id): undefined;if (narrationAction) addActionNarration(narrationAction);@@ -473,6 +474,21 @@ const buildTranscriptEntries = (continue;}+ if (isUserRejectObservation(event)) {+ const rejectedAction = actionsById.get(event.action_id);+ entries.push({+ kind: "tool",+ summary: `${+ rejectedAction+ ? getActionSummary(rejectedAction)+ : cleanInlineText(event.tool_name)+ } (${i18n.t(I18nKey.EVENT$REJECTED)})`,+ details: includeToolDetails ? event.rejection_reason : "",+ timestamp: event.timestamp ?? "",+ });+ continue;+ }+if (isACPToolCallEvent(event)) {entries.push({kind: "tool",