🙌 OpenHands: AI-Driven Development
Add automation LLM profile controls (#536)
Graham Neubig2e3f8b64ddfb
diff --git a/__tests__/api/automation-service.test.ts b/__tests__/api/automation-service.test.tsindex 2a9d18f9c7..aae43e8053 100644--- a/__tests__/api/automation-service.test.ts+++ b/__tests__/api/automation-service.test.ts@@ -1,25 +1,36 @@import { describe, it, expect, vi, beforeEach } from "vitest";+import { AutomationRunStatus } from "#/types/automation";import type {Automation,+ AutomationRun,AutomationsResponse,AutomationRunsResponse,} from "#/types/automation";import type { Backend } from "#/api/backend-registry/types";// Use vi.hoisted to define mocks that will be available during vi.mock hoisting-const { mockGet, mockPatch, mockDelete, mockCallCloudProxy, mockGetActive } =- vi.hoisted(() => ({- mockGet: vi.fn(),- mockPatch: vi.fn(),- mockDelete: vi.fn(),- mockCallCloudProxy: vi.fn(),- mockGetActive: vi.fn(),- }));+const {+ mockGet,+ mockPost,+ mockPatch,+ mockDelete,+ mockCallCloudProxy,+ mockGetActive,+} = vi.hoisted(() => ({+ mockGet: vi.fn(),+ mockPost: vi.fn(),+ mockPatch: vi.fn(),+ mockDelete: vi.fn(),+ mockCallCloudProxy: vi.fn(),+ mockGetActive: vi.fn(),+}));vi.mock("axios", () => ({default: {create: () => ({get: mockGet,+ post: mockPost,+patch: mockPatch,delete: mockDelete,interceptors: {@@ -65,11 +76,21 @@ const mockAutomation: Automation = {trigger: { type: "schedule", schedule_human: "Daily at 09:00" },enabled: true,repository: "acme/repo",- model: "Claude Opus",+ model: "daily-profile",created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-02T00:00:00Z",};+const mockRun: AutomationRun = {+ id: "run-1",+ status: AutomationRunStatus.PENDING,+ conversation_id: null,+ bash_command_id: null,+ error_detail: null,+ started_at: "2026-01-03T00:00:00Z",+ completed_at: null,+};+describe("AutomationService", () => {beforeEach(() => {// restoreAllMocks (vs clearAllMocks) re-attaches the original@@ -79,6 +100,8 @@ describe("AutomationService", () => {vi.restoreAllMocks();mockGet.mockReset();mockPatch.mockReset();+ mockPost.mockReset();+mockDelete.mockReset();mockCallCloudProxy.mockReset();// Default: active backend is local. Cloud-routing tests override this.@@ -167,6 +190,31 @@ describe("AutomationService", () => {});expect(result).toEqual(updated);});++ it("sends model profile updates to the automation API", async () => {+ const updated = { ...mockAutomation, model: "careful-profile" };+ mockPatch.mockResolvedValue({ data: updated });++ const result = await AutomationService.updateAutomation("1", {+ model: "careful-profile",+ });++ expect(mockPatch).toHaveBeenCalledWith("/api/automation/v1/1", {+ model: "careful-profile",+ });+ expect(result).toEqual(updated);+ });+ });++ describe("dispatchAutomation", () => {+ it("posts to the dispatch endpoint", async () => {+ mockPost.mockResolvedValue({ data: mockRun });++ const result = await AutomationService.dispatchAutomation("1");++ expect(mockPost).toHaveBeenCalledWith("/api/automation/v1/1/dispatch");+ expect(result).toEqual(mockRun);+ });});describe("deleteAutomation", () => {@@ -283,6 +331,20 @@ describe("AutomationService", () => {expect(result).toEqual(mockAutomation);});+ it("dispatchAutomation forwards method POST via callCloudProxy", async () => {+ mockCallCloudProxy.mockResolvedValue(mockRun);++ const result = await AutomationService.dispatchAutomation("abc");++ expect(mockCallCloudProxy).toHaveBeenCalledWith({+ backend: cloudBackend,+ method: "POST",+ path: "/api/automation/v1/abc/dispatch",+ });+ expect(mockPost).not.toHaveBeenCalled();+ expect(result).toEqual(mockRun);+ });+it("updateAutomation forwards method PATCH and body via callCloudProxy", async () => {const updated = { ...mockAutomation, enabled: false };mockCallCloudProxy.mockResolvedValue(updated);diff --git a/__tests__/hooks/query/use-automations-backend-switch.test.tsx b/__tests__/hooks/query/use-automations-backend-switch.test.tsxindex 708c35bcee..7dd5d8e968 100644--- a/__tests__/hooks/query/use-automations-backend-switch.test.tsx+++ b/__tests__/hooks/query/use-automations-backend-switch.test.tsx@@ -1,6 +1,6 @@import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import React from "react";-import { renderHook, waitFor } from "@testing-library/react";+import { act, renderHook, waitFor } from "@testing-library/react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import AutomationService from "#/api/automation-service/automation-service.api";@@ -10,11 +10,16 @@ import {setRegisteredBackends,} from "#/api/backend-registry/active-store";import { ActiveBackendProvider } from "#/contexts/active-backend-context";-import { useAutomations } from "#/hooks/query/use-automations";+import {+ useAutomations,+ useDispatchAutomation,+} from "#/hooks/query/use-automations";import { useAutomationDetail } from "#/hooks/query/use-automation-detail";import type { Backend } from "#/api/backend-registry/types";+import { AutomationRunStatus } from "#/types/automation";import type {Automation,+ AutomationRun,AutomationsResponse,} from "#/types/automation";@@ -22,6 +27,7 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({default: {getAutomations: vi.fn(),getAutomation: vi.fn(),+ dispatchAutomation: vi.fn(),},}));@@ -48,11 +54,21 @@ const automation: Automation = {trigger: { type: "schedule", schedule_human: "Daily" },enabled: true,repository: "acme/repo",- model: "Claude",+ model: "daily-profile",created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-01T00:00:00Z",};+const automationRun: AutomationRun = {+ id: "run-1",+ status: AutomationRunStatus.PENDING,+ conversation_id: null,+ bash_command_id: null,+ error_detail: null,+ started_at: "2026-01-02T00:00:00Z",+ completed_at: null,+};+const listResponse: AutomationsResponse = {automations: [automation],total: 1,@@ -76,6 +92,11 @@ beforeEach(() => {__resetActiveStoreForTests();vi.mocked(AutomationService.getAutomations).mockReset();vi.mocked(AutomationService.getAutomation).mockReset();+ vi.mocked(AutomationService.dispatchAutomation).mockReset();+ vi.mocked(AutomationService.dispatchAutomation).mockResolvedValue(+ automationRun,+ );+vi.mocked(AutomationService.getAutomations).mockResolvedValue(listResponse);vi.mocked(AutomationService.getAutomation).mockResolvedValue(automation);setRegisteredBackends([localBackend, cloudBackend]);@@ -109,10 +130,9 @@ describe("automation hooks — backend switch", () => {});it("useAutomationDetail refetches when the active backend changes", async () => {- const { result } = renderHook(- () => useAutomationDetail({ id: "auto-1" }),- { wrapper: makeWrapper() },- );+ const { result } = renderHook(() => useAutomationDetail({ id: "auto-1" }), {+ wrapper: makeWrapper(),+ });await waitFor(() => expect(result.current.isSuccess).toBe(true));expect(AutomationService.getAutomation).toHaveBeenCalledTimes(1);@@ -122,4 +142,16 @@ describe("automation hooks — backend switch", () => {expect(AutomationService.getAutomation).toHaveBeenCalledTimes(2);});});++ it("useDispatchAutomation dispatches the selected automation", async () => {+ const { result } = renderHook(() => useDispatchAutomation(), {+ wrapper: makeWrapper(),+ });++ await act(async () => {+ await result.current.mutateAsync("auto-1");+ });++ expect(AutomationService.dispatchAutomation).toHaveBeenCalledWith("auto-1");+ });});diff --git a/__tests__/routes/automation-detail.test.tsx b/__tests__/routes/automation-detail.test.tsxindex 526b39f99c..e9f7cfee3a 100644--- a/__tests__/routes/automation-detail.test.tsx+++ b/__tests__/routes/automation-detail.test.tsx@@ -1,6 +1,6 @@import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import React from "react";-import { render, screen, waitFor } from "@testing-library/react";+import { fireEvent, render, screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { MemoryRouter, Route, Routes } from "react-router";@@ -16,6 +16,7 @@ import {import { ActiveBackendProvider } from "#/contexts/active-backend-context";import AutomationDetail from "#/routes/automation-detail";import type { Backend } from "#/api/backend-registry/types";+import { AutomationRunStatus } from "#/types/automation";import type { Automation, AutomationRunsResponse } from "#/types/automation";vi.mock("#/api/automation-service/automation-service.api", () => ({@@ -24,6 +25,7 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({getAutomationRuns: vi.fn(),toggleAutomation: vi.fn(),deleteAutomation: vi.fn(),+ dispatchAutomation: vi.fn(),checkHealth: vi.fn(),},}));@@ -51,7 +53,7 @@ const automation: Automation = {trigger: { type: "schedule", schedule_human: "Daily" },enabled: true,repository: "acme/repo",- model: "Claude",+ model: "daily-profile",created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-01T00:00:00Z",};@@ -83,6 +85,17 @@ beforeEach(() => {__resetActiveStoreForTests();vi.mocked(AutomationService.checkHealth).mockReset();vi.mocked(AutomationService.checkHealth).mockResolvedValue({ status: "ok" });+ vi.mocked(AutomationService.dispatchAutomation).mockReset();+ vi.mocked(AutomationService.dispatchAutomation).mockResolvedValue({+ id: "run-1",+ status: AutomationRunStatus.PENDING,+ conversation_id: null,+ bash_command_id: null,+ error_detail: null,+ started_at: "2026-01-02T00:00:00Z",+ completed_at: null,+ });+vi.mocked(AutomationService.getAutomation).mockReset();vi.mocked(AutomationService.getAutomation).mockResolvedValue(automation);vi.mocked(AutomationService.getAutomationRuns).mockReset();@@ -162,4 +175,25 @@ describe("AutomationDetail — backend-change guard", () => {});expect(AutomationService.getAutomation).toHaveBeenCalledTimes(1);});++ it("shows the model field as the persisted model profile name", async () => {+ renderDetail();++ expect(await screen.findByText("daily-profile")).toBeInTheDocument();+ expect(screen.queryByText("Claude")).not.toBeInTheDocument();+ });++ it("dispatches the automation when Run now is clicked", async () => {+ renderDetail();++ const runNow = await screen.findByRole("button", { name: "Run now" });+ fireEvent.click(runNow);++ await waitFor(() => {+ expect(AutomationService.dispatchAutomation).toHaveBeenCalledWith(+ "auto-1",+ );+ });+ expect(AutomationService.dispatchAutomation).toHaveBeenCalledTimes(1);+ });});diff --git a/__tests__/routes/automations-list.test.tsx b/__tests__/routes/automations-list.test.tsxindex 00774955e9..facfb33d70 100644--- a/__tests__/routes/automations-list.test.tsx+++ b/__tests__/routes/automations-list.test.tsx@@ -51,7 +51,7 @@ const automation: Automation = {trigger: { type: "cron", schedule: "0 9 * * *", schedule_human: "Daily" },enabled: true,repository: "acme/repo",- model: "Claude",+ model: "daily-profile",created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-01T00:00:00Z",};diff --git a/src/api/automation-service/automation-service.api.ts b/src/api/automation-service/automation-service.api.tsindex 124c044f7d..b8c63842f6 100644--- a/src/api/automation-service/automation-service.api.ts+++ b/src/api/automation-service/automation-service.api.ts@@ -1,6 +1,7 @@import axios from "axios";import type {Automation,+ AutomationRun,AutomationsResponse,AutomationRunsResponse,} from "#/types/automation";@@ -127,6 +128,22 @@ class AutomationService {await localAutomationAxios.delete(path);}+ static async dispatchAutomation(id: string): Promise<AutomationRun> {+ const active = getActiveBackend().backend;+ const path = `${AUTOMATION_BASE_PATH}/v1/${encodeURIComponent(id)}/dispatch`;++ if (active.kind === "cloud") {+ return callCloudProxy<AutomationRun>({+ backend: active,+ method: "POST",+ path,+ });+ }++ const { data } = await localAutomationAxios.post<AutomationRun>(path);+ return data;+ }+static async listAutomationRuns(id: string,params: { limit?: number; offset?: number } = {},diff --git a/src/components/features/automations/detail/configuration-section.tsx b/src/components/features/automations/detail/configuration-section.tsxindex 0963d7b4ba..dba5eee3f5 100644--- a/src/components/features/automations/detail/configuration-section.tsx+++ b/src/components/features/automations/detail/configuration-section.tsx@@ -62,14 +62,12 @@ export function ConfigurationSection({{scheduleDisplay}</ConfigField>- {automation.model && (- <ConfigField- icon={<SparkleIcon className="size-3.5" />}- label={t(I18nKey.AUTOMATIONS$DETAIL$MODEL)}- >- {automation.model}- </ConfigField>- )}+ <ConfigField+ icon={<SparkleIcon className="size-3.5" />}+ label={t(I18nKey.AUTOMATIONS$DETAIL$MODEL)}+ >+ {automation.model ?? "Active profile"}+ </ConfigField>{automation.notification && (<ConfigFielddiff --git a/src/components/features/automations/detail/detail-header.tsx b/src/components/features/automations/detail/detail-header.tsxindex e4467a2e76..050b59cb2a 100644--- a/src/components/features/automations/detail/detail-header.tsx+++ b/src/components/features/automations/detail/detail-header.tsx@@ -20,6 +20,8 @@ interface DetailHeaderProps {*/onEdit?: () => void;onDelete: () => void;+ onRunNow?: () => void;+ isRunningNow?: boolean;}export function DetailHeader({@@ -27,6 +29,8 @@ export function DetailHeader({onToggle,onEdit,onDelete,+ onRunNow,+ isRunningNow = false,}: DetailHeaderProps) {const { t } = useTranslation("openhands");const canManage = useHasPermission("manage_automations");@@ -73,6 +77,16 @@ export function DetailHeader({<ActiveStatusBadge active={automation.enabled} /></div><div className="flex items-center gap-2">+ {canManage && onRunNow && (+ <button+ type="button"+ className="rounded-md border border-[var(--oh-border)] px-3 py-1.5 text-sm font-medium text-content transition-colors hover:bg-surface-raised disabled:cursor-not-allowed disabled:opacity-60"+ disabled={isRunningNow}+ onClick={onRunNow}+ >+ {isRunningNow ? "Starting…" : "Run now"}+ </button>+ )}{canManage && (<ToggleSwitchenabled={automation.enabled}diff --git a/src/hooks/query/use-automations.ts b/src/hooks/query/use-automations.tsindex 83c745ed1c..25fcbb58f6 100644--- a/src/hooks/query/use-automations.ts+++ b/src/hooks/query/use-automations.ts@@ -2,7 +2,10 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";import AutomationService from "#/api/automation-service/automation-service.api";import { useActiveBackend } from "#/contexts/active-backend-context";import type { Automation } from "#/types/automation";-import { AUTOMATION_DETAIL_QUERY_KEY } from "./use-automation-detail";+import {+ AUTOMATION_DETAIL_QUERY_KEY,+ AUTOMATION_RUNS_QUERY_KEY,+} from "./use-automation-detail";export const AUTOMATIONS_QUERY_KEY = ["automations"] as const;@@ -40,6 +43,18 @@ export function useToggleAutomation() {});}+export function useDispatchAutomation() {+ const queryClient = useQueryClient();+ return useMutation({+ mutationFn: (id: string) => AutomationService.dispatchAutomation(id),+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: AUTOMATIONS_QUERY_KEY });+ queryClient.invalidateQueries({ queryKey: AUTOMATION_DETAIL_QUERY_KEY });+ queryClient.invalidateQueries({ queryKey: AUTOMATION_RUNS_QUERY_KEY });+ },+ });+}+export function useUpdateAutomation() {const queryClient = useQueryClient();return useMutation({diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 15b28c2e69..f3fd2c817e 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -12461,7 +12461,7 @@"ca": "Carrega'n més"},"AUTOMATIONS$DETAIL$MODEL": {- "en": "Model",+ "en": "LLM profile","ja": "モデル","zh-CN": "模型","zh-TW": "模型",diff --git a/src/mocks/automations.mock.ts b/src/mocks/automations.mock.tsindex b89f1995fa..cc70fcd345 100644--- a/src/mocks/automations.mock.ts+++ b/src/mocks/automations.mock.ts@@ -27,7 +27,7 @@ export const MOCK_AUTOMATIONS_RESPONSE: AutomationsResponse = {},enabled: true,repository: "acme/frontend-app",- model: "Claude Opus",+ model: "triage-fast",created_at: daysAgo(90),updated_at: now,prompt:@@ -48,7 +48,7 @@ export const MOCK_AUTOMATIONS_RESPONSE: AutomationsResponse = {},enabled: true,repository: "acme/backend-api",- model: "GPT-5",+ model: "security-careful",created_at: daysAgo(60),updated_at: now,prompt:@@ -69,7 +69,7 @@ export const MOCK_AUTOMATIONS_RESPONSE: AutomationsResponse = {},enabled: true,repository: "acme/docs",- model: "GPT-4o",+ model: "docs-fast",created_at: daysAgo(45),updated_at: now,prompt:@@ -90,7 +90,7 @@ export const MOCK_AUTOMATIONS_RESPONSE: AutomationsResponse = {},enabled: false,repository: "acme/realtime-service",- model: "Gemini 2.5 Pro",+ model: "release-review",created_at: daysAgo(80),updated_at: now,prompt:@@ -111,7 +111,7 @@ export const MOCK_AUTOMATIONS_RESPONSE: AutomationsResponse = {},enabled: false,repository: "acme/incident-service",- model: "Claude Sonnet",+ model: "incident-summary",created_at: daysAgo(30),updated_at: now,prompt:diff --git a/src/routes/automation-detail.tsx b/src/routes/automation-detail.tsxindex fde902567a..adf956b490 100644--- a/src/routes/automation-detail.tsx+++ b/src/routes/automation-detail.tsx@@ -5,6 +5,7 @@ import { useAutomationDetail } from "#/hooks/query/use-automation-detail";import {useToggleAutomation,useDeleteAutomation,+ useDispatchAutomation,} from "#/hooks/query/use-automations";import { useAutomationHealth } from "#/hooks/query/use-automation-health";import { useActiveBackend } from "#/contexts/active-backend-context";@@ -60,6 +61,7 @@ export default function AutomationDetail() {const toggleMutation = useToggleAutomation();const deleteMutation = useDeleteAutomation();+ const dispatchMutation = useDispatchAutomation();const is404 =isError && isAxiosError(error) && error.response?.status === 404;@@ -131,6 +133,10 @@ export default function AutomationDetail() {});};+ const handleRunNow = () => {+ dispatchMutation.mutate(automation.id);+ };+// Edit is a local-backend-only feature in MVP — cloud automations// are managed elsewhere and we don't yet surface them here.const canEdit = active.backend.kind === "local";@@ -145,6 +151,8 @@ export default function AutomationDetail() {onToggle={handleToggle}onEdit={canEdit ? () => setShowEditModal(true) : undefined}onDelete={() => setShowDeleteModal(true)}+ onRunNow={handleRunNow}+ isRunningNow={dispatchMutation.isPending}/>{automation.prompt && <PromptSection prompt={automation.prompt} />}<ConfigurationSection automation={automation} />diff --git a/src/types/automation.ts b/src/types/automation.tsindex aa62ec46a3..d889ef4582 100644--- a/src/types/automation.ts+++ b/src/types/automation.ts@@ -10,7 +10,9 @@ export interface Automation {trigger: AutomationTrigger;enabled: boolean;repository?: string;- model?: string;+ /** LLM/model profile name used for automation runs. */+ model?: string | null;+created_at: string;updated_at: string;prompt: string | null;