Feat/operator alerts (#1635)

* feat(state): durable operator alerts owned by the State Store

Alerts dedup on org+kind+subject, resolve themselves when a condition
clears, and are raised, resolved, dismissed and listed through the state
contract. Task transitions raise needs-human and failed alerts in the same
transaction; the store checks service health and prunes closed alerts.
Each raise and resolve queues a webhook delivery whose attempts are kept.

* feat(notify): deliver operator alerts to the webhook; raise config and release alerts

notify.webhook now receives raised and resolved alerts above a severity
threshold with HMAC-signed payloads, bounded retry and every attempt recorded
on the alert. archied raises model alias, provider and credential-binding
alerts from the effective configuration, an update alert from the release
channel, and a credential-rejected alert from the egress resolver. The
dashboard API lists and dismisses the caller's org's alerts.

* feat(ui): alert bell in the top bar and webhook alert settings

The bell lists the org's open alerts by severity with dismiss and a link per
alert, and refreshes from the event stream. The task settings page gains the
webhook severity threshold and signing secret. ui/dist rebuilt.
This commit is contained in:
sam authored and GitHub committed 2026-10-12 03:30:46 +11:00
1 parent f34f60f9c7
commit 8a3ba32c5a
43 files changed
+4671 -465

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import { storeToRefs } from "pinia";
import { Bell } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { api } from "@/lib/api";
import { useLiveUpdatesStore } from "@/stores/live-updates";
import { groupBySeverity, type AlertSeverity, type OperatorAlert } from "./alerts";
const alerts = ref<OperatorAlert[]>([]);
const failed = ref(false);
const open = ref(false);
async function load() {
try {
alerts.value = (await api.alerts<{ alerts: OperatorAlert[] }>()).alerts;
failed.value = false;
} catch {
failed.value = true;
}
}
async function dismiss(alert: OperatorAlert) {
alerts.value = alerts.value.filter((a) => a.id !== alert.id);
try {
await api.dismissAlert(alert.id);
} catch {
await load();
}
}
// The bell follows the event stream: the store records every alert change as
// an event, so the newest alert event's id moving means the list moved. A
// reconnect re-reads, since events may have been missed while it was down.
const live = useLiveUpdatesStore();
const { activity, connectionRevision } = storeToRefs(live);
watch(() => activity.value.find((event) => event.kind === "alert")?.id, load);
watch(connectionRevision, load);
onMounted(load);
const groups = computed(() => groupBySeverity(alerts.value));
const tone: Record<AlertSeverity, "danger" | "warn" | "info"> = { action: "danger", warning: "warn", info: "info" };
const label = computed(() =>
alerts.value.length === 0 ? "Alerts" : `Alerts, ${alerts.value.length} open`,
);
function failedDeliveries(alert: OperatorAlert): number {
return alert.deliveries.filter((d) => d.state === "failed").length;
}
</script>
<template>
<Popover v-model:open="open">
<PopoverTrigger as-child>
<Button variant="ghost" size="icon" class="relative" :aria-label="label">
<Bell class="size-4" aria-hidden="true" />
<Badge
v-if="alerts.length"
:variant="groups[0] ? tone[groups[0].severity] : 'info'"
class="absolute -top-1 -right-1 h-4 min-w-4 px-1 text-[11px] tabular-nums"
>
{{ alerts.length }}
</Badge>
</Button>
</PopoverTrigger>
<PopoverContent align="end" class="w-96 max-w-[calc(100vw-1.5rem)] p-0">
<p v-if="failed" class="px-3 pt-3 text-xs text-danger" role="alert">Alerts could not be loaded.</p>
<p v-else-if="!groups.length" class="px-3 py-6 text-center text-sm text-fg-subtle">Nothing needs you.</p>
<div v-else class="max-h-96 overflow-y-auto">
<section v-for="group in groups" :key="group.severity" class="border-b p-3 last:border-b-0">
<h3 class="mb-2 text-xs font-medium text-fg-subtle">{{ group.label }}</h3>
<ul class="grid gap-3">
<li v-for="alert in group.alerts" :key="alert.id" class="grid gap-1">
<div class="flex items-start justify-between gap-2">
<RouterLink v-if="alert.link" :to="alert.link" class="text-sm font-medium hover:underline" @click="open = false">
{{ alert.title }}
</RouterLink>
<span v-else class="text-sm font-medium">{{ alert.title }}</span>
<Button variant="ghost" size="sm" class="h-6 shrink-0 px-2 text-xs" @click="dismiss(alert)">
Dismiss
</Button>
</div>
<p v-if="alert.body" class="text-xs text-fg-subtle">{{ alert.body }}</p>
<p class="text-xs text-fg-subtle">
<template v-if="alert.count > 1">Seen {{ alert.count }} times. </template>
<template v-if="alert.condition">Clears when fixed; dismissing snoozes it.</template>
<template v-else>Stays until dismissed.</template>
</p>
<p v-if="failedDeliveries(alert)" class="text-xs text-warn">Webhook delivery failed.</p>
</li>
</ul>
</section>
</div>
</PopoverContent>
</Popover>
</template>
+36
View File
@@ -0,0 +1,36 @@
/** Operator alerts as the dashboard reads them: what needs a human, by severity. */
export type AlertSeverity = "action" | "warning" | "info";
export interface AlertDelivery {
event: string;
state: string;
attempts: { n: number; at: string; status_code?: number; error?: string }[];
}
export interface OperatorAlert {
id: number;
kind: string;
severity: AlertSeverity;
title: string;
body: string;
link?: string;
condition: boolean;
count: number;
last_seen: string;
deliveries: AlertDelivery[];
}
/** Most urgent first, as the list groups them. */
export const SEVERITY_GROUPS: { severity: AlertSeverity; label: string }[] = [
{ severity: "action", label: "Needs you" },
{ severity: "warning", label: "Warnings" },
{ severity: "info", label: "Info" },
];
export function groupBySeverity(alerts: readonly OperatorAlert[]) {
return SEVERITY_GROUPS.map((group) => ({
...group,
alerts: alerts.filter((alert) => alert.severity === group.severity),
})).filter((group) => group.alerts.length > 0);
}
+2
View File
@@ -1,4 +1,5 @@
<script setup lang="ts">
import AlertsBell from "@/alerts/AlertsBell.vue";
import NewTaskButton from "@/tasks/NewTaskButton.vue";
import Brand from "./Brand.vue";
import ConnectionPill from "./ConnectionPill.vue";
@@ -19,6 +20,7 @@ const props = defineProps<{ hidden: string[] }>();
<div class="flex shrink-0 items-center gap-2">
<SearchBar :hidden="props.hidden" />
<NewTaskButton v-if="!props.hidden.includes('/workflows')" />
<AlertsBell />
<ConnectionPill />
<SupportLink />
<ProfileDropdown />
+3
View File
@@ -191,6 +191,9 @@ export const api = {
`/api/orgs/${encodeURIComponent(id)}/agents/${encodeURIComponent(identity)}`,
{ method: "PUT" },
),
alerts: <T = unknown>() => request<T>("/api/alerts"),
dismissAlert: (id: number) =>
request<void>(`/api/alerts/${id}/dismiss`, { method: "POST", parse: false }),
summary: <T = unknown>() => request<T>("/api/summary"),
tasks: <T = unknown>() => request<T>("/api/tasks"),
// taskPage reads one page of the board; next is the cursor for the page
+21 -2
View File
@@ -3,7 +3,9 @@ import ApplyStatusRows from "./ApplyStatusRows.vue";
import { computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import { Button } from "@/components/ui/button";
import {Input} from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import PageHeader from "@/base/PageHeader.vue";
import { DurationInput, formatGoDuration, parseGoDuration } from "@/components/ui/duration-input";
import {
@@ -17,6 +19,7 @@ import { SettingRow } from "@/components/ui/setting-row";
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import SecretRefField from "./SecretRefField.vue";
const POLICY="task-policy";
const KIND = "workflow-execution-settings";
@@ -33,7 +36,7 @@ const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "tasks"));
const policy=computed(()=>store.drafts[POLICY]?.value as {diff_cap_lines:number;notify_webhook:string}|undefined);
const policy=computed(()=>store.drafts[POLICY]?.value as {diff_cap_lines:number;notify_webhook:string;notify_min_severity:string;notify_secret:{engine:string;key:string}}|undefined);
const limits = computed(() => store.drafts[KIND]?.value as ExecutionSettings | undefined);
const error = computed(() => store.pageErrorFor(KIND));
@@ -66,9 +69,25 @@ const taskRuntime = seconds("max_task_runtime_seconds");
<SettingRow label="Maximum changed lines" hint="Applied to new tasks. 0 disables the limit." for="task-diff-cap">
<div class="flex flex-wrap items-center gap-3"><Input id="task-diff-cap" v-model.number="policy.diff_cap_lines" type="number" min="0" class="max-w-40" /><DraftHint :kind="POLICY" path="diff_cap_lines" /></div>
</SettingRow>
<SettingRow label="Notification webhook" hint="Applied to new tasks. Empty disables notifications." for="task-notify">
<SettingRow label="Alert webhook" hint="Receives each raised and resolved alert. Empty disables." for="task-notify">
<div class="flex flex-wrap items-center gap-3"><Input id="task-notify" v-model="policy.notify_webhook" type="url" class="max-w-md" /><DraftHint :kind="POLICY" path="notify_webhook" /></div>
</SettingRow>
<SettingRow label="Webhook severity" hint="The lowest severity delivered.">
<div class="flex flex-wrap items-center gap-3">
<Select :model-value="policy.notify_min_severity || 'warning'" @update:model-value="policy.notify_min_severity = String($event)">
<SelectTrigger class="w-40" aria-label="Webhook severity"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="info">Info</SelectItem>
<SelectItem value="warning">Warning</SelectItem>
<SelectItem value="action">Needs you</SelectItem>
</SelectContent>
</Select>
<DraftHint :kind="POLICY" path="notify_min_severity" />
</div>
</SettingRow>
<SettingRow label="Webhook signing secret" hint="Signs each payload in X-Archie-Signature. Not set sends unsigned.">
<div class="flex flex-wrap items-center gap-3"><SecretRefField v-if="policy.notify_secret" v-model="policy.notify_secret" id-prefix="task-notify-secret" /><Button v-else variant="outline" size="sm" @click="policy.notify_secret = { engine: '', key: '' }">Set reference</Button><DraftHint :kind="POLICY" path="notify_secret" /></div>
</SettingRow>
</template>
<template v-if="limits">
<SettingRow label="Task time limit" for="te-task" hint="Parked after this. 0 disables.">