π OpenHands: AI-Driven Development
fix(conversation): wake the paused cloud sandbox from Resume instead of calling its runtime (OHE-3407) (#18442)
Hiep Le71427af5b426
diff --git a/__tests__/hooks/mutation/conversation-mutation-utils.test.ts b/__tests__/hooks/mutation/conversation-mutation-utils.test.tsindex e0642acacb..57f75916c5 100644--- a/__tests__/hooks/mutation/conversation-mutation-utils.test.ts+++ b/__tests__/hooks/mutation/conversation-mutation-utils.test.ts@@ -23,6 +23,7 @@ const mocks = vi.hoisted(() => ({getAgentServerClientOptions: vi.fn(),interruptConversation: vi.fn(),pauseCloudSandbox: vi.fn(),+ resumeCloudSandbox: vi.fn(),resumeGoal: vi.fn(),runConversation: vi.fn(),startGoal: vi.fn(),@@ -51,6 +52,7 @@ vi.mock("#/api/backend-registry/active-store", () => ({vi.mock("#/api/cloud/conversation-service.api", () => ({pauseCloudSandbox: mocks.pauseCloudSandbox,+ resumeCloudSandbox: mocks.resumeCloudSandbox,}));vi.mock("#/api/agent-server-client-options", () => ({@@ -265,6 +267,42 @@ describe("conversation runtime commands", () => {expect(mocks.runConversation).toHaveBeenCalledOnce();expect(mocks.runConversation).toHaveBeenCalledWith(CONV_ID);});++ it("wakes the cloud sandbox instead of calling a runtime that has no URL yet", async () => {+ prepareRuntimeConversation({+ conversation_url: null,+ session_api_key: null,+ sandbox_status: "PAUSED",+ });+ mocks.getActiveBackend.mockReturnValueOnce({ backend: { kind: "cloud" } });+ mocks.resumeCloudSandbox.mockResolvedValueOnce(undefined);++ await expect(resumeConversation(CONV_ID)).resolves.toEqual({+ success: true,+ });++ expect(mocks.resumeCloudSandbox).toHaveBeenCalledOnce();+ expect(mocks.resumeCloudSandbox).toHaveBeenCalledWith("sandbox-1");+ expect(mocks.runConversation).not.toHaveBeenCalled();+ expect(mocks.getAgentServerClientOptions).not.toHaveBeenCalled();+ });++ it("names the conversation when a paused cloud sandbox has no sandbox id to wake", async () => {+ prepareRuntimeConversation({+ conversation_url: null,+ session_api_key: null,+ sandbox_id: null,+ sandbox_status: "PAUSED",+ });+ mocks.getActiveBackend.mockReturnValueOnce({ backend: { kind: "cloud" } });++ await expect(resumeConversation(CONV_ID)).rejects.toThrow(+ `cloud conversation ${CONV_ID} has no sandbox_id`,+ );++ expect(mocks.resumeCloudSandbox).not.toHaveBeenCalled();+ expect(mocks.runConversation).not.toHaveBeenCalled();+ });it("hands saved secrets to a local conversation as value-free lookups", async () => {const conversation = prepareRuntimeConversation();mocks.getActiveBackend.mockReturnValueOnce({ backend: { kind: "local" } });diff --git a/src/hooks/mutation/conversation-mutation-utils.ts b/src/hooks/mutation/conversation-mutation-utils.tsindex 9ef87cab60..ed47975076 100644--- a/src/hooks/mutation/conversation-mutation-utils.ts+++ b/src/hooks/mutation/conversation-mutation-utils.ts@@ -2,7 +2,10 @@ import { QueryClient } from "@tanstack/react-query";import { ConversationClient } from "@openhands/typescript-client/clients";import type { StartGoalRequest } from "@openhands/typescript-client";import { getActiveBackend } from "#/api/backend-registry/active-store";-import { pauseCloudSandbox } from "#/api/cloud/conversation-service.api";+import {+ pauseCloudSandbox,+ resumeCloudSandbox,+} from "#/api/cloud/conversation-service.api";import { getAgentServerClientOptions } from "#/api/agent-server-client-options";import {buildCustomSecrets,@@ -139,9 +142,27 @@ export const updateConversationSecrets = async ().updateSecrets(conversationId, { secrets });};+/**+ * Resume a conversation.+ * - Cloud mode with a paused/starting sandbox: the runtime has no URL until the+ * sandbox is RUNNING, so there is nothing to call; wake the sandbox instead+ * (mirrors `pauseConversation`). The status poll picks up the transition.+ * - Otherwise: resume the agent through the conversation's runtime.+ */export const resumeConversation = async (conversationId: string) => {- const { conversationUrl, sessionApiKey } =+ const { conversationUrl, sessionApiKey, sandboxId } =await fetchConversationData(conversationId);++ if (!conversationUrl && getActiveBackend().backend.kind === "cloud") {+ if (!sandboxId) {+ throw new Error(+ `Cannot resume: cloud conversation ${conversationId} has no sandbox_id.`,+ );+ }+ await resumeCloudSandbox(sandboxId);+ return { success: true };+ }+return new ConversationClient(getAgentServerClientOptions({ conversationUrl, sessionApiKey }),).runConversation(conversationId);