🙌 OpenHands: AI-Driven Development
fix: derive automation timeout cap from deployment (#16233)
Graham Neubig8c04ebb894b5
diff --git a/__tests__/components/automations/detail/edit-automation-modal.test.tsx b/__tests__/components/automations/detail/edit-automation-modal.test.tsxindex 7fbb176112..77b2fa5e8f 100644--- a/__tests__/components/automations/detail/edit-automation-modal.test.tsx+++ b/__tests__/components/automations/detail/edit-automation-modal.test.tsx@@ -22,6 +22,7 @@ import type { Backend } from "#/api/backend-registry/types";vi.mock("#/api/automation-service/automation-service.api", () => ({default: {updateAutomation: vi.fn(),+ getCapabilities: vi.fn(),},}));@@ -56,7 +57,9 @@ vi.mock("#/manifests/automation-interface", async (importOriginal) => {await importOriginal<typeof import("#/manifests/automation-interface")>();return {...actual,- getAttributeSpec: (name: Parameters<typeof actual.getAttributeSpec>[0]) => ({+ getAttributeSpec: (+ name: Parameters<typeof actual.getAttributeSpec>[0],+ ) => ({...actual.getAttributeSpec(name),...specOverrides.current[name],}),@@ -131,11 +134,7 @@ function renderModal(automation: Automation) {const utils = render(<QueryClientProvider client={queryClient}><ActiveBackendProvider>- <EditAutomationModal- automation={automation}- isOpen- onClose={onClose}- />+ <EditAutomationModal automation={automation} isOpen onClose={onClose} /></ActiveBackendProvider></QueryClientProvider>,);@@ -153,6 +152,15 @@ beforeEach(() => {profiles: [],active_profile: null,});+ vi.mocked(AutomationService.getCapabilities).mockResolvedValue({+ ready: true,+ maxAutomationTimeoutSeconds: 900,+ triggerKinds: ["cron"],+ eventSources: [],+ eventTypes: [],+ triggers: {},+ features: [],+ });});describe("EditAutomationModal", () => {@@ -386,7 +394,7 @@ describe("EditAutomationModal", () => {// Arrange — automation currently times out after 600s.vi.mocked(AutomationService.updateAutomation).mockResolvedValue({...timeoutAutomation,- timeout: 1800,+ timeout: 900,});const user = userEvent.setup();renderModal(timeoutAutomation);@@ -397,9 +405,9 @@ describe("EditAutomationModal", () => {) as HTMLInputElement;expect(timeoutInput.value).toBe("600");- // Act — raise the timeout to the 1800s maximum and save.+ // Act — raise the timeout to the deployment's 900-second maximum and save.await user.clear(timeoutInput);- await user.type(timeoutInput, "1800");+ await user.type(timeoutInput, "900");await user.click(screen.getByTestId("edit-automation-save"));// Assert — the PATCH carries just the new timeout.@@ -407,7 +415,7 @@ describe("EditAutomationModal", () => {expect(AutomationService.updateAutomation).toHaveBeenCalledTimes(1);});expect(AutomationService.updateAutomation).toHaveBeenCalledWith("auto-4", {- timeout: 1800,+ timeout: 900,});});@@ -437,11 +445,17 @@ describe("EditAutomationModal", () => {// Arrangeconst user = userEvent.setup();renderModal(timeoutAutomation);+ await waitFor(() => {+ expect(screen.getByTestId("edit-automation-timeout")).toHaveAttribute(+ "max",+ "900",+ );+ });- // Act — enter a timeout beyond the 1800s cap and try to save.+ // Act — enter a timeout beyond the deployment's cap and try to save.const timeoutInput = screen.getByTestId("edit-automation-timeout");await user.clear(timeoutInput);- await user.type(timeoutInput, "2000");+ await user.type(timeoutInput, "901");await user.click(screen.getByTestId("edit-automation-save"));// Assert — no PATCH fired, inline error appears.@@ -451,6 +465,34 @@ describe("EditAutomationModal", () => {).toBeInTheDocument();});+ it("never lets the manifest raise the deployment timeout ceiling", async () => {+ // Arrange — the manifest offers 1200 seconds while the service owns 900.+ specOverrides.current = { timeout: { max: 1200 } };+ renderModal(timeoutAutomation);++ // Assert — the service value is the effective maximum.+ await waitFor(() => {+ expect(screen.getByTestId("edit-automation-timeout")).toHaveAttribute(+ "max",+ "900",+ );+ });+ });++ it("lets the manifest lower the deployment timeout ceiling", async () => {+ // Arrange — this automation surface imposes a stricter product policy.+ specOverrides.current = { timeout: { max: 600 } };+ renderModal(timeoutAutomation);++ // Assert — the lower manifest value wins over the service maximum.+ await waitFor(() => {+ expect(screen.getByTestId("edit-automation-timeout")).toHaveAttribute(+ "max",+ "600",+ );+ });+ });+it("renders only the attributes the interface manifest declares, with its copy", async () => {// Arrange — an admitted manifest that omits `prompt` and relabels `name`.specOverrides.current = {diff --git a/__tests__/manifests/automation-interface.test.ts b/__tests__/manifests/automation-interface.test.tsindex 33e4a6c79a..da8800a749 100644--- a/__tests__/manifests/automation-interface.test.ts+++ b/__tests__/manifests/automation-interface.test.ts@@ -45,7 +45,7 @@ describe("the automation interface seam", () => {detailPath: "/automations/a%2Fb",createEndpoint: "/v1/preset/prompt",dispatchEndpoint: "/v1/id-1/dispatch",- timeoutMax: 1800,+ timeoutMax: null,filenameSuffix: ".automation.json",featured: ["github-pr-reviewer",@@ -116,8 +116,9 @@ describe("the automation interface seam", () => {// Assert — nothing from the rejected manifest leaks through, and the// rejection is reported rather than silent.- expect({ listTitle: copy.listTitle, warned: warn.mock.calls.length }).toEqual(- { listTitle: null, warned: 1 },- );+ expect({+ listTitle: copy.listTitle,+ warned: warn.mock.calls.length,+ }).toEqual({ listTitle: null, warned: 1 });});});diff --git a/__tests__/utils/automation-timeout.test.ts b/__tests__/utils/automation-timeout.test.tsindex bfea14fce3..ada3baa7de 100644--- a/__tests__/utils/automation-timeout.test.ts+++ b/__tests__/utils/automation-timeout.test.ts@@ -11,12 +11,12 @@ describe("validateAutomationTimeout", () => {expect(result).toEqual({ value: null });});- it("accepts a positive integer up to the maximum", () => {+ it("accepts a positive integer up to a deployment-provided maximum", () => {// Arrange / Act- const result = validateAutomationTimeout("1800");+ const result = validateAutomationTimeout("900", 900);// Assert- expect(result).toEqual({ value: 1800 });+ expect(result).toEqual({ value: 900 });});it("rejects a non-integer value", () => {@@ -41,7 +41,7 @@ describe("validateAutomationTimeout", () => {it("rejects a value above the maximum", () => {// Arrange / Act- const result = validateAutomationTimeout("1801");+ const result = validateAutomationTimeout("901", 900);// Assertexpect(result).toEqual({diff --git a/src/components/features/automations/detail/edit-automation-modal.tsx b/src/components/features/automations/detail/edit-automation-modal.tsxindex 9fe489f0c8..a72e2c8c8d 100644--- a/src/components/features/automations/detail/edit-automation-modal.tsx+++ b/src/components/features/automations/detail/edit-automation-modal.tsx@@ -24,8 +24,8 @@ import {import {validateAutomationTimeout,AUTOMATION_TIMEOUT_DEFAULT_SECONDS,- AUTOMATION_TIMEOUT_MAX_SECONDS,} from "#/utils/automation-timeout";+import { useDeploymentCapabilities } from "#/hooks/query/use-manifest-capabilities";import {getAttributeSpec,getInterfaceCopy,@@ -134,6 +134,14 @@ export function EditAutomationModal({const modelSpec = getAttributeSpec("model");const timeoutSpec = getAttributeSpec("timeout");const scheduleSpec = getAttributeSpec("schedule");+ const { data: capabilities } = useDeploymentCapabilities();+ const serviceTimeoutMax = capabilities?.maxAutomationTimeoutSeconds;+ // The deployment owns the absolute ceiling. A manifest may narrow it, never+ // expand it; without discovery, leave maximum enforcement to the service.+ const timeoutMax =+ serviceTimeoutMax === undefined+ ? undefined+ : Math.min(serviceTimeoutMax, timeoutSpec.max ?? serviceTimeoutMax);const { data: profilesData, isLoading: isLoadingProfiles } = useLlmProfiles();const profiles = profilesData?.profiles ?? [];const modelItems = [@@ -199,12 +207,9 @@ export function EditAutomationModal({}setNameError(null);- const timeoutResult = validateAutomationTimeout(- form.timeout,- timeoutSpec.max ?? undefined,- );+ const timeoutResult = validateAutomationTimeout(form.timeout, timeoutMax);if ("errorKey" in timeoutResult) {- setTimeoutError(t(timeoutResult.errorKey));+ setTimeoutError(t(timeoutResult.errorKey, { max: timeoutMax }));return;}setTimeoutError(null);@@ -365,7 +370,7 @@ export function EditAutomationModal({error={timeoutError ?? undefined}showOptionalTagmin={timeoutSpec.min ?? 1}- max={timeoutSpec.max ?? AUTOMATION_TIMEOUT_MAX_SECONDS}+ max={timeoutMax}step={1}placeholder={String(AUTOMATION_TIMEOUT_DEFAULT_SECONDS)}/>diff --git a/src/hooks/query/use-manifest-capabilities.ts b/src/hooks/query/use-manifest-capabilities.tsindex 225cee6593..2cf4557035 100644--- a/src/hooks/query/use-manifest-capabilities.ts+++ b/src/hooks/query/use-manifest-capabilities.ts@@ -17,6 +17,20 @@ export interface SetupCapabilitiesResult {isLoading: boolean;}+/** Fetch the deployment-owned automation limits and feature set. */+export function useDeploymentCapabilities() {+ const { backend, orgId } = useActiveBackend();++ return useQuery({+ queryKey: [...SETUP_QUERY_KEYS.capabilities(), backend.id, orgId],+ queryFn: () => AutomationService.getCapabilities(),+ retry: false,+ staleTime: 1000 * 60 * 5,+ // An older deployment without discovery is an expected compatibility state.+ meta: { disableToast: true },+ });+}+/*** Ask the deployment what it supports, then compare that against what the* manifest requires.@@ -30,17 +44,7 @@ export interface SetupCapabilitiesResult {export function useSetupCapabilities(entry: SetupEntry,): SetupCapabilitiesResult {- const { backend, orgId } = useActiveBackend();-- const query = useQuery({- queryKey: [...SETUP_QUERY_KEYS.capabilities(), backend.id, orgId],- queryFn: () => AutomationService.getCapabilities(),- retry: false,- staleTime: 1000 * 60 * 5,- // A deployment without discovery is an expected state, not a user-facing- // failure.- meta: { disableToast: true },- });+ const query = useDeploymentCapabilities();if (query.isLoading) {return {diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 3f3131d6ec..88580560da 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -13838,21 +13838,21 @@"ca": "El temps d'espera ha de ser positiu"},"AUTOMATIONS$ERROR_TIMEOUT_MAX_EXCEEDED": {- "en": "Timeout cannot exceed 1800 seconds (30 minutes)",- "ja": "タイムアウトは1800秒(30分)を超えることはできません",- "zh-CN": "超时不能超过1800秒(30分钟)",- "zh-TW": "超時不能超過1800秒(30分鐘)",- "ko-KR": "타임아웃은 1800초(30분)을 초과할 수 없습니다",- "no": "Timeout kan ikke overstige 1800 sekunder (30 minutter)",- "it": "Il timeout non può superare 1800 secondi (30 minuti)",- "pt": "O timeout não pode exceder 1800 segundos (30 minutos)",- "es": "El timeout no puede exceder 1800 segundos (30 minutos)",- "ar": "لا يمكن أن تتجاوز المهلة الزمنية 1800 ثانية (30 دقيقة)",- "fr": "Le timeout ne peut pas dépasser 1800 secondes (30 minutes)",- "tr": "Zaman aşımı 1800 saniyeyi (30 dakika) aşamaz",- "de": "Timeout kann 1800 Sekunden (30 Minuten) nicht überschreiten",- "uk": "Таймаут не може перевищувати 1800 секунд (30 хвилин)",- "ca": "El temps d'espera no pot superar els 1800 segons (30 minuts)"+ "en": "Timeout cannot exceed {{max}} seconds",+ "ja": "タイムアウトは{{max}}秒を超えることはできません",+ "zh-CN": "超时不能超过{{max}}秒",+ "zh-TW": "超時不能超過{{max}}秒",+ "ko-KR": "타임아웃은 {{max}}초를 초과할 수 없습니다",+ "no": "Timeout kan ikke overstige {{max}} sekunder",+ "it": "Il timeout non può superare {{max}} secondi",+ "pt": "O timeout não pode exceder {{max}} segundos",+ "es": "El timeout no puede exceder {{max}} segundos",+ "ar": "لا يمكن أن تتجاوز المهلة الزمنية {{max}} ثانية",+ "fr": "Le timeout ne peut pas dépasser {{max}} secondes",+ "tr": "Zaman aşımı {{max}} saniyeyi aşamaz",+ "de": "Timeout kann {{max}} Sekunden nicht überschreiten",+ "uk": "Таймаут не може перевищувати {{max}} секунд",+ "ca": "El temps d'espera no pot superar els {{max}} segons"},"AUTOMATIONS$CUSTOM_SCHEDULE_HINT": {"en": "This automation uses a custom schedule. Frequency editing is disabled to avoid breaking it.",diff --git a/src/manifests/automation-interface.ts b/src/manifests/automation-interface.tsindex 3e5020330b..07faef2e22 100644--- a/src/manifests/automation-interface.ts+++ b/src/manifests/automation-interface.ts@@ -12,7 +12,6 @@*/import { AUTOMATION_CATALOG } from "@openhands/extensions/automations";-import { AUTOMATION_TIMEOUT_MAX_SECONDS } from "#/utils/automation-timeout";import { validateInterfaceManifest } from "./interface-validation";import { AUTOMATION_INTERFACE_CANDIDATE } from "./manifest-sources";import type {@@ -127,7 +126,7 @@ const DEFAULT_ATTRIBUTES: Record<AutomationAttributeName, AttributeSpec> = {help: null,required: false,min: 1,- max: AUTOMATION_TIMEOUT_MAX_SECONDS,+ max: null,},schedule: {present: true,diff --git a/src/manifests/manifest-validation.ts b/src/manifests/manifest-validation.tsindex 11df8f7e47..da14643a25 100644--- a/src/manifests/manifest-validation.ts+++ b/src/manifests/manifest-validation.ts@@ -329,8 +329,9 @@ function checkMode(check: SetupChecker, setup: Rec, kinds: string[]): void {if (setup.mode === "direct") {check.templateValue(setup.prompt, "setup.prompt");- // Optional here: it seeds the fallback conversation offered when the- // deployment cannot run the direct path.+ // A direct entry may carry a fallback-conversation seed for deployments+ // that cannot run the direct path, held to the same rules as an assisted+ // message.if (setup.message !== undefined) checkMessage(check, setup.message);// The derivation reads a single trigger kind, and an event trigger takesdiff --git a/src/manifests/types.ts b/src/manifests/types.tsindex a8e32336a2..b1300b904d 100644--- a/src/manifests/types.ts+++ b/src/manifests/types.ts@@ -129,6 +129,8 @@ export type SetupFormValues = Record<string, string>;/** `GET /v1/capabilities` — what this deployment supports. */export interface DeploymentCapabilities {ready: boolean;+ /** Absolute timeout ceiling enforced by this deployment's automation API. */+ maxAutomationTimeoutSeconds?: number;triggerKinds: string[];eventSources: string[];eventTypes: string[];diff --git a/src/types/automation.ts b/src/types/automation.tsindex 8c8d85c485..ba3e3d5f13 100644--- a/src/types/automation.ts+++ b/src/types/automation.ts@@ -31,7 +31,7 @@ export interface Automation {model?: string | null;/*** Maximum run time in seconds. `null`/omitted uses the server default- * (600s, 10 min); the server caps it at 1800s (30 min).+ * (600s, 10 min); the deployment reports the maximum it accepts.*/timeout?: number | null;diff --git a/src/utils/automation-timeout.ts b/src/utils/automation-timeout.tsindex b54714b761..8fd5f7548d 100644--- a/src/utils/automation-timeout.ts+++ b/src/utils/automation-timeout.ts@@ -1,12 +1,10 @@import { I18nKey } from "#/i18n/declaration";/**- * Per-automation run timeout bounds. These mirror the automation server- * (`openhands/automation/utils/timeout.py`): a `null`/omitted timeout falls back- * to the default, and the server rejects anything above the maximum.+ * Per-automation run timeout defaults. The deployment reports the maximum it+ * enforces through capability discovery.*/export const AUTOMATION_TIMEOUT_DEFAULT_SECONDS = 600; // 10 minutes-export const AUTOMATION_TIMEOUT_MAX_SECONDS = 1800; // 30 minutesexport type AutomationTimeoutValidation =| { value: number | null }@@ -15,12 +13,12 @@ export type AutomationTimeoutValidation =/*** Validate a raw timeout string from the edit form. A blank string means "use* the server default" (resolved as `null`). Otherwise the value must be a- * positive integer no greater than the ceiling, which the interface manifest- * may lower from {@link AUTOMATION_TIMEOUT_MAX_SECONDS}.+ * positive integer. When capability discovery supplies a ceiling, values above+ * it are rejected before the request reaches the service.*/export function validateAutomationTimeout(raw: string,- maxSeconds: number = AUTOMATION_TIMEOUT_MAX_SECONDS,+ maxSeconds?: number,): AutomationTimeoutValidation {const trimmed = raw.trim();if (!trimmed) return { value: null };@@ -32,7 +30,7 @@ export function validateAutomationTimeout(if (seconds <= 0) {return { errorKey: I18nKey.AUTOMATIONS$ERROR_TIMEOUT_POSITIVE };}- if (seconds > maxSeconds) {+ if (maxSeconds !== undefined && seconds > maxSeconds) {return { errorKey: I18nKey.AUTOMATIONS$ERROR_TIMEOUT_MAX_EXCEEDED };}return { value: seconds };