Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: honor the home LLM dropdown selection over an agent profile's pinned LLM (#16671)

Hiep Lebe584ade934b
diff --git a/__tests__/hooks/mutation/use-create-conversation.test.tsx b/__tests__/hooks/mutation/use-create-conversation.test.tsx
index fd63adf2ac..4f0c13333a 100644
--- a/__tests__/hooks/mutation/use-create-conversation.test.tsx
+++ b/__tests__/hooks/mutation/use-create-conversation.test.tsx
@@ -98,6 +98,7 @@ describe("useCreateConversation", () => {
useLlmProfilesMock.mockReturnValue({ data: { active_profile: null } });
removeStoredConversationMetadata("conv-with-plugins");
removeStoredConversationMetadata("conv-ref-stamp");
+ removeStoredConversationMetadata("conv-dropdown-override");
});
it("passes suggested tasks to the V1 create conversation API", async () => {
@@ -510,9 +511,11 @@ describe("useCreateConversation", () => {
});
it("stamps the launched openhands profile's llm_profile_ref into conversation metadata (#1082)", async () => {
- // A named (non-default) profile launches via the profile path and runs its
- // own llm_profile_ref β€” which differs from the standalone active LLM
- // profile β€” so the switcher pill must name the ref, not the active profile.
+ // A named (non-default) profile launches via the profile path when no
+ // dropdown selection exists (active_profile null β€” a differing selection
+ // would win the launch instead, #16539) and runs its own llm_profile_ref,
+ // so the switcher pill must name the ref, not the hook's stale cached
+ // active profile.
useLlmProfilesMock.mockReturnValue({
data: { active_profile: "standalone-active" },
});
@@ -531,7 +534,7 @@ describe("useCreateConversation", () => {
});
listLlmProfilesMock.mockResolvedValue({
profiles: [{ name: "claude" }],
- active_profile: "standalone-active",
+ active_profile: null,
});
const createConversationSpy = vi
.spyOn(AgentServerConversationService, "createConversation")
@@ -559,4 +562,185 @@ describe("useCreateConversation", () => {
).toBe("claude"),
);
});
+
+ it("honors the home LLM dropdown selection over a named profile's pinned ref (#16539)", async () => {
+ // The home pill shows the account-wide active LLM profile, so when it
+ // differs from the active named profile's pinned llm_profile_ref the
+ // launch must run the selection: downgrade to the agent_settings path
+ // (which the dropdown activation syncs) and stamp the selected profile.
+ listAgentProfilesMock.mockResolvedValue({
+ profiles: [
+ {
+ id: "profile-luna",
+ name: "openhands-luna",
+ agent_kind: "openhands",
+ revision: 1,
+ llm_profile_ref: "pinned-model",
+ mcp_server_refs: null,
+ },
+ ],
+ active_agent_profile_id: "profile-luna",
+ });
+ listLlmProfilesMock.mockResolvedValue({
+ profiles: [{ name: "pinned-model" }, { name: "selected-model" }],
+ active_profile: "selected-model",
+ });
+ const createConversationSpy = vi
+ .spyOn(AgentServerConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ app_conversation_id: "conv-dropdown-override",
+ agent_server_url: "http://agent-server.local",
+ } as never);
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={new QueryClient()}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ const call = createConversationSpy.mock.lastCall;
+ expect(call?.[0]?.agentProfileId).toBeUndefined();
+ await waitFor(() =>
+ expect(
+ getStoredConversationMetadata("conv-dropdown-override")?.active_profile,
+ ).toBe("selected-model"),
+ );
+ });
+
+ it("keeps the named profile path when the dropdown selection matches its pinned ref (#16539)", async () => {
+ listAgentProfilesMock.mockResolvedValue({
+ profiles: [
+ {
+ id: "profile-luna",
+ name: "openhands-luna",
+ agent_kind: "openhands",
+ revision: 1,
+ llm_profile_ref: "pinned-model",
+ mcp_server_refs: null,
+ },
+ ],
+ active_agent_profile_id: "profile-luna",
+ });
+ listLlmProfilesMock.mockResolvedValue({
+ profiles: [{ name: "pinned-model" }],
+ active_profile: "pinned-model",
+ });
+ const createConversationSpy = vi
+ .spyOn(AgentServerConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ app_conversation_id: "conv-1",
+ agent_server_url: "http://agent-server.local",
+ } as never);
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={new QueryClient()}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ const call = createConversationSpy.mock.lastCall;
+ expect(call?.[0]?.agentProfileId).toBe("profile-luna");
+ });
+
+ it("keeps an explicitly-picked agent profile over the dropdown selection (#16539)", async () => {
+ // An explicit `agentProfileId` (the in-conversation profile picker) is a
+ // deliberate profile pick β€” its pinned ref stays authoritative even when
+ // the account-wide active LLM profile differs.
+ listAgentProfilesMock.mockResolvedValue({
+ profiles: [
+ {
+ id: "profile-luna",
+ name: "openhands-luna",
+ agent_kind: "openhands",
+ revision: 1,
+ llm_profile_ref: "pinned-model",
+ mcp_server_refs: null,
+ },
+ ],
+ active_agent_profile_id: null,
+ });
+ listLlmProfilesMock.mockResolvedValue({
+ profiles: [{ name: "pinned-model" }, { name: "selected-model" }],
+ active_profile: "selected-model",
+ });
+ const createConversationSpy = vi
+ .spyOn(AgentServerConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ app_conversation_id: "conv-1",
+ agent_server_url: "http://agent-server.local",
+ } as never);
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={new QueryClient()}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({
+ query: "hello",
+ agentProfileId: "profile-luna",
+ });
+
+ const call = createConversationSpy.mock.lastCall;
+ expect(call?.[0]?.agentProfileId).toBe("profile-luna");
+ });
+
+ it("keeps the named profile path on cloud regardless of the active LLM profile (#16539)", async () => {
+ // The dropdown override is local-only, like the other downgrades: cloud
+ // has no agent_settings payload to fall back to.
+ mockUseActiveBackend.mockReturnValue({
+ backend: { id: "cloud-1", kind: "cloud" },
+ orgId: null,
+ });
+ listAgentProfilesMock.mockResolvedValue({
+ profiles: [
+ {
+ id: "profile-luna",
+ name: "openhands-luna",
+ agent_kind: "openhands",
+ revision: 1,
+ llm_profile_ref: "pinned-model",
+ mcp_server_refs: null,
+ },
+ ],
+ active_agent_profile_id: "profile-luna",
+ });
+ listLlmProfilesMock.mockResolvedValue({
+ profiles: [{ name: "pinned-model" }, { name: "selected-model" }],
+ active_profile: "selected-model",
+ });
+ const createConversationSpy = vi
+ .spyOn(AgentServerConversationService, "createConversation")
+ .mockResolvedValue({
+ id: "task-id",
+ app_conversation_id: "conv-1",
+ agent_server_url: "http://agent-server.local",
+ } as never);
+
+ const { result } = renderHook(() => useCreateConversation(), {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={new QueryClient()}>
+ {children}
+ </QueryClientProvider>
+ ),
+ });
+
+ await result.current.mutateAsync({ query: "hello" });
+
+ const call = createConversationSpy.mock.lastCall;
+ expect(call?.[0]?.agentProfileId).toBe("profile-luna");
+ });
});
diff --git a/src/hooks/mutation/use-create-conversation.ts b/src/hooks/mutation/use-create-conversation.ts
index 1cda1aee24..71d38be357 100644
--- a/src/hooks/mutation/use-create-conversation.ts
+++ b/src/hooks/mutation/use-create-conversation.ts
@@ -130,6 +130,10 @@ export const useCreateConversation = () => {
// (#1571 review).
const isCloud = backend.kind === "cloud";
let effectiveAgentProfileId = requestedAgentProfileId;
+ // The account-wide active LLM profile from the launch-path fetch below
+ // (null when that fetch didn't run or failed). Fresher than the
+ // `useLlmProfiles()` render snapshot, which a fast send can outrun.
+ let fetchedActiveLlmProfile: string | null = null;
if (
!isCloud &&
resolvedAgentProfile?.name === WELL_KNOWN_DEFAULT_AGENT_PROFILE_NAME &&
@@ -174,6 +178,7 @@ export const useCreateConversation = () => {
llmProfileExists = llm.profiles.some(
(profile) => profile.name === resolvedAgentProfile.llm_profile_ref,
);
+ fetchedActiveLlmProfile = llm.active_profile ?? null;
} catch {
// List unavailable β†’ can't validate β†’ fall back to agent_settings.
}
@@ -185,6 +190,27 @@ export const useCreateConversation = () => {
"launching from agent_settings instead.",
);
effectiveAgentProfileId = undefined;
+ } else if (
+ !isCloud &&
+ !agentProfileId &&
+ fetchedActiveLlmProfile &&
+ fetchedActiveLlmProfile !== resolvedAgentProfile.llm_profile_ref
+ ) {
+ // The home LLM pill shows β€” and its dropdown activates β€” the
+ // account-wide active LLM profile, never the pinned ref
+ // (useChatInputLlmProfileState), so when the two differ the launch
+ // must run the selection or the UI advertises a model the
+ // conversation won't use (#16539). Launch via agent_settings, which
+ // the dropdown's profile activation syncs to the selection. Scoped
+ // to the implicit active-profile launch: an explicit `agentProfileId`
+ // (the in-conversation profile picker) is a deliberate profile pick,
+ // so its pinned ref stays authoritative. Local-only like the
+ // downgrades above β€” cloud has no agent_settings payload to fall
+ // back to. Trade-off: the named profile's non-LLM config doesn't
+ // apply to this launch; the start request has no per-launch LLM
+ // override that could preserve it (AgentLaunchAdditions carries only
+ // a system-message suffix).
+ effectiveAgentProfileId = undefined;
}
}
@@ -258,16 +284,17 @@ export const useCreateConversation = () => {
// A launch from a named OpenHands profile runs that profile's
// `llm_profile_ref`, which can differ from the standalone active LLM
// profile β€” stamp the ref so the switcher pill names the exact profile
- // the conversation runs (#1082). The agent_settings path (the `default`
- // baseline or a dangling ref, where effectiveAgentProfileId is cleared)
- // runs the active LLM, so it keeps `active_profile`. ACP profiles carry
- // no LLM profile, so they fall through to the active-profile stamp
- // (unused by the ACP model chip).
+ // the conversation runs (#1082). The agent_settings paths (the `default`
+ // baseline, a dangling ref, or a dropdown override (#16539) β€” where
+ // effectiveAgentProfileId is cleared) run the active LLM, so they stamp
+ // the active profile, preferring the launch-path fetch over the hook's
+ // render snapshot. ACP profiles carry no LLM profile, so they fall
+ // through to the active-profile stamp (unused by the ACP model chip).
const activeProfile =
effectiveAgentProfileId &&
resolvedAgentProfile?.agent_kind === "openhands"
? resolvedAgentProfile.llm_profile_ref
- : (llmProfiles?.active_profile ?? null);
+ : (fetchedActiveLlmProfile ?? llmProfiles?.active_profile ?? null);
if (localConversationId && (activeProfile || attachedPlugins.length)) {
const prev = getStoredConversationMetadata(localConversationId);
setStoredConversationMetadata(localConversationId, {