π OpenHands: AI-Driven Development
V1 chat: small assorted fixes (#164)
Robert Brennan1d3c72ff3a0e
diff --git a/AGENTS.md b/AGENTS.mdindex 9c52009250..b13a177484 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -22,10 +22,12 @@- `__tests__/vite-config.test.ts` should import `vite.config` directly under `// @vitest-environment node`; spawning plain `node -e 'import ./vite.config.ts'` is not portable across Node patch releases in CI.- `vitest.setup.ts` must guard DOM-specific globals (`HTMLCanvasElement`, `HTMLElement`, `window`) because some suites run in the Node environment instead of jsdom.- `__tests__/components/providers/posthog-wrapper.test.tsx` must wrap `PostHogWrapper` in a `QueryClientProvider`; the wrapper now reads its client from React Query context instead of importing the global singleton.+- WebSocket hook regression note: `__tests__/hooks/use-websocket.test.ts`'s `onClose` callback assertion was flaky against the shared MSW websocket server in CI; keep that single test on a deterministic stubbed `WebSocket` close path instead of relying on MSW close timing.+- Library i18n regression note: `__tests__/i18n/library-namespace.test.ts` imports `../../src/index`, which can take >5s under the full Vitest suite after `vi.resetModules()`. Keep an explicit per-test timeout (currently 15s) so the suite doesn't fail on slow workers.+- `src/components/shared/buttons/styled-tooltip.tsx` should keep HeroUI tooltip animations disabled in Vitest (`disableAnimation` when `import.meta.env.MODE === "test"`); otherwise full-suite runs can end with unhandled `window is not defined` rejections from `framer-motion` after jsdom teardown (seen via `recent-conversation` tests in CI).- `__tests__/i18n/library-namespace.test.ts` imports the full library entry and can exceed Vitest's default 5s timeout under full-suite load; keep an explicit higher timeout on that case unless the test is substantially narrowed.-- `@openhands/typescript-client` is consumed directly from `github:OpenHands/typescript-client#6b9603f`; that package ships the needed subpath exports for `client/http-client`, `events/remote-events-list`, and `workspace/remote-workspace`. `RemoteWorkspace.gitChanges`/`gitDiff` accept an optional `{ ref }` option; agent-canvas passes `'HEAD'` so the changes panel reflects working-tree + index versus the latest commit (i.e. staged + unstaged) instead of a diff against the upstream/default branch.- Shared TypeScript-client adapters live in `src/api/typescript-client.ts`; prefer those helpers for agent-server-backed REST/workspace/event/VS Code calls before falling back to `open-hands-axios`.- Local verification/build gotchas:@@ -73,14 +75,14 @@- Git provider token persistence note: `src/api/secrets-service.ts` stores git provider tokens in TWO places:1. **Agent-server secrets API** (`PUT /api/settings/secrets`) with naming convention `GIT_PROVIDER_{PROVIDER}_TOKEN` - for agent runtime use2. **localStorage** (`openhands-agent-server-git-provider-tokens`) - for frontend git API calls (repo search, branches, etc.)- The `addGitProvider` method stores to server FIRST (must succeed), then updates localStorage. This ensures server-side persistence is the source of truth.+ The `addGitProvider` method stores to server FIRST (must succeed), then updates localStorage. This ensures server-side persistence is the source of truth.- Agent server connection settings now live at `Settings > Agent Server` (`/settings/agent-server`). The page reads deployment defaults from `VITE_BACKEND_BASE_URL` / `VITE_SESSION_API_KEY`, saves user overrides in the `openhands-agent-server-config` localStorage key, and must stay reachable even when the backend compatibility probe fails so users can recover from missing or wrong backend configuration.- **SDK Dependency for Settings Persistence (PR #98)**: The settings persistence API changes depend on [software-agent-sdk PR #3060](https://github.com/OpenHands/software-agent-sdk/pull/3060) which adds:- `/api/settings` GET/PATCH with `X-Expose-Secrets: encrypted` header support- `/api/settings/secrets` CRUD endpoints for custom secrets- `OH_SECRET_KEY` environment variable for encryption-+**IMPORTANT**: Until PR #3060 is merged and released, `npm run dev` must use `OH_AGENT_SERVER_GIT_REF=main` to point at the SDK main branch (or the feature branch), not a released PyPI version. The dev scripts now default to `main` for this reason. Once released, update `dev-safe.mjs` to use the minimum required version.- README expectation: keep the first section as a concrete, chronological from-scratch quickstart for running this frontend against a real `openhands-agent-server` (clone, install uv, optional `.env`, run `npm run dev`).@@ -125,7 +127,6 @@- Theme/customization tokens for the embedded shell are exposed as `--oh-*` CSS variables. Override them through `styleOverrides`, `style`, or host CSS targeting `[data-agent-server-ui]`; Tailwind theme tokens in `src/tailwind.css` should continue to reference those variables with `@theme inline` so host apps can restyle the UI without reworking component class names.- Regression coverage for the CSS isolation work lives in `__tests__/agent-server-ui-providers.test.tsx`, `__tests__/agent-server-ui-style-scope.test.ts`, and the browser-level `tests/css-isolation.spec.ts` Playwright test.-- Action grouping in the chat stream:- `src/components/v1/chat/group-events.ts` folds runs of consecutive groupable events (regular `ActionEvent`/`ObservationEvent` cards, but not `FinishAction`, `ThinkAction`, `PlanningFileEditorObservation`, `TaskTrackerObservation`, hooks, errors, or message events) into single `RenderedItem` groups. The threshold lives in `EVENT_GROUP_MIN_SIZE` (currently 2, so even pairs of back-to-back actions get folded).- `EventGroup` (`src/components/v1/chat/event-message-components/event-group.tsx`) is the collapsible header that wraps each run. Default state is collapsed; the header shows `EVENT_GROUP$ACTIONS_COMPLETED` (with a success check) when the group is done, or `EVENT_GROUP$ACTIONS_PROGRESS` plus the currently-running action's title (from `getEventContent`) while a member `ActionEvent` has not yet been replaced by its observation in the UI events array. Expanding renders the original `EventMessage`s verbatim so each card still expands the way it did before.@@ -134,7 +135,6 @@- `EventGroup` should return `null` for an empty `events` array and wire the toggle button to the expanded body with `aria-controls` / `role="region"` / `aria-labelledby`.- `src/components/v1/chat/messages.tsx` is the only consumer; the grouping is transparent to upstream code. Coverage lives in `__tests__/components/v1/chat/group-events.test.ts` (pure logic, including thought hoisting) and `__tests__/components/v1/chat/event-message-components/event-group.test.tsx` (rendering/interaction).-- Library packaging notes:- Public npm entrypoints now come from `src/index.ts` β `src/lib/index.ts`, with domain barrels under `src/components/{conversation,terminal,browser,files,settings,sidebar}/index.ts`.- `npm run build` remains the standalone app build (`react-router build`), while `npm run build:lib` runs `vite build` in library mode plus `tsc -p tsconfig.lib.json` to emit `.d.ts` files into `dist/`.diff --git a/__tests__/components/v1/get-event-content.test.tsx b/__tests__/components/v1/get-event-content.test.tsxindex 4518acf2ad..e26da2a770 100644--- a/__tests__/components/v1/get-event-content.test.tsx+++ b/__tests__/components/v1/get-event-content.test.tsx@@ -81,6 +81,41 @@ describe("getEventContent", () => {).not.toBeInTheDocument();});+ it("ignores the agent-server fallback summary ('tool_name: {args}') and uses the action-kind title", () => {+ // The SDK's `_extract_summary` emits `f"{tool_name}: {json}"` when the+ // LLM omits a summary. That blob should not be shown as the title.+ const actionWithFallbackSummary = {+ ...terminalActionEvent,+ summary: 'terminal: {"command":"git status"}',+ };+ const { title } = getEventContent(actionWithFallbackSummary);++ render(<span>{title}</span>);++ expect(screen.getByText("ACTION_MESSAGE$RUN")).toBeInTheDocument();+ expect(+ screen.queryByText('terminal: {"command":"git status"}'),+ ).not.toBeInTheDocument();+ });++ it("ignores fallback summary on the paired observation as well", () => {+ const actionWithFallbackSummary = {+ ...terminalActionEvent,+ summary: 'terminal: {"command":"git status"}',+ };+ const { title } = getEventContent(+ terminalObservationEvent,+ actionWithFallbackSummary,+ );++ render(<span>{title}</span>);++ expect(screen.getByText("OBSERVATION_MESSAGE$RUN")).toBeInTheDocument();+ expect(+ screen.queryByText('terminal: {"command":"git status"}'),+ ).not.toBeInTheDocument();+ });+it("returns empty details for file view action instead of 'Unknown event'", () => {const fileViewAction: ActionEvent = {id: "action-2",diff --git a/__tests__/hooks/use-websocket.test.ts b/__tests__/hooks/use-websocket.test.tsindex ce98c35b92..39f7ee5bf5 100644--- a/__tests__/hooks/use-websocket.test.ts+++ b/__tests__/hooks/use-websocket.test.ts@@ -6,7 +6,7 @@* to ALL connected clients across all tests, causing cross-test contamination* when tests run in parallel with Vitest v4.*/-import { renderHook, waitFor } from "@testing-library/react";+import { act, renderHook, waitFor } from "@testing-library/react";import {describe,it,@@ -203,26 +203,66 @@ describe("useWebSocket", () => {});it("should call onClose handler when WebSocket connection closes", async () => {+ class MockWebSocket {+ static readonly CONNECTING = 0;+ static readonly OPEN = 1;+ static readonly CLOSING = 2;+ static readonly CLOSED = 3;++ readonly url: string;+ readyState = MockWebSocket.CONNECTING;+ onopen: ((event: Event) => void) | null = null;+ onmessage: ((event: MessageEvent) => void) | null = null;+ onclose: ((event: CloseEvent) => void) | null = null;+ onerror: ((event: Event) => void) | null = null;++ constructor(url: string) {+ this.url = url;+ queueMicrotask(() => {+ this.readyState = MockWebSocket.OPEN;+ this.onopen?.(new Event("open"));+ });+ }++ send() {}++ close() {+ this.readyState = MockWebSocket.CLOSED;+ this.onclose?.(+ new CloseEvent("close", {+ code: 1000,+ reason: "Normal closure",+ wasClean: true,+ }),+ );+ }+ }++ const originalWebSocket = globalThis.WebSocket;+ vi.stubGlobal("WebSocket", MockWebSocket);+const onCloseSpy = vi.fn();const options = { onClose: onCloseSpy };- const { result, unmount } = renderHook(() =>- useWebSocket("ws://acme.com/ws", options),- );-- await waitForConnection(result);+ try {+ const { result, unmount } = renderHook(() =>+ useWebSocket("ws://acme.com/ws", options),+ );- onCloseSpy.mockClear();+ await waitForConnection(result);- // Closing the socket while the hook is still mounted is more reliable in CI- // than waiting for the close event to propagate during unmount cleanup.- result.current.disconnect();+ act(() => {+ result.current.disconnect();+ });- await waitFor(() => {- expect(onCloseSpy).toHaveBeenCalledOnce();- });+ await waitFor(() => {+ expect(onCloseSpy).toHaveBeenCalledOnce();+ });- unmount();+ unmount();+ } finally {+ globalThis.WebSocket = originalWebSocket;+ }});it.skip("should call onMessage handler when WebSocket receives a message", async () => {diff --git a/src/components/features/chat/custom-chat-input.tsx b/src/components/features/chat/custom-chat-input.tsxindex 632b57eac3..317227cad3 100644--- a/src/components/features/chat/custom-chat-input.tsx+++ b/src/components/features/chat/custom-chat-input.tsx@@ -9,14 +9,11 @@ import { ChatInputGrip } from "./components/chat-input-grip";import { ChatInputContainer } from "./components/chat-input-container";import { HiddenFileInput } from "./components/hidden-file-input";import { useConversationStore } from "#/stores/conversation-store";-import { V1ExecutionStatus } from "#/types/v1/core/base/common";-import { isExecutionErrored } from "#/utils/status";export interface CustomChatInputProps {disabled?: boolean;isNewConversationPending?: boolean;showButton?: boolean;- executionStatus?: V1ExecutionStatus | null;onSubmit: (message: string) => void;onFocus?: () => void;onBlur?: () => void;@@ -29,7 +26,6 @@ export function CustomChatInput({disabled = false,isNewConversationPending = false,showButton = true,- executionStatus = null,onSubmit,onFocus,onBlur,@@ -44,7 +40,11 @@ export function CustomChatInput({setSubmittedMessage,} = useConversationStore();- const isDisabled = disabled || isExecutionErrored(executionStatus);+ // Note: we intentionally do NOT disable the input when the conversation is+ // in an ERROR/STUCK execution state. Users should be able to send a follow-up+ // message to recover the conversation; the message will be delivered+ // immediately via the WebSocket if connected, or queued via REST otherwise.+ const isDisabled = disabled;// Listen to submittedMessage state changesuseEffect(() => {diff --git a/src/components/features/chat/generic-event-message.tsx b/src/components/features/chat/generic-event-message.tsxindex ccb29bdb2a..e7e2233fb9 100644--- a/src/components/features/chat/generic-event-message.tsx+++ b/src/components/features/chat/generic-event-message.tsx@@ -62,7 +62,11 @@ export function GenericEventMessage({<div className="flex items-center justify-between font-bold text-neutral-300"><div className="flex items-center">{chevronPosition === "before" && chevron}- {title}+ {/* Wrap the title in a span so any whitespace inside Trans-rendered+ fragments (e.g. "Editing <path>...</path>") is preserved by+ normal inline flow instead of being collapsed between+ anonymous flex items. */}+ <span>{title}</span>{chevronPosition === "after" && chevron}</div>diff --git a/src/components/features/chat/interactive-chat-box.tsx b/src/components/features/chat/interactive-chat-box.tsxindex 766633c34e..c0357e879a 100644--- a/src/components/features/chat/interactive-chat-box.tsx+++ b/src/components/features/chat/interactive-chat-box.tsx@@ -164,7 +164,6 @@ export function InteractiveChatBox({isNewConversationPending={disabled}onSubmit={handleSubmit}onFilesPaste={handleUpload}- executionStatus={conversation?.execution_status || null}/><div className="mt-4"><GitControlBar onSuggestionsClick={handleSuggestionsClick} />diff --git a/src/components/v1/chat/event-content-helpers/get-event-content.tsx b/src/components/v1/chat/event-content-helpers/get-event-content.tsxindex b1550f19fc..47f1dc6508 100644--- a/src/components/v1/chat/event-content-helpers/get-event-content.tsx+++ b/src/components/v1/chat/event-content-helpers/get-event-content.tsx@@ -46,11 +46,25 @@ const createTitleFromKey = ();};+/**+ * Detects the agent-server's default summary fallback, which has the shape+ * `{tool_name}: {json-args}` (see `_extract_summary` in+ * `openhands/sdk/agent/agent.py`). When the LLM omits a summary the server+ * dumps the raw arguments JSON, which renders as a huge unreadable blob in+ * the chat. Treat that case as "no summary" so the action-kind specific+ * title (e.g. "Editing <path>", "Running <cmd>") is used instead.+ */+const isServerFallbackSummary = (summary: string): boolean =>+ /^[a-z][a-z0-9_]*\s*:\s*[[{]/i.test(summary);+const getSummaryTitleForActionEvent = (event: ActionEvent,): React.ReactNode | null => {const summary = event.summary?.trim().replace(/\s+/g, " ") || "";- return summary || null;+ if (!summary || isServerFallbackSummary(summary)) {+ return null;+ }+ return summary;};// Action Event Processingdiff --git a/src/hooks/use-handle-ws-events.ts b/src/hooks/use-handle-ws-events.tsindex 2e87dc4c50..7cdd76b78b 100644--- a/src/hooks/use-handle-ws-events.ts+++ b/src/hooks/use-handle-ws-events.ts@@ -4,6 +4,7 @@ import { AgentState } from "#/types/agent-state";import { displayErrorToast } from "#/utils/custom-toast-handlers";import { useEventStore } from "#/stores/use-event-store";import { useSendMessage } from "#/hooks/use-send-message";+import { isAgentErrorEvent, isV1Event } from "#/types/v1/type-guards";interface ServerError {error: boolean | string;@@ -23,6 +24,12 @@ export const useHandleWSEvents = () => {}const event = events[events.length - 1];+ // V1 agent errors are surfaced inline in the chat log (and via the error+ // banner), so don't double-notify with a toast.+ if (isV1Event(event) && isAgentErrorEvent(event)) {+ return;+ }+if (isServerError(event)) {if (event.error_code === 401) {displayErrorToast("Session expired.");