Skip to content

0018 - Health Signals, Alerts as Taskbase Incidents, and How the Ops Agent Picks Them Up

Status

Proposed 2026-10-20 in Taskbase task #1335 (epic "Ops agent runner", #66), from the owner's request of 2026-10-20: runtime-agnostic, a minimal first version, and an explicit trigger for every next step. Accepted when this pull request is merged. This record changes nothing live; the work is planned from it in Implementation tasks.

Amended 2026-10-22 (ADR 0020, task #1450): the ops-agent runner does not run on hetzner-mgmt (#1332 is superseded). It runs on the Mac mini in its own Lima VM with k3s, as a Deployment with one slot. A watchdog there also starts it without Taskbase when the cluster is down. The pipeline below does not change, because it was runtime-agnostic: Taskbase queues role=ops tasks, and whichever runner has the label takes them. By the owner's rule of 2026-10-22 the agent reaches the cluster only through a certificate-based admin kubeconfig that the owner generates and renews. It has no Terraform, Hetzner or Talos access, does no Talos or Kubernetes upgrade (those stay manual, done by the owner), and hands failures below Kubernetes to the owner with the evidence instead of repairing them.

Amended 2026-10-24 (Taskbase task #1457, platform task #1462): the operator has a fourth trigger next to its own health checks, monitoring alerts and Renovate tasks (ADR 0020, trigger d). Attention items: every minute Taskbase gives each agent task with an open task.needs_attention or task.question item a triage task, assigned to operator with required_labels: ["role=ops"], as soon as a role=ops runner serving the organization was seen within 24 hours. A task assigned to operator never gets one, so an incident the operator gives up on (§5, step 4) still goes to a person. Behaviour and limits: Triage up the reporting line.

Amended 2026-10-24 (Taskbase task #1337, Taskbase PR #572; platform task #1517): §3 is built as Incidents from Alertmanager describes. Two corrections. Task kinds are not free strings: the Context says they are "not a database constraint", but tasks.kind has been checked by tasks_kind_check since Taskbase migration 044, and each new kind widens it; migration 078 adds incident (api/internal/migrations/000078_incidents.up.sql, read 2026-10-24). "A run is working on it" (§3, resolved) shipped as: a run of the task started since the incident was created or last reopened, whether it is still going or finished. Such an incident stays open with a comment when its alert resolves; otherwise it closes as resolved by itself.

Amended 2026-10-24 (platform task #1533): the dead-man's-switch trigger in the deferred table was met by the 68-minute undetected Alertmanager outage. The Mac mini host environment check now reads active Watchdog from Alertmanager's API through the Kubernetes API server and opens a GitHub dr issue after a persistent failure. Its independent notification path and limitations are in the Mac mini ops runbook.

Amended 2026-11-07 (Taskbase task #2619, Taskbase PR #694; platform task #2620): §3's reopen rule shipped narrower. A firing notification within 24 h of the close reopens the incident only when it differs from what the incident was closed with: a fingerprint it did not have at the close, or an alert whose startsAt is after the close. Alertmanager's repeat of alerts that never stopped (for example PodEvicted, which fires for hours after an eviction) only updates last seen and fire count, adds no comment, queues no run and counts no reopen toward flapping. An incident closed by a resolved notification has no fingerprints left, so any later firing still reopens it. Details: Incidents from Alertmanager.

Date

2026-10-20

Context

The ops agent (persona operator, runner ops-agent on hetzner-mgmt, a CronJob that runs agent-runner run --once every 5 minutes and only takes tasks with required_labels: [role=ops]) is being built to upgrade risky dependencies and to repair failed rollouts. It only acts on what Taskbase gives it. Today Taskbase learns about one kind of trouble: a Flux error event. Nothing turns "an application is unhealthy" into work, and a person has no single place that shows the health of the platform. This record decides three things:

  1. Signals: which conditions count as an application being unhealthy, and how they are measured.
  2. Pipeline: how an alert becomes a Taskbase task that the ops agent picks up, without floods, duplicates or loops.
  3. Health view: what a person looks at to see the overall health.

Out of scope: the operator persona's rules (#1330), the ops runbook (#1327), deploying the runner (#1332), routing dependency and deploy-failure tasks (#1333). This record relies on them.

What exists today (read on 2026-10-20, Skatzi/platform main 6dfa7b7, Skatzi/taskbase main)

  • kube-prometheus-stack chart 92.10.1 in components/prometheus-stack/, the only Prometheus on a live cluster (kodexet is archived). defaultRules.create: true, so the chart's upstream rules are loaded; ruleSelectorNilUsesHelmValues: false, so any PrometheusRule in the cluster is picked up. Our own prometheus-rules.yaml has node CPU/memory and PVC 80 %/90 % rules.
  • Alertmanager reaches nobody on hetzner-mgmt. Its only receiver posts to Mattermost through the secret alertmanager-mattermost-webhook, and on hetzner-mgmt that secret is the component's literal webhookUrl: "placeholder" (components/prometheus-stack/alertmanager-mattermost-secret.yaml). Only kodexet ever replaced it with an ExternalSecret (cluster/kodexet/prometheus-stack/config/). This is open as #93 and #94 (epic #8). Prometheus sets no externalLabels, so alerts carry no cluster label.
  • Upstream rules already cover most pod and volume failures, with severity and an upstream runbook_url (chart templates templates/prometheus/rules-1.14/): KubePodCrashLooping, KubePodNotReady, KubeDeploymentRolloutStuck, KubeStatefulSetReplicasMismatch, KubeJobFailed (all warning), KubePersistentVolumeFillingUp (critical under 3 % free, warning when predicted full in 4 days) and CPUThrottlingHigh (info). The chart lets us add static labels per rule group (defaultRules.additionalRuleGroupLabels.<group>), annotations per rule (defaultRules.additionalRuleAnnotations.<alert>) and change severity/for per rule (customRules.<alert>). There is no upstream OOMKilled alert.
  • Metrics sources: cert-manager has a ServiceMonitor (service-monitors.yaml); CNPG clusters have enablePodMonitor: true; External Secrets Operator exposes no metrics (its chart needs serviceMonitor.enabled: true; the metric is externalsecret_status_condition, per the ESO metrics docs). Flux exports no readiness metrics that this platform scrapes; the Flux monitoring docs build resource readiness (gotk_resource_info) from kube-state-metrics custom-resource-state configuration, which we do not have.
  • CNPG backup alerts come with #1180 (open pull request #415): CNPGRestoreDrillFailed and CNPGWALArchivingFailing (critical), CNPGBackupStale (warning).
  • Canary Checker exists as components/canary-checker/ but runs only on the archived kodexet; the Renovate docs list it as an unused component. #97/#98 (epic #8) would install it on hetzner-mgmt.
  • Flux → Taskbase: notification-controller posts error events through a generic-hmac Provider (components/flux/taskbase-alerts/provider.yaml) to POST /api/webhooks/flux. Taskbase (api/internal/webhook/flux.go) checks the X-Signature HMAC of the body with FLUX_WEBHOOK_SECRET, answers 503 without a secret, refuses events older than 15 minutes, finds the project from the event's repository metadata, and keeps one task per (cluster, kind, namespace, name, revision) in a side table deploy_failures. The tasks are kind task. Kinds are free strings (task, request, dependency_update), not a database constraint.
  • Taskbase claims by priority: the runner queue orders by priority DESC, created_at (api/internal/runner/queue_pg.go), and Taskbase already records queue wait (claimed minus queued, ADR-0011 deferral table, Taskbase #480).

Facts from primary sources

  • Alertmanager webhooks cannot sign the body. <webhook_config> has url/url_file, http_config, max_alerts, timeout, send_resolved and a template payload; http_config offers basic_auth, authorization (type, credentials or credentials_file) and OAuth2, but no HMAC (Alertmanager configuration). So the Flux webhook's HMAC cannot be reused as is.
  • The webhook payload (version 4) carries status, groupKey, groupLabels, commonLabels, commonAnnotations, externalURL, truncatedAlerts and per alert status, labels, annotations, startsAt, endsAt, generatorURL and fingerprint (same page).
  • Silenced and inhibited alerts are not sent to any receiver (Alertmanager concepts), so a silence stops Taskbase too. An incident can therefore stay open after its alert ended under a silence; the agent's first check (decision 5) covers that.
  • Prometheus adds external_labels to alerts it sends to Alertmanager (Prometheus configuration).
  • The Prometheus Operator has a Probe resource that scrapes a prober such as the blackbox exporter for a static list of targets (API reference, monitoring.coreos.com/v1 Probe).

Decision

Overview

flowchart LR
  subgraph "hetzner-mgmt"
    rules["PrometheusRules"]
    probes["Blackbox exporter and Probes"]
    prom["Prometheus"]
    am["Alertmanager"]
    flux["Flux notification-controller"]
    ops["ops-agent CronJob"]
  end
  subgraph "Taskbase"
    amhook["POST /api/webhooks/alertmanager"]
    fluxhook["POST /api/webhooks/flux"]
    incident["incident task, one per group"]
    deploy["deploy-failure task"]
    triage["attention triage task"]
  end
  mm["Mattermost #alerts"]
  person["Person"]
  grafana["Grafana Platform health"]

  probes --> prom
  rules --> prom
  prom --> am
  am -- "all alerts" --> mm
  am -- "incident=true, critical or warning" --> amhook
  amhook --> incident
  flux --> fluxhook --> deploy
  incident -- "claimed by priority, role=ops" --> ops
  deploy --> ops
  triage -- "role=ops" --> ops
  ops -- "gives up" --> person
  grafana --> person
  mm --> person

1. Signals v1

An alert is an incident only when it says so. A rule opts in with the label incident: "true". Every alert keeps going to Mattermost; only opted-in alerts of severity critical or warning go to Taskbase. info never makes a task. Opting in is a pull request, and it needs a runbook that tells the agent what to do.

Every opted-in alert carries:

Field Kind Value
severity label critical (user-visible or data at risk) or warning (will become critical if left)
incident label "true"
component label The platform component, e.g. gitea; may be left out when it equals the namespace, since Taskbase falls back to namespace
repository label, optional owner/repo of the repository that owns the fix, when it is not Skatzi/platform (e.g. Skatzi/taskbase for Taskbase's probe)
cluster label From Prometheus externalLabels, set once per cluster from ${cluster_name}
runbook_url annotation Our runbook page for our own rules; the upstream runbook for opted-in upstream rules
summary, description annotation What is wrong, with the object's name

The v1 set:

Signal Source Severity Notes
Pod crash-looping, not ready, rollout stuck, StatefulSet replicas missing, Job failed Upstream groups kubernetesApps warning Opt in the whole group with additionalRuleGroupLabels.kubernetesApps: {incident: "true"}; upstream runbooks stay
Container OOMKilled more than twice in 1 h Own rule on kube_pod_container_status_last_terminated_reason and restarts warning No upstream rule exists
PVC filling up Upstream group kubernetesStorage critical / warning Opt in the group. Our own PersistentVolumeFillingUp (80 %) and PersistentVolumeAlmostFull (90 %) stay, without incident, as Mattermost warnings; no new 85 % rule
Certificate expires in under 14 days, or not Ready for 1 h Own rules on cert-manager's certmanager_certificate_expiration_timestamp_seconds and certmanager_certificate_ready_status warning; critical under 3 days cert-manager renews at 30 days, so 14 days means renewal has failed for two weeks
ExternalSecret not Ready for 15 min Own rule on externalsecret_status_condition warning Needs ESO serviceMonitor.enabled: true
CNPG WAL archiving failing, backup stale, restore drill failed #1180's rules critical / warning as #1180 set them Add incident: "true" and our runbook URL; #1180 owns the rules
Public host down Blackbox probe per public hostname, probe_success == 0 for 5 min critical See below
Gitea API slow Blackbox probe of a database-backed anonymous Gitea API call, probe_duration_seconds > 2 for 10 min warning The 2026-10-20 case: 3-10 s API calls and lost CI jobs
Flux deploy failure Flux notification-controller → /api/webhooks/flux (unchanged) — Keeps making deploy-failure tasks; not an Alertmanager alert

Not in v1: CPU throttling (CPUThrottlingHigh stays info: it explains slowness, it is not a fault to repair), node CPU/memory (Mattermost only), and Flux "not Ready for 30 minutes" (see deferred).

Probes: the Prometheus blackbox exporter with Probe resources, not Canary Checker. A probe is an HTTPS GET of each public hostname on hetzner-mgmt (every HTTPRoute host, including those of workload repositories such as Taskbase, Emiliero, Botyard and Helloweekly), through the public address like a user, expecting a 2xx/3xx answer. One Probe per component with a static target list, in Skatzi/platform beside the component; a new public host adds a target in the same pull request. The probe results are ordinary Prometheus series, so alerts, Grafana and the incident pipeline need nothing new.

Runbooks. One page per alert we own, in a runbooks/ directory next to the ops runbook page (#1327), named after the alert in lowercase: what it means, the read-only first checks, and links into the ops runbook's roll-forward and roll-back sections. Opted-in upstream alerts keep their upstream runbook_url, which the ops runbook's general section points to.

2. Alertmanager: one routing tree, two receivers

  • Receivers: mattermost (the webhook URL from OpenBao through an ExternalSecret, replacing the placeholder; this absorbs #93 and #94), taskbase (webhook to POST /api/webhooks/alertmanager) and null.
  • Routes, in order: alertname=~"Watchdog|InfoInhibitor" → null; then incident="true", severity=~"critical|warning" → taskbase with continue: true; then the default mattermost. Every alert reaches Mattermost; Mattermost stays the channel that does not depend on Taskbase or the ops agent.
  • Grouping is the dedupe key. The taskbase route groups by ['cluster', 'alertname', 'namespace', 'component']. All pods of one component that crash-loop form one group and one incident; pod names, which change on every restart, are not part of the key. Timers: group_wait: 1m, group_interval: 5m, repeat_interval: 4h, send_resolved: true.
  • Authentication: http_config.authorization with type: Bearer and credentials_file from a Secret mounted through alertmanagerSpec.secrets, synced by an ExternalSecret from OpenBao hetzner-mgmt/taskbase/alertmanager-webhook — the same secret pattern as taskbase-flux-webhook, a separate secret so one can be rotated without the other.
  • Silences are the only maintenance-window mechanism in v1: a person (or the ops agent before a planned risky step, logged in its run report) sets a silence in Alertmanager with an end time and a comment naming the task. No recurring time_intervals.

3. Taskbase: the incident

A new endpoint, task kind and side table, built like the deploy-failure path.

  • Endpoint POST /api/webhooks/alertmanager, outside the authenticated API mux like /api/webhooks/flux. Authentication is "the same way" in everything Alertmanager can do: a shared secret from OpenBao, ALERTMANAGER_WEBHOOK_TOKEN in Taskbase, compared in constant time; 503 when unset, 401 on a mismatch, 1 MiB body limit. There is no signed timestamp, so no replay window; a replayed request can only refresh or reopen an incident that the key already names.
  • Kind incident, with an incident object on the task (cluster, alertname, namespace, component, severity, first and last seen, fire count, Alertmanager link), like dependency on a dependency_update task. A kind rather than deploy-failure's plain task, so the persona, the board and the health view can tell incidents apart without parsing titles.
  • Key: the notification's groupLabels (cluster, alertname, namespace, component — component falls back to namespace). One open incident per key, in a unique side table incidents.
  • Project: the project linked to the alerts' repository label, else the project linked to Skatzi/platform (the Platform project).
  • Route: assignee operator, model large, required_labels: ["role=ops"], priority high for critical and medium for warning. The claim queue orders by priority, so a critical incident goes before queued dependency work on the one-slot ops runner.
  • Description: summary, description, every alert's labels, runbook_url, generatorURL and the Alertmanager link; the first lines tell the agent to check that the alert still fires before it changes anything.
  • firing: no open incident for the key → create one. Open incident → update last seen and fire count; add a comment only when the set of alerts in the group changed (a new pod, a new volume), not on every 4 h repeat. A key whose incident was closed less than 24 h ago reopens that task instead of making a new one, but only when its alerts differ from those it was closed with (a new fingerprint, or an alert that started after the close); a repeat of the same alerts only updates last seen and fire count (amended 2026-11-07, task #2619).
  • resolved: if no run is working on the incident, comment "resolved by itself" and close it. If a run is working on it, comment only; the agent closes it after it has checked. A key that reopened twice within 24 h is flapping: it is no longer closed automatically and is handed to a person in Needs attention with the history.
  • Storm cap: at most 5 open incidents per cluster. Beyond that, new keys do not get their own task: they are listed (and later marked resolved) on one open umbrella incident per cluster, "Incident storm on <cluster>", priority high. A storm usually has one cause (on 2026-10-20 one failed external-secrets upgrade froze about 20 Flux Kustomizations), and the one-slot ops runner could not work 20 tasks in parallel anyway. The operator closes the umbrella.
  • Info and unknown severities answer 200 and create nothing.

4. Spawning: the CronJob is enough for v1

The ops runner's CronJob runs every 5 minutes with concurrencyPolicy: Forbid and one slot. A new incident is claimed at the next tick, or after the run in progress ends. Priority ordering puts critical incidents first. No push from Taskbase, no KEDA and no second runner in v1: the trigger to build one is in the deferred table, measured with Taskbase's queue wait.

Runtime-agnostic: nothing in the pipeline depends on how the runner runs. Taskbase only queues a task with required_labels: ["role=ops"]; a CronJob, a long-lived Deployment or a machine outside the cluster with that label takes it the same way, with any agent adapter the runner has.

5. Escalation and safety

These go into the operator persona (#1330, with an incident follow-up) and the runbook pages:

  1. First check that the alert still fires (Alertmanager API in the cluster); if not, close the incident with what was seen.
  2. Read-only checks from the runbook before any write; GitOps first (fix by pull request), direct kubectl/flux/helm writes only for recovery and every command in the run report.
  3. A destructive or stateful step only with a fresh, verified backup from the component's backup gate (Renovate architecture §11); no gate, no step.
  4. When the runbook is exhausted, or the fix needs a person, stop and raise a Needs attention item with what was tried and 2-4 options (ADR-0010). No automatic re-queue of a given-up incident.
  5. A silence set by the agent always has an end time and names the incident.

6. Health view: one Grafana dashboard

A person sees the health in one "Platform health" Grafana dashboard, provisioned from git and set as Grafana's home dashboard: firing alerts by severity and component (from the ALERTS series, so it works whatever rules exist), probe status per public host, pods crash-looping or not ready, PVC usage with days until full (absorbs #96), certificate expiry, CNPG backup and drill status, and Gitea API latency. It links to the open incidents in Taskbase. Mattermost #alerts is the push channel; Taskbase holds what is being worked on. No status page in v1. Flux readiness is not on the dashboard in v1: Flux failures are deploy-failure tasks in Taskbase (see deferred).

Alternatives considered

Area Alternative Why not
Selection Every critical/warning alert becomes a task, as first sketched About 150 upstream rules are loaded; most have no runbook here, so the agent would get tasks it cannot act on, and the 5-incident cap would be spent on them. The opt-in label costs one line per rule group
Selection An alertname allowlist in the Alertmanager route Works, but the list lives far from the rule and its runbook; a label travels with the rule
Probes Canary Checker (#97/#98) Brings its own operator, CRDs, UI and a volume for result history; the only argument for it was "same as kodexet", which is archived. Blackbox results are plain Prometheus series and the Probe resource is already served by the operator we run
Probes Probes discovered automatically from HTTPRoutes About a dozen hosts today; a static list in the component's pull request is simpler. Deferred
Dedupe Key on alert fingerprint Changes with every new pod name, so one crash-looping Deployment would open a task per restart
Dedupe Key on groupKey Opaque and changes when the routing tree changes; groupLabels are the same labels, readable
Auth Reuse the Flux HMAC scheme Alertmanager cannot sign a body (primary source above)
Auth A templated payload with a hand-made signature The template language has no HMAC; the Alertmanager team marks custom payloads unsupported
Kind Plain task with a side table, like deploy failures The persona, board and health view would have to recognise incidents by title
Resolve Never close automatically Transient alerts would cost an Opus run each to find nothing
Spawning Taskbase starts a Kubernetes Job on a critical incident Gives Taskbase cluster credentials and couples it to one runtime
Spawning KEDA scaling the runner on Taskbase's queue A new operator and CRDs to save at most 5 minutes; KEDA would poll Taskbase anyway
Spawning Run the CronJob every minute Each tick is a pod start and a Taskbase login; the gain is at most 4 minutes
Health view A public status page now Nobody outside the team has asked; Grafana is behind Keycloak and serves the team
Overlap Install both Canary Checker and blackbox Two probe systems for the same hosts

Existing tasks of epic #8

  • #93, #94 (Alertmanager on hetzner-mgmt, Mattermost channel): absorbed by the Alertmanager routing task below; that task closes them when its work is live.
  • #96 (PVC dashboard): absorbed by the Platform health dashboard task; closed by it.
  • #97, #98 (Canary Checker): superseded by the blackbox probes task; closed by it.

Consequences

Positive

  • Alerts on hetzner-mgmt reach a person again (Mattermost) before any agent work starts, and do not wait for the backup chain.
  • The ops agent gets only actionable incidents, one per component and failure, with a runbook link, and a storm becomes one task.
  • Every piece is a stock part (upstream rules, blackbox exporter, Alertmanager webhook) plus one Taskbase endpoint modelled on an existing one.
  • Taskbase and the runner stay unaware of Kubernetes; another cluster joins by setting its cluster label, Mattermost secret and Taskbase token.

Negative

  • An alert without incident: "true" never reaches the agent; a new failure mode needs a rule pull request first. This is intended, but a real outage of an un-opted-in kind only reaches Mattermost.
  • Pick-up can take 5 minutes plus the length of a run already in progress on the single slot.
  • Alertmanager has no body signature; the bearer token is the only proof of origin.
  • Probing through the public address tests the gateway path from inside the cluster, not the internet path; a floating-IP or DNS failure outside the cluster is not seen.
  • If Prometheus or Alertmanager is down, no alert fires at all (see deferred: dead man's switch).

What we deferred (and what would trigger adding it)

Concept Trigger to add
Immediate spawn for critical incidents (a second ops slot or runner for incidents only; or Taskbase-triggered start) Taskbase queue wait for a critical incident above 30 minutes once, or its median above 10 minutes over 4 weeks
Flux "Kustomization/HelmRelease not Ready for 30 minutes" from kube-state-metrics custom-resource state A Flux object stays not Ready for more than 30 minutes without a deploy-failure task (found by a person or the agent)
Fold an incident into an open deploy-failure task of the same cluster and namespace Three incidents in a month that duplicated an open deploy-failure task
Probes discovered from HTTPRoutes A public host was found unprobed, or more than 25 hosts
Recurring maintenance windows (time_intervals) Planned recurring work (e.g. Talos upgrades) creates incidents twice
Dead man's switch outside the cluster for Watchdog The monitoring stack was down for more than an hour without anyone noticing
Probes from outside the cluster (internet path, DNS, floating IP) An outage that users saw and the in-cluster probes did not
Per-cluster webhook tokens bound to the cluster label A second cluster sends alerts to Taskbase
A cheaper triage model before the large run Incident runs cost more than 20 % of the ops runner's weekly usage (ADR-0008) for 2 weeks
A status page A user outside the team asks for platform status, or the team gets asked "is X down" more than twice a month
An incident view in Taskbase beyond the task list More than 10 incidents a week for 4 weeks
Raising or lowering the cap of 5 open incidents The umbrella task is used more than once a week, or never in 3 months

Implementation tasks

All in epic #66, each linked depends_on #1335. Tasks that make the ops agent act on live alerts also wait for the backup chain (#1228, #1180, #1181, #1183, #1184, #1185).

Task Repository Waits for backup chain
#1341 Alertmanager routing tree on hetzner-mgmt: Mattermost receiver from OpenBao, cluster external label, null route (absorbs #93, #94) platform no
#1336 Health signals v1: rules, opt-in labels, ESO metrics, runbook pages platform no
#1342 Blackbox exporter with a Probe per public host and the Gitea API latency probe (supersedes #97, #98) platform no
#1339 Platform health dashboard (absorbs #96) platform no
#1337 Taskbase /api/webhooks/alertmanager, kind incident, dedupe, resolve, flapping, storm cap taskbase yes
#1338 Alertmanager taskbase receiver with its token, end-to-end check platform yes
#1343 Operator persona: incident handling rules (follows #1330) skatzi-agents no