Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat: reset LLM profile to active from the edit modal (#1588)

Hiep Leeb47f599613b
diff --git a/__tests__/components/automations/detail/edit-automation-modal.test.tsx b/__tests__/components/automations/detail/edit-automation-modal.test.tsx
index 81e190daa4..876e2211db 100644
--- a/__tests__/components/automations/detail/edit-automation-modal.test.tsx
+++ b/__tests__/components/automations/detail/edit-automation-modal.test.tsx
@@ -274,6 +274,38 @@ describe("EditAutomationModal", () => {
expect(onClose).toHaveBeenCalled();
});
+ it("resets the LLM profile to active when 'Active profile' is selected", async () => {
+ // Arrange β€” automation pinned to "fast"; the backend re-resolves a null
+ // model back to whatever profile is active.
+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue(profilesResponse);
+ vi.mocked(AutomationService.updateAutomation).mockResolvedValue({
+ ...modeledAutomation,
+ model: "fast",
+ });
+ const user = userEvent.setup();
+ renderModal(modeledAutomation);
+
+ // The picker pre-fills with the pinned profile once profiles have loaded.
+ await waitFor(() =>
+ expect(screen.getByLabelText("AUTOMATIONS$DETAIL$MODEL")).toHaveValue(
+ "fast",
+ ),
+ );
+
+ // Act β€” clear the pin via the "Active profile" option, then save.
+ await user.click(screen.getByLabelText("AUTOMATIONS$DETAIL$MODEL"));
+ await user.click(await screen.findByText("COMMON$ACTIVE_PROFILE"));
+ await user.click(screen.getByTestId("edit-automation-save"));
+
+ // Assert β€” the PATCH carries model: null so the backend resets to active.
+ await waitFor(() => {
+ expect(AutomationService.updateAutomation).toHaveBeenCalledTimes(1);
+ });
+ expect(AutomationService.updateAutomation).toHaveBeenCalledWith("auto-3", {
+ model: null,
+ });
+ });
+
it("omits the LLM profile from the payload when it is left unchanged", async () => {
// Arrange β€” profiles available; the user will only rename the automation.
vi.mocked(ProfilesService.listProfiles).mockResolvedValue(profilesResponse);
diff --git a/src/components/features/automations/detail/edit-automation-modal.tsx b/src/components/features/automations/detail/edit-automation-modal.tsx
index d7b0dc245f..8b420022e2 100644
--- a/src/components/features/automations/detail/edit-automation-modal.tsx
+++ b/src/components/features/automations/detail/edit-automation-modal.tsx
@@ -36,6 +36,12 @@ interface EditAutomationModalProps {
type FrequencyKey = SchedulePresetKind | "custom";
+// Sentinel key for the "Active profile" picker option. Real profile names must
+// start with an alphanumeric (backend MODEL_PROFILE_PATTERN), so this cannot
+// collide with a stored profile name. Maps to an empty `form.model` (= use the
+// active/default profile).
+const ACTIVE_PROFILE_KEY = "__active__";
+
const WEEKDAY_KEYS: I18nKey[] = [
I18nKey.AUTOMATIONS$WEEKDAY_SUN,
I18nKey.AUTOMATIONS$WEEKDAY_MON,
@@ -107,7 +113,10 @@ export function EditAutomationModal({
const updateMutation = useUpdateAutomation();
const { data: profilesData, isLoading: isLoadingProfiles } = useLlmProfiles();
const profiles = profilesData?.profiles ?? [];
- const modelItems = profiles.map((p) => ({ key: p.name, label: p.name }));
+ const modelItems = [
+ { key: ACTIVE_PROFILE_KEY, label: t(I18nKey.COMMON$ACTIVE_PROFILE) },
+ ...profiles.map((p) => ({ key: p.name, label: p.name })),
+ ];
const initial = useMemo(() => buildInitialState(automation), [automation]);
const [form, setForm] = useState<FormState>(initial);
@@ -178,8 +187,9 @@ export function EditAutomationModal({
}
const selectedModel = form.model.trim();
- if (selectedModel && selectedModel !== (automation.model ?? "")) {
- body.model = selectedModel;
+ const initialModel = automation.model ?? "";
+ if (selectedModel !== initialModel) {
+ body.model = selectedModel === "" ? null : selectedModel;
}
if (!form.isCustomSchedule && form.frequency !== "custom") {
@@ -291,11 +301,14 @@ export function EditAutomationModal({
name="model"
label={t(I18nKey.AUTOMATIONS$DETAIL$MODEL)}
items={modelItems}
- selectedKey={form.model || undefined}
+ selectedKey={form.model || ACTIVE_PROFILE_KEY}
isLoading={isLoadingProfiles}
placeholder={t(I18nKey.COMMON$ACTIVE_PROFILE)}
onSelectionChange={(key) =>
- setForm((f) => ({ ...f, model: key ? String(key) : "" }))
+ setForm((f) => ({
+ ...f,
+ model: key && key !== ACTIVE_PROFILE_KEY ? String(key) : "",
+ }))
}
/>
)}