π OpenHands: AI-Driven Development
feat(chat): render empty-response corrective nudge as an informational note (#17864)
Denis Ermakovfd848e28cd7d
diff --git a/.github/pr-assets/issue-16815-01-before.png b/.github/pr-assets/issue-16815-01-before.pngnew file mode 100644index 0000000000..acc7d02fcfBinary files /dev/null and b/.github/pr-assets/issue-16815-01-before.png differdiff --git a/.github/pr-assets/issue-16815-02-after.png b/.github/pr-assets/issue-16815-02-after.pngnew file mode 100644index 0000000000..57d7889b16Binary files /dev/null and b/.github/pr-assets/issue-16815-02-after.png differdiff --git a/__tests__/components/conversation-events/chat/event-message-corrective-nudge.test.tsx b/__tests__/components/conversation-events/chat/event-message-corrective-nudge.test.tsxnew file mode 100644index 0000000000..49ff3d9c46--- /dev/null+++ b/__tests__/components/conversation-events/chat/event-message-corrective-nudge.test.tsx@@ -0,0 +1,93 @@+import { describe, expect, it, vi, beforeEach } from "vitest";+import { screen } from "@testing-library/react";+import { EventMessage } from "#/components/conversation-events/chat/event-message";+import { useAgentState } from "#/hooks/use-agent-state";+import { AgentState } from "#/types/agent-state";+import { MessageEvent } from "#/types/agent-server/core";+import { renderWithProviders } from "test-utils";++vi.mock("#/hooks/query/use-config", () => ({+ useConfig: () => ({+ data: {},+ }),+}));++vi.mock("#/hooks/use-agent-state");++vi.mock("#/hooks/use-conversation-id", () => ({+ useOptionalConversationId: () => ({ conversationId: "test-conversation-id" }),+ useConversationId: () => ({ conversationId: "test-conversation-id" }),+}));++// Emitted by the SDK's `_send_corrective_nudge` (response_dispatch.py).+const CORRECTIVE_NUDGE_TEXT =+ "Your last response did not include a function call or a message. Please use a tool to proceed with the task.";++const createMessageEvent = (+ source: MessageEvent["source"],+ role: MessageEvent["llm_message"]["role"],+ text: string,+): MessageEvent => ({+ id: `${source}-message-1`,+ timestamp: "2024-01-01T00:00:00.000Z",+ source,+ llm_message: {+ role,+ content: [{ type: "text", text }],+ },+ activated_skills: [],+ extended_content: [],+});++const renderEvent = (event: MessageEvent) =>+ renderWithProviders(+ <EventMessage+ event={event}+ messages={[event]}+ isLastMessage={false}+ isInLast10Actions={false}+ />,+ );++describe("EventMessage - empty-response corrective nudge", () => {+ beforeEach(() => {+ vi.mocked(useAgentState).mockReturnValue({+ curAgentState: AgentState.INIT,+ });+ });++ it("renders the SDK corrective nudge as an informational note instead of a chat message", () => {+ const event = createMessageEvent(+ "environment",+ "user",+ CORRECTIVE_NUDGE_TEXT,+ );++ renderEvent(event);++ const note = screen.getByTestId("corrective-nudge-message");+ expect(note).toHaveTextContent(CORRECTIVE_NUDGE_TEXT);+ expect(note.querySelector("svg")).toBeInTheDocument();+ expect(screen.queryByTestId("environment-message")).not.toBeInTheDocument();+ });++ it.each([+ ["user", "user", "Please fix the failing test"],+ ["agent", "assistant", "I fixed the failing test"],+ ["environment", "user", "Some other framework message"],+ // Only the framework's own nudge qualifies, not a user typing its text.+ ["user", "user", CORRECTIVE_NUDGE_TEXT],+ ] as const)(+ "keeps the regular chat message for a %s-sourced %s message",+ (source, role, text) => {+ const event = createMessageEvent(source, role, text);++ renderEvent(event);++ expect(screen.getByTestId(`${source}-message`)).toHaveTextContent(text);+ expect(+ screen.queryByTestId("corrective-nudge-message"),+ ).not.toBeInTheDocument();+ },+ );+});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 c287a473cd..cfbe5b44f0 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@@ -42,6 +42,14 @@ const isGoalLoopReprompt = (event: MessageEvent): boolean => {return GOAL_REPROMPT_PREFIXES.some((prefix) => text.startsWith(prefix));};+// SDK empty-response nudge (`_send_corrective_nudge`); keep in sync with the SDK.+const CORRECTIVE_NUDGE_PREFIX =+ "Your last response did not include a function call or a message.";++export const isCorrectiveNudge = (event: MessageEvent): boolean =>+ event.source === "environment" &&+ (userMessageText(event)?.startsWith(CORRECTIVE_NUDGE_PREFIX) ?? false);+// The frontend posts the outcome of a `launch_child_conversation` call back as// a `user` message because client tools have no result channel (see// `services/child-conversation-launch.ts`). It is a JSON payload addressed todiff --git a/src/components/conversation-events/chat/event-message-components/corrective-nudge-message.tsx b/src/components/conversation-events/chat/event-message-components/corrective-nudge-message.tsxnew file mode 100644index 0000000000..f81b214b03--- /dev/null+++ b/src/components/conversation-events/chat/event-message-components/corrective-nudge-message.tsx@@ -0,0 +1,27 @@+import { MessageEvent } from "#/types/agent-server/core";+import InfoCircleIcon from "#/icons/info-circle.svg?react";+import { parseMessageFromEvent } from "../event-content-helpers/parse-message-from-event";++interface CorrectiveNudgeMessageProps {+ event: MessageEvent;+}++export function CorrectiveNudgeMessage({ event }: CorrectiveNudgeMessageProps) {+ return (+ <div+ role="note"+ data-testid="corrective-nudge-message"+ className="mt-6 flex w-full items-start gap-1.5 text-sm italic text-muted last:mb-4"+ >+ <InfoCircleIcon+ width={14}+ height={14}+ className="mt-[5px] shrink-0"+ aria-hidden+ />+ <span className="leading-6 [word-break:break-word]">+ {parseMessageFromEvent(event)}+ </span>+ </div>+ );+}diff --git a/src/components/conversation-events/chat/event-message.tsx b/src/components/conversation-events/chat/event-message.tsxindex 5e6fac8a6f..602d419111 100644--- a/src/components/conversation-events/chat/event-message.tsx+++ b/src/components/conversation-events/chat/event-message.tsx@@ -34,7 +34,9 @@ import { GenericEventMessageWrapper } from "./event-message-components/generic-eimport { ThoughtEventMessage } from "./event-message-components/thought-event-message";import { CollapsibleThinking } from "./event-message-components/collapsible-thinking";import { HookExecutionEventMessage } from "./event-message-components/hook-execution-event-message";+import { CorrectiveNudgeMessage } from "./event-message-components/corrective-nudge-message";import { createSkillReadyEvent } from "./event-content-helpers/create-skill-ready-event";+import { isCorrectiveNudge } from "./event-content-helpers/should-render-event";import { shouldShowPlanPreview } from "./hooks/use-plan-preview-events";import { getReasoningContent, splitInlineThink } from "./event-thought-helpers";import { useStreamedText } from "#/hooks/use-streamed-text";@@ -372,6 +374,10 @@ function EventMessageComponent({if (!isActionEvent(event) && !isObservationEvent(event)) {const messageEvent = event as MessageEvent;+ if (isCorrectiveNudge(messageEvent)) {+ return <CorrectiveNudgeMessage event={messageEvent} />;+ }+// Check if this is a user message that should display a Skill Ready eventif (isUserMessageEvent(event) && shouldShowSkillReadyEvent(messageEvent)) {return renderUserMessageWithSkillReady(