Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: prevent V0 conversation creation due to settings race condition (#13628)

Xingyao Wang9ad47bf43fe2
diff --git a/frontend/__tests__/components/features/home/new-conversation.test.tsx b/frontend/__tests__/components/features/home/new-conversation.test.tsx
index d947f2a017..c392ec85cf 100644
--- a/frontend/__tests__/components/features/home/new-conversation.test.tsx
+++ b/frontend/__tests__/components/features/home/new-conversation.test.tsx
@@ -3,9 +3,23 @@ import { render, screen } from "@testing-library/react";
import { createRoutesStub } from "react-router";
import { describe, expect, it, vi } from "vitest";
import userEvent from "@testing-library/user-event";
-import ConversationService from "#/api/conversation-service/conversation-service.api";
+import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";
import { NewConversation } from "#/components/features/home/new-conversation/new-conversation";
+vi.mock("#/hooks/query/use-settings", async () => {
+ const actual = await vi.importActual<typeof import("#/hooks/query/use-settings")>(
+ "#/hooks/query/use-settings",
+ );
+ return {
+ ...actual,
+ getSettingsQueryFn: vi.fn().mockResolvedValue({ v1_enabled: true }),
+ };
+});
+
+vi.mock("#/context/use-selected-organization", () => ({
+ useSelectedOrganizationId: () => ({ organizationId: null }),
+}));
+
// Mock the translation function
vi.mock("react-i18next", async () => {
const actual = await vi.importActual("react-i18next");
@@ -50,31 +64,52 @@ const renderNewConversation = () => {
describe("NewConversation", () => {
it("should create an empty conversation and redirect when pressing the launch from scratch button", async () => {
- const createConversationSpy = vi.spyOn(
- ConversationService,
- "createConversation",
- );
+ const createConversationSpy = vi
+ .spyOn(V1ConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ created_by_user_id: null,
+ status: "READY",
+ detail: null,
+ app_conversation_id: "conv-123",
+ sandbox_id: null,
+ agent_server_url: "http://agent-server.local",
+ request: {
+ sandbox_id: null,
+ initial_message: null,
+ processors: [],
+ llm_model: null,
+ selected_repository: null,
+ selected_branch: null,
+ git_provider: "github",
+ suggested_task: null,
+ title: null,
+ trigger: null,
+ pr_number: [],
+ parent_conversation_id: null,
+ agent_type: "default",
+ },
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ });
renderNewConversation();
const launchButton = screen.getByTestId("launch-new-conversation-button");
await userEvent.click(launchButton);
- expect(createConversationSpy).toHaveBeenCalledExactlyOnceWith(
- undefined,
- undefined,
- undefined,
- undefined,
- undefined,
- undefined,
- undefined,
- );
+ expect(createConversationSpy).toHaveBeenCalledOnce();
// expect to be redirected to /conversations/:conversationId
await screen.findByTestId("conversation-screen");
});
it("should change the launch button text to 'Loading...' when creating a conversation", async () => {
+ // Mock V1 API to never resolve, keeping the mutation in loading state
+ vi.spyOn(V1ConversationService, "createConversation").mockImplementation(
+ () => new Promise(() => {}),
+ );
+
renderNewConversation();
const launchButton = screen.getByTestId("launch-new-conversation-button");
diff --git a/frontend/__tests__/components/features/home/repo-connector.test.tsx b/frontend/__tests__/components/features/home/repo-connector.test.tsx
index 4cba3850b4..1dad4e3dc3 100644
--- a/frontend/__tests__/components/features/home/repo-connector.test.tsx
+++ b/frontend/__tests__/components/features/home/repo-connector.test.tsx
@@ -4,7 +4,7 @@ import userEvent from "@testing-library/user-event";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
import { createRoutesStub, Outlet } from "react-router";
import SettingsService from "#/api/settings-service/settings-service.api";
-import ConversationService from "#/api/conversation-service/conversation-service.api";
+import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";
import GitService from "#/api/git-service/git-service.api";
import OptionService from "#/api/option-service/option-service.api";
import { GitRepository } from "#/types/git";
@@ -314,23 +314,34 @@ describe("RepoConnector", () => {
});
it("should create a conversation and redirect with the selected repo when pressing the launch button", async () => {
- const createConversationSpy = vi.spyOn(
- ConversationService,
- "createConversation",
- );
- createConversationSpy.mockResolvedValue({
- conversation_id: "mock-conversation-id",
- title: "Test Conversation",
- selected_repository: "user/repo1",
- selected_branch: "main",
- git_provider: "github",
- last_updated_at: "2023-01-01T00:00:00Z",
- created_at: "2023-01-01T00:00:00Z",
- status: "STARTING",
- runtime_status: null,
- url: null,
- session_api_key: null,
- });
+ const createConversationSpy = vi
+ .spyOn(V1ConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ created_by_user_id: null,
+ status: "READY",
+ detail: null,
+ app_conversation_id: "mock-conversation-id",
+ sandbox_id: null,
+ agent_server_url: "http://agent-server.local",
+ request: {
+ sandbox_id: null,
+ initial_message: null,
+ processors: [],
+ llm_model: null,
+ selected_repository: "rbren/polaris",
+ selected_branch: "main",
+ git_provider: "github",
+ suggested_task: null,
+ title: null,
+ trigger: null,
+ pr_number: [],
+ parent_conversation_id: null,
+ agent_type: "default",
+ },
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ });
const retrieveUserGitRepositoriesSpy = vi.spyOn(
GitService,
"retrieveUserGitRepositories",
@@ -390,20 +401,24 @@ describe("RepoConnector", () => {
await userEvent.click(launchButton);
- expect(createConversationSpy).toHaveBeenCalledExactlyOnceWith(
+ expect(createConversationSpy).toHaveBeenCalledOnce();
+ expect(createConversationSpy).toHaveBeenCalledWith(
"rbren/polaris",
"github",
undefined,
- undefined,
"main",
undefined,
undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
);
});
it("should change the launch button text to 'Loading...' when creating a conversation", async () => {
const createConversationSpy = vi.spyOn(
- ConversationService,
+ V1ConversationService,
"createConversation",
);
createConversationSpy.mockImplementation(() => new Promise(() => { })); // Never resolves to keep loading state
diff --git a/frontend/__tests__/components/features/home/task-card.test.tsx b/frontend/__tests__/components/features/home/task-card.test.tsx
index 48746270df..ec4fb57147 100644
--- a/frontend/__tests__/components/features/home/task-card.test.tsx
+++ b/frontend/__tests__/components/features/home/task-card.test.tsx
@@ -1,15 +1,28 @@
-import { render, screen } from "@testing-library/react";
+import { render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import userEvent from "@testing-library/user-event";
import { createRoutesStub } from "react-router";
-import ConversationService from "#/api/conversation-service/conversation-service.api";
-import UserService from "#/api/user-service/user-service.api";
+import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";
import GitService from "#/api/git-service/git-service.api";
import { TaskCard } from "#/components/features/home/tasks/task-card";
import { GitRepository } from "#/types/git";
import { SuggestedTask } from "#/utils/types";
+vi.mock("#/hooks/query/use-settings", async () => {
+ const actual = await vi.importActual<typeof import("#/hooks/query/use-settings")>(
+ "#/hooks/query/use-settings",
+ );
+ return {
+ ...actual,
+ getSettingsQueryFn: vi.fn().mockResolvedValue({ v1_enabled: true }),
+ };
+});
+
+vi.mock("#/context/use-selected-organization", () => ({
+ useSelectedOrganizationId: () => ({ organizationId: null }),
+}));
+
const MOCK_TASK_1: SuggestedTask = {
issue_number: 123,
repo: "repo1",
@@ -56,17 +69,43 @@ describe("TaskCard", () => {
});
it("should call createConversation when clicking the launch button", async () => {
- const createConversationSpy = vi.spyOn(
- ConversationService,
- "createConversation",
- );
+ const createConversationSpy = vi
+ .spyOn(V1ConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ created_by_user_id: null,
+ status: "READY",
+ detail: null,
+ app_conversation_id: "conv-123",
+ sandbox_id: null,
+ agent_server_url: "http://agent-server.local",
+ request: {
+ sandbox_id: null,
+ initial_message: null,
+ processors: [],
+ llm_model: null,
+ selected_repository: null,
+ selected_branch: null,
+ git_provider: "github",
+ suggested_task: null,
+ title: null,
+ trigger: null,
+ pr_number: [],
+ parent_conversation_id: null,
+ agent_type: "default",
+ },
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ });
renderTaskCard();
const launchButton = screen.getByTestId("task-launch-button");
await userEvent.click(launchButton);
- expect(createConversationSpy).toHaveBeenCalled();
+ await waitFor(() => {
+ expect(createConversationSpy).toHaveBeenCalled();
+ });
});
describe("creating suggested task conversation", () => {
@@ -82,10 +121,34 @@ describe("TaskCard", () => {
});
it("should call create conversation with suggest task trigger and selected suggested task", async () => {
- const createConversationSpy = vi.spyOn(
- ConversationService,
- "createConversation",
- );
+ const createConversationSpy = vi
+ .spyOn(V1ConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ created_by_user_id: null,
+ status: "READY",
+ detail: null,
+ app_conversation_id: "conv-123",
+ sandbox_id: null,
+ agent_server_url: "http://agent-server.local",
+ request: {
+ sandbox_id: null,
+ initial_message: null,
+ processors: [],
+ llm_model: null,
+ selected_repository: MOCK_RESPOSITORIES[0].full_name,
+ selected_branch: null,
+ git_provider: "github",
+ suggested_task: null,
+ title: null,
+ trigger: null,
+ pr_number: [],
+ parent_conversation_id: null,
+ agent_type: "default",
+ },
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ });
renderTaskCard(MOCK_TASK_1);
@@ -96,6 +159,8 @@ describe("TaskCard", () => {
MOCK_RESPOSITORIES[0].full_name,
MOCK_RESPOSITORIES[0].git_provider,
undefined,
+ undefined,
+ undefined,
{
git_provider: "github",
issue_number: 123,
@@ -106,27 +171,37 @@ describe("TaskCard", () => {
undefined,
undefined,
undefined,
+ undefined,
);
});
});
it("should navigate to the conversation page after creating a conversation", async () => {
- const createConversationSpy = vi.spyOn(
- ConversationService,
- "createConversation",
- );
- createConversationSpy.mockResolvedValue({
- conversation_id: "test-conversation-id",
- title: "Test Conversation",
- selected_repository: "repo1",
- selected_branch: "main",
- git_provider: "github",
- last_updated_at: "2023-01-01T00:00:00Z",
- created_at: "2023-01-01T00:00:00Z",
- status: "RUNNING",
- runtime_status: "STATUS$READY",
- url: null,
- session_api_key: null,
+ vi.spyOn(V1ConversationService, "createConversation").mockResolvedValue({
+ id: "task-id",
+ created_by_user_id: null,
+ status: "READY",
+ detail: null,
+ app_conversation_id: "test-conversation-id",
+ sandbox_id: null,
+ agent_server_url: "http://agent-server.local",
+ request: {
+ sandbox_id: null,
+ initial_message: null,
+ processors: [],
+ llm_model: null,
+ selected_repository: "repo1",
+ selected_branch: "main",
+ git_provider: "github",
+ suggested_task: null,
+ title: null,
+ trigger: null,
+ pr_number: [],
+ parent_conversation_id: null,
+ agent_type: "default",
+ },
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
});
renderTaskCard();
diff --git a/frontend/__tests__/hooks/mutation/use-create-conversation-race-condition.test.tsx b/frontend/__tests__/hooks/mutation/use-create-conversation-race-condition.test.tsx
new file mode 100644
index 0000000000..26a42290ae
--- /dev/null
+++ b/frontend/__tests__/hooks/mutation/use-create-conversation-race-condition.test.tsx
@@ -0,0 +1,228 @@
+import { renderHook, waitFor } from "@testing-library/react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { describe, expect, it, vi, beforeEach } from "vitest";
+import ConversationService from "#/api/conversation-service/conversation-service.api";
+import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";
+import { useCreateConversation } from "#/hooks/mutation/use-create-conversation";
+
+// ---------------------------------------------------------------
+// These tests document a race condition where clicking
+// "New Conversation" before settings have loaded causes
+// the hook to create a V0 (legacy) conversation instead of V1.
+//
+// Root cause (original code):
+// const { data: settings } = useSettings();
+// ...
+// const useV1 = !!settings?.v1_enabled && !createMicroagent;
+//
+// When settings haven't loaded yet, `settings` is `undefined`,
+// so `!!undefined?.v1_enabled` β†’ false, silently routing through
+// the V0 code path even though the backend defaults v1_enabled
+// to `true`.
+//
+// The fix uses `queryClient.ensureQueryData()` inside the mutation
+// to wait for settings before deciding V0 vs V1, with a fallback
+// to DEFAULT_SETTINGS (v1_enabled: true) on fetch failure.
+// ---------------------------------------------------------------
+
+const mockGetSettingsQueryFn = vi.fn();
+
+vi.mock("#/hooks/query/use-settings", async () => {
+ const actual = await vi.importActual<
+ typeof import("#/hooks/query/use-settings")
+ >("#/hooks/query/use-settings");
+ return {
+ ...actual,
+ getSettingsQueryFn: (...args: unknown[]) =>
+ mockGetSettingsQueryFn(...args),
+ };
+});
+
+vi.mock("#/hooks/use-tracking", () => ({
+ useTracking: () => ({
+ trackConversationCreated: vi.fn(),
+ }),
+}));
+
+vi.mock("#/context/use-selected-organization", () => ({
+ useSelectedOrganizationId: () => ({ organizationId: null }),
+}));
+
+// Shared mock return values
+const V1_RESPONSE = {
+ id: "task-id-123",
+ created_by_user_id: null,
+ status: "READY" as const,
+ detail: null,
+ app_conversation_id: null,
+ sandbox_id: null,
+ agent_server_url: "http://agent-server.local",
+ request: {
+ sandbox_id: null,
+ initial_message: { role: "user" as const, content: [{ type: "text" as const, text: "hello" }] },
+ processors: [],
+ llm_model: null,
+ selected_repository: null,
+ selected_branch: null,
+ git_provider: "github" as const,
+ suggested_task: null,
+ title: null,
+ trigger: null,
+ pr_number: [],
+ parent_conversation_id: null,
+ agent_type: "default" as const,
+ },
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+};
+
+const V0_RESPONSE = {
+ conversation_id: "conv-legacy",
+ session_api_key: null,
+ url: null,
+ title: "",
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ last_updated_at: new Date().toISOString(),
+ status: "RUNNING" as const,
+ runtime_status: null,
+ selected_repository: null,
+ selected_branch: null,
+ git_provider: null,
+};
+
+describe("useCreateConversation – V0 race condition", () => {
+ let v1Spy: ReturnType<typeof vi.spyOn>;
+ let v0Spy: ReturnType<typeof vi.spyOn>;
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+
+ v1Spy = vi
+ .spyOn(V1ConversationService, "createConversation")
+ .mockResolvedValue(V1_RESPONSE);
+
+ v0Spy = vi
+ .spyOn(ConversationService, "createConversation")
+ .mockResolvedValue(V0_RESPONSE);
+ });
+
+ /**
+ * BUG REPRODUCTION: When the settings API hasn't been called yet
+ * (no cached data), the hook should wait for settings to load
+ * rather than defaulting to V0.
+ *
+ * The fix uses `ensureQueryData` to fetch/wait for settings before
+ * deciding V0 vs V1. The mock here resolves with v1_enabled: true,
+ * proving that the mutation waits for the settings query.
+ */
+ it("should use V1 API even when settings are not yet cached (race condition scenario)", async () => {
+ // Simulate the race condition: settings haven't been fetched yet.
+ // With the fix, ensureQueryData will call getSettingsQueryFn to fetch them.
+ mockGetSettingsQueryFn.mockResolvedValue({ v1_enabled: true });
+
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={queryClient}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ await waitFor(() => {
+ // V1 should be used β€” the fix waits for settings before deciding
+ expect(v1Spy).toHaveBeenCalled();
+ });
+
+ // V0 should NOT have been called
+ expect(v0Spy).not.toHaveBeenCalled();
+ });
+
+ /**
+ * When the settings fetch fails (e.g. 404 for a new user), the hook
+ * falls back to DEFAULT_SETTINGS where v1_enabled is now `true`,
+ * still routing through V1.
+ */
+ it("should use V1 API when settings fetch fails (falls back to defaults)", async () => {
+ // Simulate settings API failure
+ mockGetSettingsQueryFn.mockRejectedValue(new Error("404 Not Found"));
+
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={queryClient}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ await waitFor(() => {
+ // DEFAULT_SETTINGS.v1_enabled is now true, so V1 should be used
+ expect(v1Spy).toHaveBeenCalled();
+ });
+ expect(v0Spy).not.toHaveBeenCalled();
+ });
+
+ /**
+ * When settings explicitly have v1_enabled: true, V1 API is used.
+ */
+ it("should use V1 API when settings explicitly have v1_enabled: true", async () => {
+ mockGetSettingsQueryFn.mockResolvedValue({ v1_enabled: true });
+
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={queryClient}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ await waitFor(() => {
+ expect(v1Spy).toHaveBeenCalled();
+ });
+ expect(v0Spy).not.toHaveBeenCalled();
+ });
+
+ /**
+ * When v1_enabled is explicitly false, V0 should be used.
+ */
+ it("should use V0 API when v1_enabled is explicitly false", async () => {
+ mockGetSettingsQueryFn.mockResolvedValue({ v1_enabled: false });
+
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={queryClient}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ await waitFor(() => {
+ expect(v0Spy).toHaveBeenCalled();
+ });
+ expect(v1Spy).not.toHaveBeenCalled();
+ });
+});
diff --git a/frontend/__tests__/hooks/mutation/use-create-conversation.test.tsx b/frontend/__tests__/hooks/mutation/use-create-conversation.test.tsx
index 6f56ce7f9d..bbed1f87dd 100644
--- a/frontend/__tests__/hooks/mutation/use-create-conversation.test.tsx
+++ b/frontend/__tests__/hooks/mutation/use-create-conversation.test.tsx
@@ -11,11 +11,8 @@ vi.mock("#/hooks/query/use-settings", async () => {
);
return {
...actual,
- useSettings: vi.fn().mockReturnValue({
- data: {
- v1_enabled: true,
- },
- isLoading: false,
+ getSettingsQueryFn: vi.fn().mockResolvedValue({
+ v1_enabled: true,
}),
};
});
@@ -26,6 +23,10 @@ vi.mock("#/hooks/use-tracking", () => ({
}),
}));
+vi.mock("#/context/use-selected-organization", () => ({
+ useSelectedOrganizationId: () => ({ organizationId: null }),
+}));
+
describe("useCreateConversation", () => {
it("passes suggested tasks to the V1 create conversation API", async () => {
const createConversationSpy = vi
diff --git a/frontend/__tests__/routes/llm-settings.test.tsx b/frontend/__tests__/routes/llm-settings.test.tsx
index b83f121192..1d3c08aa91 100644
--- a/frontend/__tests__/routes/llm-settings.test.tsx
+++ b/frontend/__tests__/routes/llm-settings.test.tsx
@@ -285,11 +285,15 @@ describe("Content", () => {
});
it("should render the advanced form if the switch is toggled", async () => {
- // Use OSS mode so agent-input is visible
+ // Use OSS mode and V0 (v1_enabled: false) so agent-input is visible
mockUseConfig.mockReturnValue({
data: { app_mode: "oss" },
isLoading: false,
});
+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue({
+ ...MOCK_DEFAULT_USER_SETTINGS,
+ v1_enabled: false,
+ });
renderLlmSettingsScreen();
await screen.findByTestId("llm-settings-screen");
@@ -325,11 +329,15 @@ describe("Content", () => {
});
it("should render the default advanced settings", async () => {
- // Use OSS mode so agent-input is visible
+ // Use OSS mode and V0 (v1_enabled: false) so agent-input is visible
mockUseConfig.mockReturnValue({
data: { app_mode: "oss" },
isLoading: false,
});
+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue({
+ ...MOCK_DEFAULT_USER_SETTINGS,
+ v1_enabled: false,
+ });
renderLlmSettingsScreen();
await screen.findByTestId("llm-settings-screen");
@@ -370,7 +378,7 @@ describe("Content", () => {
});
it("should render existing advanced settings correctly", async () => {
- // Use OSS mode so agent-input is visible
+ // Use OSS mode and V0 (v1_enabled: false) so agent-input is visible
mockUseConfig.mockReturnValue({
data: { app_mode: "oss" },
isLoading: false,
@@ -386,6 +394,7 @@ describe("Content", () => {
confirmation_mode: true,
enable_default_condenser: false,
security_analyzer: "none",
+ v1_enabled: false,
});
renderLlmSettingsScreen();
@@ -738,11 +747,15 @@ describe("Form submission", () => {
});
it("should submit the advanced form with the correct values", async () => {
- // Use OSS mode so agent-input is visible
+ // Use OSS mode and V0 (v1_enabled: false) so agent-input is visible
mockUseConfig.mockReturnValue({
data: { app_mode: "oss" },
isLoading: false,
});
+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue({
+ ...MOCK_DEFAULT_USER_SETTINGS,
+ v1_enabled: false,
+ });
const saveSettingsSpy = vi.spyOn(SettingsService, "saveSettings");
@@ -852,7 +865,7 @@ describe("Form submission", () => {
});
it("should disable the button if there are no changes in the advanced form", async () => {
- // Use OSS mode so agent-input is visible
+ // Use OSS mode and V0 (v1_enabled: false) so agent-input is visible
mockUseConfig.mockReturnValue({
data: { app_mode: "oss" },
isLoading: false,
@@ -865,6 +878,7 @@ describe("Form submission", () => {
llm_base_url: "https://api.openai.com/v1/chat/completions",
llm_api_key_set: true,
confirmation_mode: true,
+ v1_enabled: false,
});
renderLlmSettingsScreen();
diff --git a/frontend/src/hooks/mutation/use-create-conversation.ts b/frontend/src/hooks/mutation/use-create-conversation.ts
index f0ceab359a..a8a4126fe7 100644
--- a/frontend/src/hooks/mutation/use-create-conversation.ts
+++ b/frontend/src/hooks/mutation/use-create-conversation.ts
@@ -3,10 +3,12 @@ import ConversationService from "#/api/conversation-service/conversation-service
import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";
import { PluginSpec } from "#/api/conversation-service/v1-conversation-service.types";
import { SuggestedTask } from "#/utils/types";
-import { Provider } from "#/types/settings";
+import { Provider, Settings } from "#/types/settings";
import { CreateMicroagent, Conversation } from "#/api/open-hands.types";
import { useTracking } from "#/hooks/use-tracking";
-import { useSettings } from "#/hooks/query/use-settings";
+import { getSettingsQueryFn } from "#/hooks/query/use-settings";
+import { DEFAULT_SETTINGS } from "#/services/settings";
+import { useSelectedOrganizationId } from "#/context/use-selected-organization";
interface CreateConversationVariables {
query?: string;
@@ -36,7 +38,7 @@ interface CreateConversationResponse extends Partial<Conversation> {
export const useCreateConversation = () => {
const queryClient = useQueryClient();
const { trackConversationCreated } = useTracking();
- const { data: settings } = useSettings();
+ const { organizationId } = useSelectedOrganizationId();
return useMutation({
mutationKey: ["create-conversation"],
@@ -54,7 +56,20 @@ export const useCreateConversation = () => {
plugins,
} = variables;
- const useV1 = !!settings?.v1_enabled && !createMicroagent;
+ // Wait for settings to be loaded before deciding V0 vs V1
+ let settings: Settings;
+ try {
+ settings = await queryClient.ensureQueryData<Settings>({
+ queryKey: ["settings", organizationId],
+ queryFn: getSettingsQueryFn,
+ staleTime: 1000 * 60 * 5,
+ });
+ } catch {
+ // Settings fetch failed (e.g., 404 for new user) β€” use defaults
+ settings = DEFAULT_SETTINGS;
+ }
+
+ const useV1 = settings.v1_enabled && !createMicroagent;
if (useV1) {
// Use V1 API - creates a conversation start task
diff --git a/frontend/src/hooks/query/use-settings.ts b/frontend/src/hooks/query/use-settings.ts
index 5a00df92ac..686c37406b 100644
--- a/frontend/src/hooks/query/use-settings.ts
+++ b/frontend/src/hooks/query/use-settings.ts
@@ -7,7 +7,7 @@ import { useIsAuthed } from "./use-is-authed";
import { useSelectedOrganizationId } from "#/context/use-selected-organization";
import { useConfig } from "./use-config";
-const getSettingsQueryFn = async (): Promise<Settings> => {
+export const getSettingsQueryFn = async (): Promise<Settings> => {
const settings = await SettingsService.getSettings();
return {
diff --git a/frontend/src/services/settings.ts b/frontend/src/services/settings.ts
index 2efa97ac55..1d2dbf3294 100644
--- a/frontend/src/services/settings.ts
+++ b/frontend/src/services/settings.ts
@@ -33,7 +33,7 @@ export const DEFAULT_SETTINGS: Settings = {
},
git_user_name: "openhands",
git_user_email: "[email protected]",
- v1_enabled: false,
+ v1_enabled: true,
sandbox_grouping_strategy: "NO_GROUPING",
};