Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): stop polling app-conversations with task IDs on new conversation (#14989)

Hiep Le3dafef983f5a
diff --git a/frontend/__tests__/hooks/query/use-batch-app-conversations.test.tsx b/frontend/__tests__/hooks/query/use-batch-app-conversations.test.tsx
new file mode 100644
index 0000000000..872e331efd
--- /dev/null
+++ b/frontend/__tests__/hooks/query/use-batch-app-conversations.test.tsx
@@ -0,0 +1,58 @@
+import { renderHook, waitFor } from "@testing-library/react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import React from "react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";
+import { useBatchAppConversations } from "#/hooks/query/use-batch-app-conversations";
+
+const createWrapper = () => {
+ const queryClient = new QueryClient({
+ defaultOptions: {
+ queries: { retry: false },
+ },
+ });
+
+ return ({ children }: { children: React.ReactNode }) => (
+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
+ );
+};
+
+describe("useBatchAppConversations", () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it("does not call the app-conversations endpoint for task IDs", () => {
+ // Arrange: a task ID (format "task-{uuid}") is not a valid conversation UUID
+ const batchGetAppConversations = vi
+ .spyOn(V1ConversationService, "batchGetAppConversations")
+ .mockResolvedValue([]);
+
+ // Act
+ renderHook(
+ () => useBatchAppConversations(["task-949349dbeae346e895e25679b16f8193"]),
+ { wrapper: createWrapper() },
+ );
+
+ // Assert: the endpoint is never hit, so the backend never returns a 400
+ expect(batchGetAppConversations).not.toHaveBeenCalled();
+ });
+
+ it("calls the app-conversations endpoint for valid conversation IDs", async () => {
+ // Arrange
+ const conversationId = "5c99c669-1151-4413-a75d-1fa4f2cc5355";
+ const batchGetAppConversations = vi
+ .spyOn(V1ConversationService, "batchGetAppConversations")
+ .mockResolvedValue([]);
+
+ // Act
+ renderHook(() => useBatchAppConversations([conversationId]), {
+ wrapper: createWrapper(),
+ });
+
+ // Assert
+ await waitFor(() =>
+ expect(batchGetAppConversations).toHaveBeenCalledWith([conversationId]),
+ );
+ });
+});
diff --git a/frontend/src/hooks/query/use-batch-app-conversations.ts b/frontend/src/hooks/query/use-batch-app-conversations.ts
index 0218359450..6fd0c550cf 100644
--- a/frontend/src/hooks/query/use-batch-app-conversations.ts
+++ b/frontend/src/hooks/query/use-batch-app-conversations.ts
@@ -5,7 +5,8 @@ export const useBatchAppConversations = (ids: string[]) =>
useQuery({
queryKey: ["v1-batch-get-app-conversations", ids],
queryFn: () => V1ConversationService.batchGetAppConversations(ids),
- enabled: ids.length > 0,
+ // task-{uuid} IDs are not valid conversation UUIDs; skip to avoid a 400.
+ enabled: ids.length > 0 && !ids.some((id) => id.startsWith("task-")),
staleTime: 1000 * 60 * 5, // 5 minutes
gcTime: 1000 * 60 * 15, // 15 minutes
});
diff --git a/frontend/src/hooks/query/use-unified-vscode-url.ts b/frontend/src/hooks/query/use-unified-vscode-url.ts
index 892ba32811..ddc9be3783 100644
--- a/frontend/src/hooks/query/use-unified-vscode-url.ts
+++ b/frontend/src/hooks/query/use-unified-vscode-url.ts
@@ -20,9 +20,13 @@ export const useUnifiedVSCodeUrl = () => {
const { conversationId } = useConversationId();
const runtimeIsReady = useRuntimeIsReady({ allowAgentError: true });
+ // Don't fetch for task IDs (format: "task-{uuid}"); the real conversation ID is
+ // resolved by useTaskPolling. Mirrors useActiveConversation.
+ const isTaskId = conversationId.startsWith("task-");
+
// Fetch V1 app conversation to get sandbox_id
const appConversationsQuery = useBatchAppConversations(
- conversationId ? [conversationId] : [],
+ isTaskId ? [] : [conversationId],
);
const appConversation = appConversationsQuery.data?.[0];
const sandboxId = appConversation?.sandbox_id;