Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(chat): let a Cloud member pick the LLM profile on the home page (OHE-3669) (#18729)

Hiep Lee9b78030a761
diff --git a/__tests__/api/agent-server-conversation-service.test.ts b/__tests__/api/agent-server-conversation-service.test.ts
index 714c4b4cd4..90309ac0fe 100644
--- a/__tests__/api/agent-server-conversation-service.test.ts
+++ b/__tests__/api/agent-server-conversation-service.test.ts
@@ -1465,6 +1465,26 @@ describe("AgentServerConversationService", () => {
});
});
+ it("sends a picked LLM profile as llm_profile on the cloud start request", async () => {
+ const requests = captureRequests(["post"], {
+ id: "task-1",
+ status: "WORKING",
+ app_conversation_id: null,
+ agent_server_url: null,
+ request: {},
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ });
+
+ await AgentServerConversationService.createConversation({
+ metadata: null,
+ llmProfile: "ops55",
+ });
+
+ expect(requests).toHaveLength(1);
+ expect(requests[0].body).toMatchObject({ llm_profile: "ops55" });
+ });
+
it("forwards automation client tools and setup tag to cloud OpenHands conversations", async () => {
const requests = captureRequests(["post"], {
id: "task-automation",
diff --git a/__tests__/components/features/home/home-chat-launcher.test.tsx b/__tests__/components/features/home/home-chat-launcher.test.tsx
index eea877c775..7a7c707f48 100644
--- a/__tests__/components/features/home/home-chat-launcher.test.tsx
+++ b/__tests__/components/features/home/home-chat-launcher.test.tsx
@@ -1,4 +1,4 @@
-import { render, screen, waitFor } from "@testing-library/react";
+import { act, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
@@ -8,6 +8,8 @@ import { HomeChatLauncher } from "#/components/features/home/home-chat-launcher"
import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";
import AutomationService from "#/api/automation-service/automation-service.api";
import WorkspacesService from "#/api/workspaces-service/workspaces-service.api";
+import ProfilesService from "#/api/profiles-service/profiles-service.api";
+import { useModelStore } from "#/stores/model-store";
import {
LAST_LOCAL_WORKSPACE_MODE_STORAGE_KEY,
writeStoredLocalWorkspaceMode,
@@ -386,6 +388,7 @@ describe("HomeChatLauncher", () => {
afterEach(() => {
toast.remove();
window.localStorage.removeItem(LAST_LOCAL_WORKSPACE_MODE_STORAGE_KEY);
+ useModelStore.setState({ homeLlmProfile: null });
});
it("defaults to Code mode and switches to Automate mode", async () => {
@@ -688,6 +691,47 @@ describe("HomeChatLauncher", () => {
);
});
+ it.each([
+ {
+ description: "forwards a member's home LLM pick",
+ pick: "ops55",
+ expected: "ops55",
+ },
+ {
+ description: "drops a home LLM pick whose profile is gone",
+ pick: "Deleted",
+ expected: undefined,
+ },
+ ])("$description on a cloud launch", async ({ pick, expected }) => {
+ mockUseActiveBackend.mockReturnValue(cloudBackend);
+ const listProfilesSpy = vi
+ .spyOn(ProfilesService, "listProfiles")
+ .mockResolvedValue({
+ profiles: [
+ {
+ name: "ops55",
+ model: "anthropic/claude-opus-5-5",
+ base_url: null,
+ api_key_set: true,
+ },
+ ],
+ active_profile: null,
+ });
+ useModelStore.setState({ homeLlmProfile: pick });
+ const createSpy = vi
+ .spyOn(AgentServerConversationService, "createConversation")
+ .mockResolvedValue(makeConversationResponse());
+ renderLauncher();
+ await waitFor(() => expect(listProfilesSpy).toHaveBeenCalled());
+ // Let the resolved profile list reach the launcher before submitting.
+ await act(() => new Promise((resolve) => setTimeout(resolve, 0)));
+
+ await userEvent.click(screen.getByTestId("stub-chat-submit"));
+
+ await waitFor(() => expect(createSpy).toHaveBeenCalledTimes(1));
+ expect(createSpy.mock.lastCall?.[0]?.llmProfile).toBe(expected);
+ });
+
it("does not pass query to createConversation when attachments are present", async () => {
mockImages = [new File(["x"], "shot.png", { type: "image/png" })];
const createSpy = vi
diff --git a/__tests__/hooks/use-chat-input-llm-profile-state.test.tsx b/__tests__/hooks/use-chat-input-llm-profile-state.test.tsx
index 9d1a5f3549..5ec6e461b8 100644
--- a/__tests__/hooks/use-chat-input-llm-profile-state.test.tsx
+++ b/__tests__/hooks/use-chat-input-llm-profile-state.test.tsx
@@ -6,9 +6,15 @@ const useOptionalConversationIdMock = vi.fn();
const useActiveConversationMock = vi.fn();
const useLlmProfilesMock = vi.fn();
const switchAndLog = vi.fn();
+const setHomeLlmProfile = vi.fn();
-let modelStoreState: { activeProfileByConversation: Record<string, string> } = {
+let modelStoreState: {
+ activeProfileByConversation: Record<string, string>;
+ homeLlmProfile?: string | null;
+ setHomeLlmProfile?: typeof setHomeLlmProfile;
+} = {
activeProfileByConversation: {},
+ setHomeLlmProfile,
};
vi.mock("#/hooks/use-conversation-id", () => ({
@@ -73,7 +79,8 @@ const PROFILES = [
describe("useChatInputLlmProfileState", () => {
beforeEach(() => {
switchAndLog.mockReset();
- modelStoreState = { activeProfileByConversation: {} };
+ setHomeLlmProfile.mockReset();
+ modelStoreState = { activeProfileByConversation: {}, setHomeLlmProfile };
useOptionalConversationIdMock.mockReturnValue({ conversationId: "c1" });
useActiveConversationMock.mockReturnValue({ data: undefined });
useLlmProfilesMock.mockReturnValue({
@@ -207,19 +214,49 @@ describe("useChatInputLlmProfileState", () => {
expect(switchAndLog).toHaveBeenCalledWith(null, "Smart");
});
- it("keeps the home picker read-only for a member who cannot manage org profiles", () => {
- // A home pick hits the org-gated activate endpoint, which a cloud member
- // could only 403 on.
+ it("holds a member's home pick for the next launch instead of activating it", () => {
+ // A home activate hits the org-gated endpoint, which a cloud member could
+ // only 403 on; the pick is sent with the next home launch instead.
useOptionalConversationIdMock.mockReturnValue({ conversationId: null });
useCanManageOrgProfilesMock.mockReturnValue(false);
const { result } = renderState();
result.current.selectProfile("Smart");
- expect(result.current.canSwitchProfile).toBe(false);
+ expect(result.current.canSwitchProfile).toBe(true);
+ expect(setHomeLlmProfile).toHaveBeenCalledWith("Smart");
expect(switchAndLog).not.toHaveBeenCalled();
});
+ it.each([
+ {
+ description: "names a member's home pick on the home page",
+ conversationId: null,
+ pick: "Smart",
+ expected: "Smart",
+ },
+ {
+ description: "names a member's home pick while its start task runs",
+ conversationId: "task-abc",
+ pick: "Smart",
+ expected: "Smart",
+ },
+ {
+ description:
+ "falls back to the active profile when the picked one is gone",
+ conversationId: null,
+ pick: "Deleted",
+ expected: "Fast",
+ },
+ ])("$description", ({ conversationId, pick, expected }) => {
+ useOptionalConversationIdMock.mockReturnValue({ conversationId });
+ modelStoreState = { ...modelStoreState, homeLlmProfile: pick };
+
+ const { result } = renderState();
+
+ expect(result.current.currentProfileName).toBe(expected);
+ });
+
it("keeps the picker read-only while a cloud start task is provisioning", () => {
// `task-…` is not a real conversation id yet, so /switch_profile would 404.
useOptionalConversationIdMock.mockReturnValue({
diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.ts
index 32b73bb42b..1237717681 100644
--- a/src/api/conversation-service/agent-server-conversation-service.api.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts
@@ -471,6 +471,8 @@ export interface CreateConversationOptions {
agentLlmProfileRef?: string | null;
/** Local only: run the agent profile with this LLM profile instead of its own. */
agentLlmProfileOverride?: string;
+ /** Cloud only: run this conversation on the named LLM profile (`llm_profile`). */
+ llmProfile?: string;
}
class AgentServerConversationService {
@@ -532,6 +534,7 @@ class AgentServerConversationService {
agentLlmProfileOverride,
profileHasRouter,
acpServer,
+ llmProfile,
} = options;
if (getActiveBackend().backend.kind === "cloud") {
@@ -565,6 +568,7 @@ class AgentServerConversationService {
agent_type: agentType,
sandbox_id: sandboxId ?? null,
agent_profile_id: agentProfileId ?? null,
+ ...(llmProfile ? { llm_profile: llmProfile } : {}),
...(routerAtStartSuffix
? {
agent_launch_additions: {
diff --git a/src/api/conversation-service/agent-server-conversation-service.types.ts b/src/api/conversation-service/agent-server-conversation-service.types.ts
index a555cfb5e7..89ff401bf9 100644
--- a/src/api/conversation-service/agent-server-conversation-service.types.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.types.ts
@@ -73,6 +73,8 @@ export interface AppConversationStartRequest {
initial_message?: SendMessageRequest | null;
processors?: unknown[]; // EventCallbackProcessor - keeping as unknown for now
llm_model?: string | null;
+ // One-off launch on a saved LLM profile (by name), without activating it.
+ llm_profile?: string | null;
selected_repository?: string | null;
selected_branch?: string | null;
git_provider?: Provider | null;
diff --git a/src/components/features/chat/components/chat-input-llm-profile-picker.tsx b/src/components/features/chat/components/chat-input-llm-profile-picker.tsx
index a8b1d10b9c..d1e209334b 100644
--- a/src/components/features/chat/components/chat-input-llm-profile-picker.tsx
+++ b/src/components/features/chat/components/chat-input-llm-profile-picker.tsx
@@ -56,9 +56,9 @@ export function ChatInputLlmProfileMenuContent({
canSwitchProfile,
selectProfile,
} = useChatInputLlmProfileState();
- // Read-only surfaces (a cloud member on the home page, or a start-task route)
- // still name the active profile β€” the same shape ChatInputModelMenuContent
- // uses when the ACP picker is gated off.
+ // A read-only surface (a cloud start-task route) still names the active
+ // profile β€” the same shape ChatInputModelMenuContent uses when the ACP
+ // picker is gated off.
const showProfileList = canSwitchProfile && profiles.length > 0;
const readOnlyProfileName = canSwitchProfile ? null : currentProfileName;
// Locked-to-Cloud blocks the Canvas LLM page this links to (OHE-3457).
diff --git a/src/components/features/home/home-chat-launcher.tsx b/src/components/features/home/home-chat-launcher.tsx
index ee363bd9af..40444fa58e 100644
--- a/src/components/features/home/home-chat-launcher.tsx
+++ b/src/components/features/home/home-chat-launcher.tsx
@@ -6,11 +6,13 @@ import { CustomChatInput } from "#/components/features/chat/custom-chat-input";
import { useActiveBackend } from "#/contexts/active-backend-context";
import { useCreateConversation } from "#/hooks/mutation/use-create-conversation";
import { useLocalWorkspaces } from "#/hooks/query/use-local-workspaces";
+import { useLlmProfiles } from "#/hooks/query/use-llm-profiles";
import { useModelInterceptor } from "#/hooks/chat/use-model-interceptor";
import { useLlmConfigured } from "#/hooks/use-llm-configured";
import { HOME_PROMPT_DRAFT_KEY } from "#/hooks/chat/use-draft-persistence";
import { useChatAttachmentUpload } from "#/hooks/chat/use-chat-attachment-upload";
import { useConversationStore } from "#/stores/conversation-store";
+import { useModelStore } from "#/stores/model-store";
import type { WorkspaceMode } from "#/api/conversation-metadata-store";
import { setPendingTaskAttachments } from "#/stores/pending-task-attachments-store";
import { enqueueHomeTaskPendingMessage } from "#/utils/enqueue-home-task-pending-message";
@@ -104,6 +106,8 @@ export function HomeChatLauncher() {
restoreMessageToInputIfEmpty,
} = useConversationStore();
const { handleUpload } = useChatAttachmentUpload();
+ const homeLlmProfile = useModelStore((s) => s.homeLlmProfile);
+ const { data: llmProfiles } = useLlmProfiles();
const { error: workspacesError } = useLocalWorkspaces({ enabled: isLocal });
const { isolated, unsupportedMessage: runtimeWorkspaceMessage } =
useConversationWorkspace();
@@ -175,6 +179,15 @@ export function HomeChatLauncher() {
variables = { ...variables, plugins: selectedPlugins };
}
+ // A cloud member's home LLM pick (see useChatInputLlmProfileState), unless
+ // that profile has since gone.
+ if (
+ homeLlmProfile &&
+ llmProfiles?.profiles.some((p) => p.name === homeLlmProfile)
+ ) {
+ variables = { ...variables, llmProfile: homeLlmProfile };
+ }
+
const openAutomationSetupMode = (conversationId: string) => {
if (!isAutomateMode) return;
markAutomationSetupHandoff(conversationId);
diff --git a/src/hooks/mutation/use-create-conversation.ts b/src/hooks/mutation/use-create-conversation.ts
index 8f0488d38e..2c32fcf940 100644
--- a/src/hooks/mutation/use-create-conversation.ts
+++ b/src/hooks/mutation/use-create-conversation.ts
@@ -40,6 +40,8 @@ export interface CreateConversationVariables {
// active AgentProfile (if any) is used so home-composed conversations
// launch from the user's selected profile (#3727).
agentProfileId?: string;
+ // Cloud: run on this LLM profile (a member's home pick) without activating it.
+ llmProfile?: string;
entryPoint?: string; // analytics only; not forwarded to the service
}
@@ -101,6 +103,7 @@ export const useCreateConversation = ({
parentConversationId,
agentType,
agentProfileId,
+ llmProfile,
} = variables;
// The active AgentProfile is the default launch profile for new
@@ -131,6 +134,7 @@ export const useCreateConversation = ({
workspaceMode,
parentConversationId,
agentType,
+ ...(llmProfile ? { llmProfile } : {}),
// Cloud only; a local launch reads the toggle itself and gates it
// on the launched profile's router. Only stamped when on, so the
// e2e snapshot tests that assert the exact createConversation
diff --git a/src/hooks/use-chat-input-llm-profile-state.ts b/src/hooks/use-chat-input-llm-profile-state.ts
index a74300271a..861419a614 100644
--- a/src/hooks/use-chat-input-llm-profile-state.ts
+++ b/src/hooks/use-chat-input-llm-profile-state.ts
@@ -26,14 +26,15 @@ export interface ChatInputLlmProfileState {
isSwitching: boolean;
/**
* Whether picking a profile here would actually land. False on a cloud
- * start-task route and for a cloud member on the home page; the surfaces
- * still name the active profile, they just drop the selectable rows.
+ * start-task route; the surfaces still name the active profile, they just
+ * drop the selectable rows.
*/
canSwitchProfile: boolean;
/**
* Switch the LLM profile: live via `/switch_profile` inside a conversation.
* On the home page it becomes the active agent profile's LLM, which for
- * `default` means activating it (see {@link useSwitchLlmProfile}).
+ * `default` means activating it (see {@link useSwitchLlmProfile}). A cloud
+ * member's home pick is held for the next home launch instead.
*/
selectProfile: (profileName: string) => void;
}
@@ -67,17 +68,31 @@ export function useChatInputLlmProfileState(): ChatInputLlmProfileState {
const optimisticActiveProfile = useModelStore((s) =>
conversationId ? s.activeProfileByConversation[conversationId] : undefined,
);
+ const homeLlmProfile = useModelStore((s) => s.homeLlmProfile);
+ const setHomeLlmProfile = useModelStore((s) => s.setHomeLlmProfile);
const profiles = data?.profiles ?? [];
const conversationModel = conversation?.llm_model ?? null;
+ // A cloud `task-…` route has no real conversation id yet, so the
+ // per-conversation /switch_profile would 404.
+ const isTaskRoute = conversationId?.startsWith("task-") ?? false;
+ // A cloud member's home pick names the profile the home launch (and its
+ // start-task route) runs, until that profile is gone.
+ const homePick =
+ (!conversationId || isTaskRoute) &&
+ homeLlmProfile &&
+ profiles.some((p) => p.name === homeLlmProfile)
+ ? homeLlmProfile
+ : null;
// Resolution priority (mirrors the former SwitchProfileButton):
// 1. Optimistic (just-clicked) β€” instant feedback before the refetch.
// 2. Profile stamped on the conversation, validated against the live list
// so a since-deleted/renamed profile falls through.
// 3. Profile whose model matches the running llm_model.
- // 4. Before the first message, the active agent profile's own LLM, which
- // the launch runs, else the user-level active_profile.
+ // 4. Before the first message, a cloud member's home pick, else the
+ // active agent profile's own LLM, which the launch runs, else the
+ // user-level active_profile.
const stampedProfile = conversation?.active_profile ?? null;
const conversationProfile =
stampedProfile && profiles.some((p) => p.name === stampedProfile)
@@ -104,20 +119,15 @@ export function useChatInputLlmProfileState(): ChatInputLlmProfileState {
conversationProfile ??
(conversationModel
? (profiles.find((p) => p.model === conversationModel)?.name ?? null)
- : (agentLlmProfile ?? data?.active_profile ?? null));
+ : (homePick ?? agentLlmProfile ?? data?.active_profile ?? null));
const currentProfileModel =
profiles.find((p) => p.name === currentProfileName)?.model ??
conversationModel ??
null;
- // A home pick activates the profile account-wide β€” on cloud that's the
- // org-gated activate endpoint a member can only 403 on. A cloud `task-…`
- // route has no real conversation id yet, so the per-conversation
- // /switch_profile would 404. Either way the pill still names the active
- // profile; only the selectable rows drop out.
- const isTaskRoute = conversationId?.startsWith("task-") ?? false;
- const canSwitchProfile =
- !isTaskRoute && (!!conversationId || canManageOrgProfiles);
+ // On a start-task route the pill still names the active profile; only the
+ // selectable rows drop out.
+ const canSwitchProfile = !isTaskRoute;
const selectProfile = useCallback(
(profileName: string) => {
@@ -130,12 +140,25 @@ export function useChatInputLlmProfileState(): ChatInputLlmProfileState {
);
return;
}
+ if (!conversationId) {
+ // Otherwise a home pick activates the profile account-wide β€” on cloud
+ // that's the org-gated activate endpoint a member can only 403 on.
+ // Hold a member's pick for the next home launch (sent as
+ // `llm_profile`).
+ if (!canManageOrgProfiles) {
+ setHomeLlmProfile(profileName);
+ return;
+ }
+ setHomeLlmProfile(null);
+ }
switchAndLog(conversationId, profileName);
},
[
+ canManageOrgProfiles,
canSwitchProfile,
conversationId,
currentProfileName,
+ setHomeLlmProfile,
switchAndLog,
ownsHomeLlm,
activeAgentProfile,
diff --git a/src/stores/model-store.ts b/src/stores/model-store.ts
index c856a96e50..4a05ac6d7b 100644
--- a/src/stores/model-store.ts
+++ b/src/stores/model-store.ts
@@ -35,6 +35,11 @@ interface ModelState {
* server lands.
*/
activeProfileByConversation: Record<string, string>;
+ /**
+ * A cloud member's home-page pick, sent with the next home launch instead of
+ * activating the profile org-wide (which needs org-admin permission).
+ */
+ homeLlmProfile: string | null;
}
interface ModelActions {
@@ -63,6 +68,7 @@ interface ModelActions {
setActiveProfile: (conversationId: string, profileName: string) => void;
/** Drops only the optimistic active-profile entry for a conversation. */
clearActiveProfile: (conversationId: string) => void;
+ setHomeLlmProfile: (profileName: string | null) => void;
clear: (conversationId: string) => void;
clearAll: () => void;
}
@@ -88,6 +94,7 @@ export const useModelStore = create<ModelStore>()(
(set) => ({
entriesByConversation: {},
activeProfileByConversation: {},
+ homeLlmProfile: null,
show: (conversationId, anchorEventId, profiles) =>
set((s) =>
appendEntry(s, conversationId, {
@@ -147,6 +154,7 @@ export const useModelStore = create<ModelStore>()(
delete activeProfileByConversation[conversationId];
return { activeProfileByConversation };
}),
+ setHomeLlmProfile: (profileName) => set({ homeLlmProfile: profileName }),
clear: (conversationId) =>
set((s) => {
const entriesByConversation = { ...s.entriesByConversation };
@@ -158,7 +166,11 @@ export const useModelStore = create<ModelStore>()(
return { entriesByConversation, activeProfileByConversation };
}),
clearAll: () =>
- set({ entriesByConversation: {}, activeProfileByConversation: {} }),
+ set({
+ entriesByConversation: {},
+ activeProfileByConversation: {},
+ homeLlmProfile: null,
+ }),
}),
{ name: "ModelStore" },
),