π OpenHands: AI-Driven Development
feat: use async conversations and interrupt endpoint for local mode (#670)
Rohit Malhotraeee7fe1b7a3e
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.tsindex 5de384f974..dadff5853b 100644--- a/__tests__/api/agent-server-adapter.test.ts+++ b/__tests__/api/agent-server-adapter.test.ts@@ -337,6 +337,7 @@ describe("buildStartConversationRequest", () => {expect(payload.initial_message).toEqual({role: "user",content: [{ type: "text", text: "Follow the repo conventions." }],+ run: true,});});diff --git a/__tests__/api/agent-server-conversation-service.test.ts b/__tests__/api/agent-server-conversation-service.test.tsindex 63247e65f1..14b460a3a0 100644--- a/__tests__/api/agent-server-conversation-service.test.ts+++ b/__tests__/api/agent-server-conversation-service.test.ts@@ -71,11 +71,15 @@ vi.mock("@openhands/typescript-client/clients", async () => {};});-vi.mock("@openhands/typescript-client/client/http-client", () => ({- HttpClient: vi.fn(function HttpClientMock() {- return { post: mockSdkHttpPost };- }),-}));+vi.mock("@openhands/typescript-client/client/http-client", async (importOriginal) => {+ const actual = await importOriginal<typeof import("@openhands/typescript-client/client/http-client")>();+ return {+ ...actual,+ HttpClient: vi.fn(function HttpClientMock() {+ return { post: mockSdkHttpPost };+ }),+ };+});vi.mock("#/api/agent-server-config", () => ({DEFAULT_WORKING_DIR: "workspace/project",diff --git a/__tests__/hooks/mutation/pause-conversation-local.test.ts b/__tests__/hooks/mutation/pause-conversation-local.test.tsnew file mode 100644index 0000000000..17bafd83d2--- /dev/null+++ b/__tests__/hooks/mutation/pause-conversation-local.test.ts@@ -0,0 +1,93 @@+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import {+ __resetActiveStoreForTests,+ setActiveSelection,+ setRegisteredBackends,+} from "#/api/backend-registry/active-store";+import type { Backend } from "#/api/backend-registry/types";+import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";+import type { AppConversation } from "#/api/conversation-service/agent-server-conversation-service.types";+import { pauseConversation } from "#/hooks/mutation/conversation-mutation-utils";+import { ExecutionStatus } from "#/types/agent-server/core/base/common";++const { interruptConversationMock } = vi.hoisted(() => ({+ interruptConversationMock: vi.fn(),+}));++vi.mock("@openhands/typescript-client/clients", () => ({+ ConversationClient: vi.fn(function ConversationClientMock() {+ return { interruptConversation: interruptConversationMock };+ }),+}));++const localBackend: Backend = {+ id: "local",+ name: "Local",+ host: "http://localhost:18000",+ apiKey: "test-key",+ kind: "local",+};++const buildConversation = (+ overrides: Partial<AppConversation> = {},+): AppConversation => ({+ id: "conv-local-1",+ created_by_user_id: null,+ selected_repository: null,+ selected_branch: null,+ git_provider: null,+ title: "Test",+ trigger: null,+ pr_number: [],+ llm_model: null,+ metrics: null,+ created_at: "2026-04-16T00:00:00Z",+ updated_at: "2026-04-16T00:00:00Z",+ execution_status: ExecutionStatus.RUNNING,+ conversation_url: "http://localhost:18000",+ session_api_key: "sess-key",+ sandbox_id: null,+ sub_conversation_ids: [],+ ...overrides,+});++beforeEach(() => {+ window.localStorage.clear();+ __resetActiveStoreForTests();+ setRegisteredBackends([localBackend]);+ setActiveSelection({ backendId: localBackend.id });+ interruptConversationMock.mockReset();+});++afterEach(() => {+ window.localStorage.clear();+ __resetActiveStoreForTests();+ vi.restoreAllMocks();+});++describe("pauseConversation local branch", () => {+ it("calls interruptConversation on the local agent server", async () => {+ vi.spyOn(+ AgentServerConversationService,+ "batchGetAppConversations",+ ).mockResolvedValue([buildConversation()]);+ interruptConversationMock.mockResolvedValue({ success: true });++ await pauseConversation("conv-local-1");++ expect(interruptConversationMock).toHaveBeenCalledOnce();+ expect(interruptConversationMock).toHaveBeenCalledWith("conv-local-1");+ });++ it("propagates errors from interruptConversation", async () => {+ vi.spyOn(+ AgentServerConversationService,+ "batchGetAppConversations",+ ).mockResolvedValue([buildConversation()]);+ interruptConversationMock.mockRejectedValue(new Error("interrupt failed"));++ await expect(pauseConversation("conv-local-1")).rejects.toThrow(+ "interrupt failed",+ );+ });+});diff --git a/__tests__/scripts/dev-safe.test.ts b/__tests__/scripts/dev-safe.test.tsindex f78b44fd58..2f540d1492 100644--- a/__tests__/scripts/dev-safe.test.ts+++ b/__tests__/scripts/dev-safe.test.ts@@ -319,14 +319,14 @@ describe("buildAgentServerCommand", () => {// Defaults to the released PyPI version with all SDK packages pinned to same versionexpect(cmd.args).toEqual(["--from",- "openhands-agent-server==1.22.1",+ "openhands-agent-server==1.23.0","--with",- "openhands-tools==1.22.1",+ "openhands-tools==1.23.0","--with",- "openhands-workspace==1.22.1",+ "openhands-workspace==1.23.0","agent-server",]);- expect(cmd.source).toBe("PyPI (1.22.1, default)");+ expect(cmd.source).toBe("PyPI (1.23.0, default)");});it("uses specific PyPI version when OH_AGENT_SERVER_VERSION is set with all packages pinned", () => {diff --git a/config/defaults.json b/config/defaults.jsonindex 6a95a0570e..636e573102 100644--- a/config/defaults.json+++ b/config/defaults.json@@ -2,7 +2,7 @@"_comment": "Single source of truth for version pins, ports, paths, and defaults shared across the npm and Docker install paths. Read by scripts/dev-safe.mjs, scripts/dev-with-automation.mjs, docker/entrypoint.sh (via generated defaults.env), and .github/workflows/docker.yml.","versions": {- "agentServer": "1.22.1",+ "agentServer": "1.23.0","automation": "1.0.0a3","automationSdk": "1.22.1"},diff --git a/package-lock.json b/package-lock.jsonindex 336a80283a..78b5a2e28e 100644--- a/package-lock.json+++ b/package-lock.json@@ -13,7 +13,7 @@"@microlink/react-json-view": "1.31.20","@monaco-editor/react": "4.7.0","@openhands/extensions": "git+https://github.com/OpenHands/extensions.git#7b33f64ffccf95f7ccd2ec640aeae84ab1cc2c75",- "@openhands/typescript-client": "git+https://github.com/OpenHands/typescript-client.git#v0.6.0",+ "@openhands/typescript-client": "git+https://github.com/OpenHands/typescript-client.git#af9688c493d465b38c99dbac2302d462c76dc8ff","@react-router/node": "7.14.2","@react-router/serve": "7.14.2","@tailwindcss/vite": "4.2.4",@@ -3441,7 +3441,7 @@},"node_modules/@openhands/extensions": {"version": "0.0.0",- "resolved": "git+https://github.com/OpenHands/extensions.git#7b33f64ffccf95f7ccd2ec640aeae84ab1cc2c75",+ "resolved": "git+ssh://[email protected]/OpenHands/extensions.git#7b33f64ffccf95f7ccd2ec640aeae84ab1cc2c75","integrity": "sha512-vozWq4MJiKoColb7zvXYgtxmWJsk7LdjdRH9SQebheHDOKvDAn7xy+sM7d0mEFRCk3QDEaVyR5HMH9w/1HH25Q==","license": "MIT","engines": {@@ -3455,7 +3455,8 @@},"node_modules/@openhands/typescript-client": {"version": "0.1.1",- "resolved": "git+ssh://[email protected]/OpenHands/typescript-client.git#ef62e82fc3dfb03991a1c8025429caf354427263",+ "resolved": "git+ssh://[email protected]/OpenHands/typescript-client.git#af9688c493d465b38c99dbac2302d462c76dc8ff",+ "integrity": "sha512-JAf4cQ594Zwrjbc51A3/toES8/G5FReGZFayB6v5fZRGJsmCOrDg0lnfBlqHjspt1d4Bz6qHceBFLzhG/I2Oyg==","license": "MIT","dependencies": {"@openrouter/sdk": "^0.12.35",diff --git a/package.json b/package.jsonindex 657226e914..70b4b1c881 100644--- a/package.json+++ b/package.json@@ -24,7 +24,7 @@"@microlink/react-json-view": "1.31.20","@monaco-editor/react": "4.7.0","@openhands/extensions": "git+https://github.com/OpenHands/extensions.git#7b33f64ffccf95f7ccd2ec640aeae84ab1cc2c75",- "@openhands/typescript-client": "git+https://github.com/OpenHands/typescript-client.git#v0.6.0",+ "@openhands/typescript-client": "git+https://github.com/OpenHands/typescript-client.git#af9688c493d465b38c99dbac2302d462c76dc8ff","@react-router/node": "7.14.2","@react-router/serve": "7.14.2","@tailwindcss/vite": "4.2.4",diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.tsindex 4554bdf5e1..5feb1d6119 100644--- a/src/api/agent-server-adapter.ts+++ b/src/api/agent-server-adapter.ts@@ -484,6 +484,7 @@ function buildInitialMessage(return {role: "user",content: [{ type: "text", text: parts.join("\n\n") }],+ run: true,};}diff --git a/src/contexts/conversation-websocket-context.tsx b/src/contexts/conversation-websocket-context.tsxindex dd28175999..c8c0a05859 100644--- a/src/contexts/conversation-websocket-context.tsx+++ b/src/contexts/conversation-websocket-context.tsx@@ -863,8 +863,9 @@ export function ConversationWebSocketProvider({}try {- // Send message through WebSocket as JSON- currentSocket.send(JSON.stringify(message));+ // Send message through WebSocket as JSON with run: true so the+ // agent loop starts automatically in async mode.+ currentSocket.send(JSON.stringify({ ...message, run: true }));return { queued: false };} catch (error) {const errorMessage =diff --git a/src/hooks/mutation/conversation-mutation-utils.ts b/src/hooks/mutation/conversation-mutation-utils.tsindex 288c0f2a77..a652ac3774 100644--- a/src/hooks/mutation/conversation-mutation-utils.ts+++ b/src/hooks/mutation/conversation-mutation-utils.ts@@ -32,6 +32,11 @@ const fetchConversationData = async (};};+/**+ * Stop a running conversation.+ * - Cloud mode: Pauses the sandbox (waits for current LLM call to finish).+ * - Local mode: Interrupts immediately (cancels in-flight requests).+ */export const pauseConversation = async (conversationId: string) => {const { conversationUrl, sessionApiKey, sandboxId } =await fetchConversationData(conversationId);@@ -46,9 +51,12 @@ export const pauseConversation = async (conversationId: string) => {return { success: true };}+ // In local mode, use /interrupt instead of /pause so in-flight LLM+ // requests are cancelled immediately rather than waiting for the+ // current call to finish.return new ConversationClient(getAgentServerClientOptions({ conversationUrl, sessionApiKey }),- ).pauseConversation(conversationId);+ ).interruptConversation(conversationId);};/**diff --git a/src/mocks/conversation-handlers.ts b/src/mocks/conversation-handlers.tsindex e0e72dad77..5cecc52bdb 100644--- a/src/mocks/conversation-handlers.ts+++ b/src/mocks/conversation-handlers.ts@@ -316,6 +316,10 @@ export const CONVERSATION_HANDLERS = [HttpResponse.json({ success: true }),),+ http.post("*/api/conversations/:conversationId/interrupt", async () =>+ HttpResponse.json({ success: true }),+ ),+http.post("*/api/conversations/:conversationId/run", async () =>HttpResponse.json({ success: true }),),diff --git a/vite.config.ts b/vite.config.tsindex 40375c28a6..aedbfd8896 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -340,6 +340,11 @@ export default defineConfig(({ mode }) => {environment: "jsdom",setupFiles: ["vitest.setup.ts"],exclude: [...configDefaults.exclude, "tests"],+ server: {+ deps: {+ inline: ["@openhands/typescript-client"],+ },+ },coverage: {reporter: ["text", "json", "html", "lcov", "text-summary"],reportsDirectory: "coverage",