Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: do not silently persist ACP model picks to agent_settings when profile discovery fails (#16701)

Hiep Le28be38adac6a
diff --git a/__tests__/hooks/mutation/use-switch-acp-model.test.tsx b/__tests__/hooks/mutation/use-switch-acp-model.test.tsx
index 10c1a48352..a7fb3aa8f1 100644
--- a/__tests__/hooks/mutation/use-switch-acp-model.test.tsx
+++ b/__tests__/hooks/mutation/use-switch-acp-model.test.tsx
@@ -167,23 +167,23 @@ describe("useSwitchAcpModel", () => {
});
});
- it("falls back to the agent-settings default when the profiles surface is unavailable", async () => {
+ it("does not persist to agent_settings when the profiles fetch fails", async () => {
+ // Discovery failure propagates instead of downgrading (#16523): an
+ // active-profile launch ignores agent_settings, so persisting the pick
+ // there would silently drop it.
vi.mocked(AgentProfilesService.listProfiles).mockRejectedValue(
- new Error("404"),
+ new Error("profile endpoint unavailable"),
);
- vi.mocked(SettingsService.saveSettings).mockResolvedValue(true);
const { result } = renderSwitchHook();
result.current.mutate({ conversationId: null, model: "gemini-2.5-pro" });
await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
+ expect(result.current.isError).toBe(true);
});
- expect(SettingsService.saveSettings).toHaveBeenCalledWith({
- agent_settings_diff: { acp_model: "gemini-2.5-pro" },
- });
+ expect(SettingsService.saveSettings).not.toHaveBeenCalled();
expect(AgentProfilesService.saveProfile).not.toHaveBeenCalled();
});
diff --git a/src/hooks/mutation/use-switch-acp-model.ts b/src/hooks/mutation/use-switch-acp-model.ts
index 3c54adff5b..396c4e0eeb 100644
--- a/src/hooks/mutation/use-switch-acp-model.ts
+++ b/src/hooks/mutation/use-switch-acp-model.ts
@@ -36,9 +36,11 @@ interface SwitchAcpModelVars {
* launches resolve the agent server-side purely from the stored profile
* (``agent_profile_id`` and ``agent_settings`` are mutually exclusive launch
* sources), so writing ``agent_settings.acp_model`` would not affect them.
- * Only when no ACP profile is active (a legacy backend without the
- * /api/agent-profiles surface) does the write fall back to the
- * ``agent_settings_diff`` the legacy launch path reads.
+ * Only when the profile list resolves with no active ACP profile does the
+ * write fall back to the ``agent_settings_diff`` the legacy launch path
+ * reads. A failed profile discovery propagates instead of downgrading
+ * (#16523): an active-profile launch ignores agent_settings, so persisting
+ * the pick there would silently drop it.
*
* Invalidates the same conversation/settings query keys the profile hook does
* so the chat-input model chip + conversation chip refresh with the new model.
@@ -59,21 +61,21 @@ export const useSwitchAcpModel = () => {
// Home page: resolve the active profile from the shared query cache
// (same keys/retry policy as useCreateConversation's launch path, so a
- // pick can't disagree with what a subsequent send would launch).
- let agentProfiles: AgentProfileListResponse | undefined;
- try {
- agentProfiles = await queryClient.ensureQueryData({
+ // pick can't disagree with what a subsequent send would launch). Like
+ // that launch path, do not fall back to the legacy agent_settings
+ // persist when profile discovery fails (#16523): an active-profile
+ // launch ignores agent_settings, so the pick would be silently dropped.
+ // The rejection surfaces via the global mutation error toast.
+ const agentProfiles: AgentProfileListResponse =
+ await queryClient.ensureQueryData({
queryKey: [...AGENT_PROFILES_QUERY_KEYS.all, backend.id, orgId],
queryFn: AgentProfilesService.listProfiles,
...AGENT_PROFILES_RETRY_OPTIONS,
});
- } catch {
- // Profiles unavailable β†’ legacy agent_settings persist below.
- }
- const activeProfile = agentProfiles?.profiles?.find(
+ const activeProfile = agentProfiles.profiles?.find(
(profile) =>
profile.id != null &&
- profile.id === agentProfiles?.active_agent_profile_id,
+ profile.id === agentProfiles.active_agent_profile_id,
);
if (activeProfile?.agent_kind === "acp") {
@@ -98,10 +100,11 @@ export const useSwitchAcpModel = () => {
return;
}
- // Legacy/no-profile backends: persist as the agent-settings default. The
- // backend deep-merges ``agent_settings_diff`` into the existing
- // ``agent_settings`` dict, so a scalar ``acp_model`` diff updates only
- // the model and preserves the selected provider + command.
+ // No active ACP profile: persist as the agent-settings default the
+ // legacy launch path reads. The backend deep-merges
+ // ``agent_settings_diff`` into the existing ``agent_settings`` dict, so
+ // a scalar ``acp_model`` diff updates only the model and preserves the
+ // selected provider + command.
await SettingsService.saveSettings({
agent_settings_diff: { acp_model: model },
});