Skip to content

🙌 OpenHands: AI-Driven Development

feat: surface automation disablement reason in the UI (#17425)

Rohit Malhotrad8be0295b4cf
diff --git a/__tests__/components/automations/detail/disabled-reason-banner.test.tsx b/__tests__/components/automations/detail/disabled-reason-banner.test.tsx
new file mode 100644
index 0000000000..d3580b217b
--- /dev/null
+++ b/__tests__/components/automations/detail/disabled-reason-banner.test.tsx
@@ -0,0 +1,106 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+import { DisabledReasonBanner } from "#/components/features/automations/detail/disabled-reason-banner";
+import { I18nKey } from "#/i18n/declaration";
+import type { Automation } from "#/types/automation";
+
+const baseAutomation: Automation = {
+ id: "auto-1",
+ name: "Daily digest",
+ prompt: "Summarize",
+ trigger: { type: "cron", schedule: "0 9 * * *" },
+ enabled: false,
+ created_at: "2026-01-01T00:00:00Z",
+ updated_at: "2026-01-01T00:00:00Z",
+};
+
+describe("DisabledReasonBanner", () => {
+ it("renders nothing for an enabled automation even if a stale reason exists", () => {
+ const { container } = render(
+ <DisabledReasonBanner
+ automation={{
+ ...baseAutomation,
+ enabled: true,
+ disabled_reason: "Paused automatically: auth — bad key.",
+ }}
+ />,
+ );
+ expect(container.firstChild).toBeNull();
+ });
+
+ it("renders nothing for an inactive automation with no recorded reason", () => {
+ const { container } = render(
+ <DisabledReasonBanner automation={{ ...baseAutomation, disabled_reason: null }} />,
+ );
+ expect(container.firstChild).toBeNull();
+ });
+
+ it("surfaces the automatic-pause reason text and timestamp", () => {
+ const reason =
+ "Paused automatically: auth — Invalid API key. This failed the last 3 runs and needs a configuration fix.";
+ render(
+ <DisabledReasonBanner
+ automation={{
+ ...baseAutomation,
+ disabled_reason: reason,
+ disabled_detail: { reason: "consecutive_permanent_failures", source: "consecutive_permanent_failures" },
+ disabled_at: "2026-09-14T10:00:00Z",
+ }}
+ />,
+ );
+
+ expect(screen.getByTestId("automation-disabled-reason-banner")).toBeInTheDocument();
+ expect(screen.getByTestId("automation-disabled-reason-text")).toHaveTextContent(
+ reason,
+ );
+ expect(screen.getByTestId("automation-disabled-reason-timestamp")).toBeInTheDocument();
+ });
+
+ it("hides the timestamp when disabled_at is missing or invalid", () => {
+ render(
+ <DisabledReasonBanner
+ automation={{
+ ...baseAutomation,
+ disabled_reason: "Paused automatically: the last 5 runs all failed.",
+ disabled_detail: { reason: "consecutive_failures", source: "consecutive_failures" },
+ disabled_at: null,
+ }}
+ />,
+ );
+
+ expect(screen.queryByTestId("automation-disabled-reason-timestamp")).toBeNull();
+ });
+
+ it("hides the timestamp for an epoch/zero disabled_at", () => {
+ render(
+ <DisabledReasonBanner
+ automation={{
+ ...baseAutomation,
+ disabled_reason: "Paused automatically: the last 5 runs all failed.",
+ disabled_detail: { reason: "consecutive_failures", source: "consecutive_failures" },
+ disabled_at: "1970-01-01T00:00:00Z",
+ }}
+ />,
+ );
+
+ expect(screen.queryByTestId("automation-disabled-reason-timestamp")).toBeNull();
+ });
+
+ it("substitutes the manual-disable label", () => {
+ render(
+ <DisabledReasonBanner
+ automation={{
+ ...baseAutomation,
+ disabled_reason: "manual",
+ disabled_detail: { reason: "manual", source: "user" },
+ disabled_at: null,
+ }}
+ />,
+ );
+
+ expect(screen.getByTestId("automation-disabled-reason-text")).toHaveTextContent(
+ I18nKey.AUTOMATIONS$DETAIL$DISABLED_MANUAL,
+ );
+ expect(screen.queryByTestId("automation-disabled-reason-timestamp")).toBeNull();
+ });
+});
diff --git a/__tests__/components/features/home/home-automation-run-tooltip.test.tsx b/__tests__/components/features/home/home-automation-run-tooltip.test.tsx
index b6305ab714..fb99debaea 100644
--- a/__tests__/components/features/home/home-automation-run-tooltip.test.tsx
+++ b/__tests__/components/features/home/home-automation-run-tooltip.test.tsx
@@ -185,3 +185,59 @@ describe("HomeAutomationRunTooltip — task outcome", () => {
).not.toBeInTheDocument();
});
});
+
+describe("HomeAutomationRunTooltip — disabled reason", () => {
+ it("surfaces an automatic-pause reason on an inactive automation", () => {
+ const reason =
+ "Paused automatically: auth — Invalid API key. This failed the last 3 runs and needs a configuration fix.";
+ render(
+ <HomeAutomationRunTooltip
+ automation={{
+ ...automation,
+ enabled: false,
+ disabled_reason: reason,
+ disabled_detail: {
+ reason: "consecutive_permanent_failures",
+ source: "consecutive_permanent_failures",
+ },
+ }}
+ runState={makeState(null)}
+ />,
+ );
+
+ expect(screen.getByTestId("automation-tooltip-disabled-reason")).toHaveTextContent(
+ reason,
+ );
+ });
+
+ it("substitutes the manual-disable label instead of the raw 'manual' value", () => {
+ render(
+ <HomeAutomationRunTooltip
+ automation={{
+ ...automation,
+ enabled: false,
+ disabled_reason: "manual",
+ disabled_detail: { reason: "manual", source: "user" },
+ }}
+ runState={makeState(null)}
+ />,
+ );
+
+ expect(screen.getByTestId("automation-tooltip-disabled-reason")).toHaveTextContent(
+ "AUTOMATIONS$DETAIL$DISABLED_MANUAL",
+ );
+ });
+
+ it("omits the disabled-reason row for an enabled automation", () => {
+ render(
+ <HomeAutomationRunTooltip
+ automation={{ ...automation, enabled: true, disabled_reason: null }}
+ runState={makeState(makeRun())}
+ />,
+ );
+
+ expect(
+ screen.queryByTestId("automation-tooltip-disabled-reason"),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/__tests__/routes/automation-detail.test.tsx b/__tests__/routes/automation-detail.test.tsx
index 8cde11f349..53ace9b610 100644
--- a/__tests__/routes/automation-detail.test.tsx
+++ b/__tests__/routes/automation-detail.test.tsx
@@ -345,3 +345,49 @@ describe("AutomationDetail — Automation Runs As", () => {
expect(getCloudOrganizationMember).not.toHaveBeenCalled();
});
});
+
+describe("AutomationDetail — disabled reason banner", () => {
+ it("surfaces the latest disablement reason on an inactive automation", async () => {
+ // Arrange — an automation paused automatically for a permanent config fault.
+ const reason =
+ "Paused automatically: auth — Invalid API key. This failed the last 3 runs and needs a configuration fix.";
+ vi.mocked(AutomationService.getAutomation).mockResolvedValue({
+ ...automation,
+ enabled: false,
+ disabled_reason: reason,
+ disabled_detail: {
+ reason: "consecutive_permanent_failures",
+ source: "consecutive_permanent_failures",
+ },
+ disabled_at: "2026-09-14T10:00:00Z",
+ });
+
+ // Act
+ renderDetail();
+ await waitFor(() => {
+ expect(AutomationService.getAutomation).toHaveBeenCalledTimes(1);
+ });
+
+ // Assert — the banner renders the backend's human-readable reason.
+ expect(
+ await screen.findByTestId("automation-disabled-reason-banner"),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByTestId("automation-disabled-reason-text"),
+ ).toHaveTextContent(reason);
+ });
+
+ it("does not render the banner for an enabled automation", async () => {
+ // Arrange — default beforeEach returns the enabled automation fixture.
+ renderDetail();
+ await waitFor(() => {
+ expect(AutomationService.getAutomation).toHaveBeenCalledTimes(1);
+ });
+ await screen.findByText(automation.name);
+
+ // Assert
+ expect(
+ screen.queryByTestId("automation-disabled-reason-banner"),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/__tests__/utils/automation-disabled-reason.test.ts b/__tests__/utils/automation-disabled-reason.test.ts
new file mode 100644
index 0000000000..61dfd3a9ea
--- /dev/null
+++ b/__tests__/utils/automation-disabled-reason.test.ts
@@ -0,0 +1,136 @@
+import { describe, expect, it, vi } from "vitest";
+import { I18nKey } from "#/i18n/declaration";
+import type { Automation } from "#/types/automation";
+import {
+ getDisablementReasonDisplay,
+ hasDisablementReason,
+ isManualDisable,
+} from "#/utils/automation-disabled-reason";
+
+const t = (key: I18nKey) => key as string;
+const identity = vi.fn((key: I18nKey) => key as string);
+
+function automation(
+ overrides: Partial<Pick<Automation, "enabled" | "disabled_reason" | "disabled_detail">>,
+) {
+ return { enabled: true, ...overrides } as Automation;
+}
+
+describe("hasDisablementReason", () => {
+ it("is false for an enabled automation even with a stale reason", () => {
+ expect(
+ hasDisablementReason(
+ automation({
+ enabled: true,
+ disabled_reason: "Paused automatically: auth — bad key.",
+ }),
+ ),
+ ).toBe(false);
+ });
+
+ it("is false for an inactive automation with no recorded reason", () => {
+ expect(
+ hasDisablementReason(automation({ enabled: false, disabled_reason: null })),
+ ).toBe(false);
+ });
+
+ it("is true when inactive and a reason is recorded", () => {
+ expect(
+ hasDisablementReason(
+ automation({
+ enabled: false,
+ disabled_reason: "Paused automatically: auth — bad key.",
+ }),
+ ),
+ ).toBe(true);
+ });
+});
+
+describe("isManualDisable", () => {
+ it("detects the manual reason value", () => {
+ expect(
+ isManualDisable(
+ automation({
+ disabled_reason: "manual",
+ disabled_detail: { reason: "manual", source: "user" },
+ }),
+ ),
+ ).toBe(true);
+ });
+
+ it("detects the manual_delete reason value", () => {
+ expect(
+ isManualDisable(automation({ disabled_reason: "manual_delete" })),
+ ).toBe(true);
+ });
+
+ it("detects a user source in detail even with a non-manual reason string", () => {
+ expect(
+ isManualDisable(
+ automation({
+ disabled_reason: "some-other-reason",
+ disabled_detail: { source: "user" },
+ }),
+ ),
+ ).toBe(true);
+ });
+
+ it("is false for automatic disablement sources", () => {
+ expect(
+ isManualDisable(
+ automation({
+ disabled_reason:
+ "Paused automatically: the last 5 runs all failed and nothing has succeeded in 2 days.",
+ disabled_detail: { reason: "consecutive_failures", source: "consecutive_failures" },
+ }),
+ ),
+ ).toBe(false);
+ });
+});
+
+describe("getDisablementReasonDisplay", () => {
+ it("returns null when there is no recorded disablement reason", () => {
+ expect(
+ getDisablementReasonDisplay(automation({ enabled: false, disabled_reason: null }), identity),
+ ).toBeNull();
+ expect(
+ getDisablementReasonDisplay(automation({ enabled: true, disabled_reason: "manual" }), identity),
+ ).toBeNull();
+ });
+
+ it("substitutes a localized label for manual disables instead of the raw 'manual' string", () => {
+ const display = getDisablementReasonDisplay(
+ automation({
+ enabled: false,
+ disabled_reason: "manual",
+ disabled_detail: { reason: "manual", source: "user" },
+ }),
+ identity,
+ );
+ expect(display).not.toBeNull();
+ expect(display?.text).toBe(I18nKey.AUTOMATIONS$DETAIL$DISABLED_MANUAL);
+ });
+
+ it("surfaces the backend's human-readable reason for automatic disables", () => {
+ const reason =
+ "Paused automatically: auth — Invalid API key. This failed the last 3 runs and needs a configuration fix.";
+ const display = getDisablementReasonDisplay(
+ automation({
+ enabled: false,
+ disabled_reason: reason,
+ disabled_detail: { reason: "consecutive_permanent_failures", source: "consecutive_permanent_failures" },
+ }),
+ identity,
+ );
+ expect(display?.text).toBe(reason);
+ });
+
+ it("treats an automatic disable with an unknown source as automatic", () => {
+ const reason = "Paused automatically: the last 5 runs all failed.";
+ const display = getDisablementReasonDisplay(
+ automation({ enabled: false, disabled_reason: reason, disabled_detail: null }),
+ t,
+ );
+ expect(display?.text).toBe(reason);
+ });
+});
diff --git a/src/components/features/automations/detail/disabled-reason-banner.tsx b/src/components/features/automations/detail/disabled-reason-banner.tsx
new file mode 100644
index 0000000000..1328df9bc1
--- /dev/null
+++ b/src/components/features/automations/detail/disabled-reason-banner.tsx
@@ -0,0 +1,68 @@
+import { useTranslation } from "react-i18next";
+import { I18nKey } from "#/i18n/declaration";
+import type { Automation } from "#/types/automation";
+import { getDisablementReasonDisplay } from "#/utils/automation-disabled-reason";
+import {
+ formatRelativeTime,
+ isInvalidTimestamp,
+} from "#/utils/format-relative-time";
+import PauseIcon from "#/icons/pause.svg?react";
+
+interface DisabledReasonBannerProps {
+ automation: Automation;
+}
+
+/**
+ * Surfaces the reason an inactive automation was last disabled.
+ *
+ * The automation service records `disabled_reason`/`disabled_detail`/
+ * `disabled_at` on every disable (manual toggle, manual delete, or automatic
+ * pause for failing runs) and clears them on every re-enable, so when the
+ * automation is inactive and carries a reason, that reason is the latest
+ * reason it went inactive. Shown on the automation detail page below the
+ * header so the user knows *why* an automation is paused, not just that it is.
+ */
+export function DisabledReasonBanner({
+ automation,
+}: DisabledReasonBannerProps) {
+ const { t, i18n } = useTranslation("openhands");
+
+ const display = getDisablementReasonDisplay(automation, t);
+ if (!display) return null;
+
+ const showTimestamp = !isInvalidTimestamp(automation.disabled_at);
+
+ return (
+ <div
+ data-testid="automation-disabled-reason-banner"
+ className="flex flex-col gap-2 rounded-2xl border border-[var(--oh-border)] bg-[var(--oh-surface)] px-5 py-4"
+ >
+ <div className="flex items-center gap-2">
+ <PauseIcon className="size-4 shrink-0 text-muted" aria-hidden />
+ <h3 className="text-sm font-medium text-content">
+ {t(I18nKey.AUTOMATIONS$DETAIL$DISABLED_REASON_HEADING)}
+ </h3>
+ </div>
+ <p
+ data-testid="automation-disabled-reason-text"
+ className="text-sm leading-5 text-[var(--oh-text-secondary)]"
+ >
+ {display.text}
+ </p>
+ {showTimestamp ? (
+ <p
+ data-testid="automation-disabled-reason-timestamp"
+ className="text-xs text-muted"
+ >
+ {t(I18nKey.AUTOMATIONS$DETAIL$DISABLED_AT, {
+ time: formatRelativeTime(
+ automation.disabled_at as string,
+ i18n.language,
+ t,
+ ),
+ })}
+ </p>
+ ) : null}
+ </div>
+ );
+}
diff --git a/src/components/features/home/featured-automations/home-automation-run-tooltip.tsx b/src/components/features/home/featured-automations/home-automation-run-tooltip.tsx
index 0a6e8c2dd2..61c68931ca 100644
--- a/src/components/features/home/featured-automations/home-automation-run-tooltip.tsx
+++ b/src/components/features/home/featured-automations/home-automation-run-tooltip.tsx
@@ -21,6 +21,10 @@ import {
getRunHealthLabelKey,
getTriggerSummary,
} from "./automation-run-health";
+import {
+ getDisablementReasonDisplay,
+ hasDisablementReason,
+} from "#/utils/automation-disabled-reason";
export function getRunStatusLabelKey(
runState: LatestAutomationRunState,
@@ -99,6 +103,9 @@ export function HomeAutomationRunTooltip({
const TriggerIcon = automation.trigger.type === "event" ? Zap : ClockIcon;
const health = deriveRunHealth(runState);
const display = latestRun ? getAutomationRunDisplay(latestRun) : null;
+ const disabledReason = hasDisablementReason(automation)
+ ? getDisablementReasonDisplay(automation, t)
+ : null;
return (
<div className="flex w-[280px] flex-col gap-3 p-3">
@@ -124,6 +131,19 @@ export function HomeAutomationRunTooltip({
</span>
</PreviewRow>
+ {disabledReason ? (
+ <PreviewRow
+ label={t(I18nKey.AUTOMATIONS$DETAIL$DISABLED_REASON_HEADING)}
+ >
+ <span
+ data-testid="automation-tooltip-disabled-reason"
+ className="line-clamp-3 text-[var(--oh-text-secondary)]"
+ >
+ {disabledReason.text}
+ </span>
+ </PreviewRow>
+ ) : null}
+
<PhaseRow run={latestRun} />
{timestamp ? (
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 6b479e4e7d..0177bf39c0 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -14417,6 +14417,57 @@
"uk": "Неактивний",
"ca": "Inactiu"
},
+ "AUTOMATIONS$DETAIL$DISABLED_MANUAL": {
+ "en": "Turned off manually",
+ "ja": "手動でオフにしました",
+ "zh-CN": "已手动关闭",
+ "zh-TW": "已手動關閉",
+ "ko-KR": "수동으로 꺼짐",
+ "no": "Slått av manuelt",
+ "it": "Disattivata manualmente",
+ "pt": "Desativada manualmente",
+ "es": "Desactivada manualmente",
+ "ar": "تم إيقافها يدويًا",
+ "fr": "Désactivée manuellement",
+ "tr": "El ile kapatıldı",
+ "de": "Manuell deaktiviert",
+ "uk": "Вимкнено вручну",
+ "ca": "Desactivada manualment"
+ },
+ "AUTOMATIONS$DETAIL$DISABLED_REASON_HEADING": {
+ "en": "Why this is paused",
+ "ja": "一時停止の理由",
+ "zh-CN": "暂停原因",
+ "zh-TW": "暫停原因",
+ "ko-KR": "일시 중지된 이유",
+ "no": "Hvorfor dette er satt på pause",
+ "it": "Perché è in pausa",
+ "pt": "Por que está pausada",
+ "es": "Por qué está en pausa",
+ "ar": "سبب الإيقاف المؤقت",
+ "fr": "Pourquoi c'est en pause",
+ "tr": "Neden duraklatıldı",
+ "de": "Warum pausiert",
+ "uk": "Чому призупинено",
+ "ca": "Per què està en pausa"
+ },
+ "AUTOMATIONS$DETAIL$DISABLED_AT": {
+ "en": "Paused {{time}}",
+ "ja": "{{time}}に一時停止",
+ "zh-CN": "{{time}} 暂停",
+ "zh-TW": "{{time}} 暫停",
+ "ko-KR": "{{time}}에 일시 중지됨",
+ "no": "Satt på pause {{time}}",
+ "it": "In pausa {{time}}",
+ "pt": "Pausada {{time}}",
+ "es": "Pausada {{time}}",
+ "ar": "أُوقفت مؤقتًا {{time}}",
+ "fr": "En pause {{time}}",
+ "tr": "{{time}} duraklatıldı",
+ "de": "Pausiert {{time}}",
+ "uk": "Призупинено {{time}}",
+ "ca": "En pausa {{time}}"
+ },
"AUTOMATIONS$DETAIL$LAST_RUN": {
"en": "Last run",
"ja": "最終実行",
diff --git a/src/routes/automation-detail.tsx b/src/routes/automation-detail.tsx
index 5fa1a754f9..7affec129c 100644
--- a/src/routes/automation-detail.tsx
+++ b/src/routes/automation-detail.tsx
@@ -24,6 +24,7 @@ import {
} from "#/manifests/automation-interface";
import { BackLink } from "#/components/features/automations/detail/back-link";
import { DetailHeader } from "#/components/features/automations/detail/detail-header";
+import { DisabledReasonBanner } from "#/components/features/automations/detail/disabled-reason-banner";
import { PromptSection } from "#/components/features/automations/detail/prompt-section";
import { ConfigurationSection } from "#/components/features/automations/detail/configuration-section";
import { PluginsSection } from "#/components/features/automations/detail/plugins-section";
@@ -255,6 +256,7 @@ export default function AutomationDetail() {
canManage={canManage}
canToggle={canToggle}
/>
+ <DisabledReasonBanner automation={automation} />
{automation.prompt && <PromptSection prompt={automation.prompt} />}
<ConfigurationSection automation={automation} runsAs={runsAs} />
{automation.plugins && automation.plugins.length > 0 && (
diff --git a/src/types/automation.ts b/src/types/automation.ts
index f0616d8ab9..4bd66bf5f5 100644
--- a/src/types/automation.ts
+++ b/src/types/automation.ts
@@ -26,6 +26,28 @@ export interface Automation {
name: string;
trigger: AutomationTrigger;
enabled: boolean;
+ /**
+ * Human-readable reason the automation was last disabled (the latest
+ * disablement event overwrites this). Mirrors the automation service's
+ * `AutomationResponse.disabled_reason`. `null`/absent for enabled automations
+ * or an automation service older than the release that started recording it.
+ */
+ disabled_reason?: string | null;
+ /**
+ * Structured disablement metadata from the automation service
+ * (`AutomationResponse.disabled_detail`): `{reason, source, run_id, ...}`
+ * plus rule-specific fields (threshold, consecutive counts, status_detail).
+ * Used to tell user-initiated ("manual") disables from automatic ones
+ * (consecutive failures, permanent config faults).
+ */
+ disabled_detail?: {
+ reason?: string;
+ source?: string;
+ run_id?: string | null;
+ [key: string]: unknown;
+ } | null;
+ /** UTC timestamp the automation was last disabled. */
+ disabled_at?: string | null;
/**
* UUID of the user who created this automation. The backend returns it in
* `AutomationResponse.user_id`; the frontend uses it to implement the
@@ -61,7 +83,14 @@ export interface Automation {
export type AutomationSpec = Omit<
Automation,
- "id" | "created_at" | "updated_at" | "last_triggered_at" | "preset_metadata"
+ | "id"
+ | "created_at"
+ | "updated_at"
+ | "last_triggered_at"
+ | "preset_metadata"
+ | "disabled_reason"
+ | "disabled_detail"
+ | "disabled_at"
>;
/** The envelope constants come from the interface manifest's import/export spec. */
diff --git a/src/utils/automation-disabled-reason.ts b/src/utils/automation-disabled-reason.ts
new file mode 100644
index 0000000000..d9174c51ea
--- /dev/null
+++ b/src/utils/automation-disabled-reason.ts
@@ -0,0 +1,65 @@
+import { I18nKey } from "#/i18n/declaration";
+import type { Automation } from "#/types/automation";
+
+/** Detail `source` values written by the automation service on disable. */
+const MANUAL_DETAIL_SOURCES = new Set(["user"]);
+/** Top-level `disabled_reason` values written for user-initiated disables. */
+const MANUAL_REASON_VALUES = new Set(["manual", "manual_delete"]);
+
+/**
+ * Whether an automation is inactive *because* of a recorded disablement
+ * reason (vs. simply toggled off by an older client path, or an automation
+ * service that predates disablement tracking).
+ *
+ * The automation service overwrites `disabled_reason`/`disabled_detail`/
+ * `disabled_at` on every disable and clears them on every re-enable, so when
+ * an automation is `enabled === false` and carries a `disabled_reason`, that
+ * reason is the latest reason it went inactive.
+ */
+export function hasDisablementReason(
+ automation: Pick<Automation, "enabled" | "disabled_reason">,
+): boolean {
+ return !automation.enabled && Boolean(automation.disabled_reason);
+}
+
+/**
+ * Whether the recorded disablement was user-initiated (manual toggle / delete)
+ * rather than an automatic pause for failing runs.
+ */
+export function isManualDisable(
+ automation: Pick<Automation, "disabled_reason" | "disabled_detail">,
+): boolean {
+ const reason = automation.disabled_reason;
+ if (reason && MANUAL_REASON_VALUES.has(reason)) return true;
+ const source = automation.disabled_detail?.source;
+ if (source && MANUAL_DETAIL_SOURCES.has(source)) return true;
+ return false;
+}
+
+export interface DisablementReasonDisplay {
+ /**
+ * Full reason text to render. For automatic disables this is the backend's
+ * human-readable `disabled_reason` (already phrased for users, e.g.
+ * "Paused automatically: auth — ..."). For manual disables the backend
+ * stores the opaque "manual" string, so we substitute a localized label.
+ */
+ text: string;
+}
+
+/**
+ * Resolve the disablement reason into display text. Returns `null` when the
+ * automation is not inactive-for-a-recorded-reason.
+ */
+export function getDisablementReasonDisplay(
+ automation: Pick<
+ Automation,
+ "enabled" | "disabled_reason" | "disabled_detail"
+ >,
+ t: (key: I18nKey) => string,
+): DisablementReasonDisplay | null {
+ if (!hasDisablementReason(automation)) return null;
+ if (isManualDisable(automation)) {
+ return { text: t(I18nKey.AUTOMATIONS$DETAIL$DISABLED_MANUAL) };
+ }
+ return { text: automation.disabled_reason as string };
+}