Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(settings): keep "Don't create profiles" for router templates (#18020)

awss9c550ac39e88
diff --git a/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx b/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx
index 1d6c9114f5..ccfeae377b 100644
--- a/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx
+++ b/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx
@@ -229,6 +229,69 @@ describe("MetaProfileEditor", () => {
expect(onSave).toHaveBeenCalledWith("fast", FILLED, null);
});
+ it("keeps an explicit don't create choice over the template's default connection", async () => {
+ const user = userEvent.setup();
+ const onSave = vi.fn();
+ renderWithProviders(
+ <MetaProfileEditor
+ mode="create"
+ initialConfig={FILLED}
+ providerConnections={CONNECTIONS}
+ selectRouterConnectionByDefault
+ availableProfiles={AVAILABLE}
+ isSaving={false}
+ onSave={onSave}
+ onCancel={vi.fn()}
+ />,
+ );
+ const picker = screen.getByTestId("meta-profile-router-connection");
+
+ await user.click(picker);
+ await user.click(
+ screen.getByRole("option", {
+ name: "SETTINGS$META_PROFILE_ROUTER_CONNECTION_NONE",
+ }),
+ );
+
+ expect(picker).toHaveValue("SETTINGS$META_PROFILE_ROUTER_CONNECTION_NONE");
+ await user.click(screen.getByTestId("meta-profile-save"));
+ expect(onSave).toHaveBeenCalledWith(
+ DEFAULT_ROUTER_PRO_META_PROFILE_NAME,
+ FILLED,
+ null,
+ );
+ });
+
+ it("preselects the first connection when connections load after the editor opens", async () => {
+ const user = userEvent.setup();
+ const onSave = vi.fn();
+ const editor = (providerConnections: typeof CONNECTIONS) => (
+ <MetaProfileEditor
+ mode="create"
+ initialConfig={FILLED}
+ providerConnections={providerConnections}
+ selectRouterConnectionByDefault
+ availableProfiles={AVAILABLE}
+ isSaving={false}
+ onSave={onSave}
+ onCancel={vi.fn()}
+ />
+ );
+ const { rerender } = renderWithProviders(editor([]));
+ const picker = screen.getByTestId("meta-profile-router-connection");
+ expect(picker).toHaveValue("SETTINGS$META_PROFILE_ROUTER_CONNECTION_NONE");
+
+ rerender(editor(CONNECTIONS));
+
+ expect(picker).toHaveValue("OpenHands (openhands)");
+ await user.click(screen.getByTestId("meta-profile-save"));
+ expect(onSave).toHaveBeenCalledWith(
+ DEFAULT_ROUTER_PRO_META_PROFILE_NAME,
+ FILLED,
+ "conn-openhands",
+ );
+ });
+
it("allows the existing name in edit mode (no duplicate warning)", () => {
renderWithProviders(
<MetaProfileEditor
diff --git a/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx b/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx
index d281b72247..65a612557f 100644
--- a/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx
+++ b/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useState } from "react";
+import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { BrandButton } from "#/components/features/settings/brand-button";
import { SettingsDropdownInput } from "#/components/features/settings/settings-dropdown-input";
@@ -112,28 +112,17 @@ export function MetaProfileEditor({
return [...byId.values()];
}, [providerConnections, createdProviderConnections]);
const showRouterConnectionPicker = !isEdit;
- const [routerConnectionId, setRouterConnectionId] = useState(() =>
- selectRouterConnectionByDefault && providerConnections.length > 0
- ? providerConnections[0].id
- : NO_ROUTER_CONNECTION_KEY,
- );
-
- useEffect(() => {
- if (
- !showRouterConnectionPicker ||
- routerConnectionId ||
- !selectRouterConnectionByDefault ||
- connectionOptions.length === 0
- ) {
- return;
- }
- setRouterConnectionId(connectionOptions[0].id);
- }, [
- connectionOptions,
- routerConnectionId,
- selectRouterConnectionByDefault,
- showRouterConnectionPicker,
- ]);
+ // `null` until the user picks a connection. "Don't create profiles" is the
+ // empty key, so the template default must not be stored in the same state
+ // or it would overwrite that choice.
+ const [chosenRouterConnectionId, setChosenRouterConnectionId] = useState<
+ string | null
+ >(null);
+ const routerConnectionId =
+ chosenRouterConnectionId ??
+ (selectRouterConnectionByDefault && connectionOptions.length > 0
+ ? connectionOptions[0].id
+ : NO_ROUTER_CONNECTION_KEY);
// The classifier dropdown is driven by saved LLM profile names, but a router
// template can name a classifier (e.g. ``minimax-m3``) before any profiles
@@ -185,7 +174,7 @@ export function MetaProfileEditor({
...existing.filter((item) => item.id !== connection.id),
]);
onProviderConnectionCreated?.(connection);
- setRouterConnectionId(connection.id);
+ setChosenRouterConnectionId(connection.id);
};
const handleSave = () => {
@@ -331,7 +320,7 @@ export function MetaProfileEditor({
selectedKey={routerConnectionId}
isDisabled={isSaving}
onSelectionChange={(key) =>
- setRouterConnectionId(
+ setChosenRouterConnectionId(
key ? String(key) : NO_ROUTER_CONNECTION_KEY,
)
}