Skip to content

Taskbase — Incidents from Alertmanager

Kind: reference

Alertmanager posts opted-in alert groups to POST /api/webhooks/alertmanager. Taskbase keeps one open task of kind incident per alert group, routed to the operator persona on a role=ops runner, and refreshes, reopens or closes it as later notifications arrive. This page describes the endpoint, the incident task and the rules as they shipped (ADR 0018 §3, task #1337, Taskbase PR #572, first released in Taskbase v1.230.0). An incident left to a person waits for them (Waiting for a person, task #1555, Taskbase PR #579).

Sources, read on 2026-10-24 on Skatzi/taskbase main 08537ab: api/internal/webhook/alertmanager.go, api/internal/task/incident.go, api/internal/task/incident_pg.go, api/internal/migrations/000078_incidents.up.sql, deploy/prod/alertmanager-webhook-external-secret.yaml, deploy/prod/api-deployment.yaml and the OpenAPI operation postAlertmanagerNotification. The Waiting for a person rules were read on 2026-10-24 on main b25d1b3 (PR #579): api/internal/webhook/alertmanager.go (reopen), api/internal/webhook/handler.go (completeMergedPR, UseIncidents), api/internal/task/incident_pg.go (waitsForPersonSQL, ReopenIncident) and their tests. The repeat rule was read on 2026-11-07 on main 2566270 (task #2619, Taskbase PR #694): api/internal/webhook/alertmanager.go (closedWith, repeat).

The sending side — the taskbase receiver, its route, and how an alert opts in with incident="true" — is in Prometheus stack: Alerting. DR run reports filed by a runner are also incident tasks, but take another path (POST /api/runners/{id}/incidents) and have no incidents row.

Endpoint

POST /api/webhooks/alertmanager sits outside the authenticated API, like the Flux webhook. Alertmanager proves itself with a bearer token.

  • Token. Authorization: Bearer <token>, compared in constant time with ALERTMANAGER_WEBHOOK_TOKEN. In prod the variable comes from the Secret tasks-alertmanager-webhook (key token, optional), which the ExternalSecret of the same name in tasks-prod syncs from OpenBao hetzner-mgmt/taskbase/alertmanager-webhook, property token. Alertmanager reads the same OpenBao key. The API reads the variable only at start.
  • Body. Alertmanager's webhook payload, version 4, at most 1 MiB. There is no signed timestamp and so no replay window.
  • Key. The notification's groupLabels cluster, alertname, namespace and component. An empty component falls back to namespace.
  • Severity. The highest of the alerts' severity labels (critical above warning), else commonLabels.severity. Only critical and warning make incidents.
Answer When
201 {"result":"created","task_id":N} A new incident task was made
200 {"result":"updated","task_id":N} A firing notification refreshed the key's open incident
200 {"result":"reopened","task_id":N} A firing notification reopened an incident closed under 24 h ago
200 {"result":"repeat","task_id":N} A firing notification repeated the alerts an incident closed under 24 h ago was closed with; it stays closed
200 {"result":"storm","task_id":N} The key is listed on the cluster's umbrella task N (Storm cap)
200 {"result":"closed","task_id":N} A resolved notification closed the incident
200 {"result":"kept","task_id":N} A resolved notification left the incident open (flapping, or a run worked on it)
200 {"result":"ignored"} A severity other than critical/warning, or a resolved notification for a key with no open incident
400 The body is not JSON
401 The Authorization header is missing, not Bearer, or the token does not match
413 The body is over 1 MiB
422 version is not "4"; groupLabels lack cluster or alertname; or neither the repository label's project nor Skatzi/platform's is linked
500 Database error
503 ALERTMANAGER_WEBHOOK_TOKEN is not set

The checks run in that order: token, body, version, key, severity. A 422 for an unlinked project comes only when a task would be created.

A firing notification as the webhook tests build it (shortened from notification in api/internal/webhook/alertmanager_test.go; the tests passed on 2026-10-24 with go test ./internal/webhook/ -run Alertmanager; the payload was not posted to a live Taskbase from this page):

{
  "version": "4",
  "status": "firing",
  "receiver": "taskbase",
  "groupLabels": {"cluster": "hetzner-mgmt", "alertname": "KubePodCrashLooping", "namespace": "gitea"},
  "commonLabels": {"alertname": "KubePodCrashLooping", "cluster": "hetzner-mgmt", "namespace": "gitea", "severity": "warning"},
  "commonAnnotations": {"description": "Pods of gitea keep restarting."},
  "externalURL": "http://alertmanager.monitoring:9093",
  "truncatedAlerts": 0,
  "alerts": [{
    "status": "firing",
    "labels": {"alertname": "KubePodCrashLooping", "cluster": "hetzner-mgmt", "namespace": "gitea",
               "pod": "gitea-a1", "severity": "warning", "incident": "true"},
    "annotations": {"summary": "Pod gitea/gitea-a1 is crash looping"},
    "startsAt": "2026-10-24T08:00:00Z",
    "generatorURL": "http://prometheus:9090/graph?g0.expr=KubePodCrashLooping",
    "fingerprint": "a1"
  }]
}

Its key is (hetzner-mgmt, KubePodCrashLooping, gitea, gitea), the last gitea being the component that falls back to the namespace.

The incident task

Field Value
kind incident. Read-only, like every kind
Project The project linked to the alerts' repository label (commonLabels, else the first alert that has one), else the project linked to Skatzi/platform
Column The project's Backlog
Title Incident: <alertname> in <namespace> on <cluster>, with <component>, in front of the namespace when it differs from it, e.g. Incident: KubePodCrashLooping in gitea on hetzner-mgmt
Description First a line telling the agent to check that the alert still fires before it changes anything; then the key, severity and number of firing alerts, the common summary, description and runbook_url, the Alertmanager link, and up to 20 alerts with their fingerprint, start, labels, runbook and source link
Assignee operator (agent), model large, effort high, required_labels: ["role=ops"] — the same route as risky upgrades (opsRoute in api/internal/task/dependency.go)
Priority High for critical, medium for warning
Gitea issue None
Comments Written by the author alertmanager

The incident object

Every task carries incident, null unless the task is of kind incident and has an own or umbrella row in incidents. It is read from that row and is read-only: PUT /api/tasks/{id} does not change it. A DR run report's incident task has null.

Field Type Meaning
cluster, alertname, namespace, component string The key. All but cluster are empty on an umbrella task
severity string critical or warning; raised to critical by a later critical notification, never lowered
status string firing or resolved, as Alertmanager last said
first_seen, last_seen timestamp The key's first and latest firing notification
fire_count integer How many firing notifications the key has had
alertmanager_url string The notification's externalURL
reopened_at timestamp[] When the incident was reopened
flapping boolean Set by the second reopen within 24 h (Flapping)
umbrella boolean true on the cluster's "Incident storm" task
waits_for_person boolean The task's last finished implementation run offered options in its handoff: it stopped for a person (Waiting for a person)

Rules

Notifications for one cluster are handled one at a time across API replicas, under a session advisory lock on the cluster (LockIncidents).

The diagram shows what a firing notification does with its key.

flowchart TD
    A[Firing notification] --> B{Key has an open task?}
    B -->|yes| C[Refresh: last seen, fire count, comment if alerts changed]
    B -->|no| D{Own task closed under 24 h ago?}
    D -->|yes| R{Same alerts it was closed with?}
    R -->|yes| S[Repeat: last seen, fire count; stays closed]
    R -->|no| E[Reopen; second reopen in 24 h makes it flapping]
    D -->|no| F{5 or more own incidents open on the cluster?}
    F -->|no| G[Create an incident task]
    F -->|yes| H[List the key on the umbrella task]

Firing

  • No open incident for the key: a new task as above, and the key's row with role own. A key whose task closed 24 hours or more ago gets a new task too: its row moves to the new task and its counts, reopen history and flapping start over.
  • Open incident: last_seen, fire_count, status firing and alertmanager_url are updated. A comment ("The alerts in this group changed: N firing now.", with the alert list) is added only when the set of firing fingerprints differs from the last notification's, not on Alertmanager's repeat of the same alerts. A critical notification on a warning incident raises the task's priority to high.
  • Own incident closed under 24 hours ago (ReopenWindow), with alerts that differ from those it was closed with (closedWith): at least one firing alert has a fingerprint the incident did not have at its close, or a startsAt later than the close (it resolved and fired again). The task is reopened (ReopenIncident). It moves from the Done column back to the Backlog, is queued for its agent again, and gets a comment "Reopened: the alert fires again, … after this incident was closed." with the alert list. A critical notification raises its priority to high. A flapping incident, and one that waits for a person, goes to Needs attention instead of the queue.
  • Own incident closed under 24 hours ago, same alerts (repeat): every firing alert was firing at the close and has fired since before it. This is Alertmanager's repeat_interval repeat of an alert that never stopped, for example PodEvicted, which keeps firing for hours after an eviction whose cause is already fixed. Only last_seen, fire_count and alertmanager_url are updated, and the answer is repeat: the task stays done, gets no comment, is not queued, and the notification counts as no reopen toward flapping. The incident keeps the fingerprints it was closed with, so later repeats in the window are repeats too. An incident closed by a resolved notification has no fingerprints left, so any later firing reopens it.

Flapping

The second reopen within 24 hours makes the key flapping:

  • the task is reopened in Needs attention instead of the queue, with reason incident_flapping ("Incident keeps coming back") and the detail "Flapping: the alert reopened this incident N times in 24 h; it is not closed automatically." — see Attention;
  • its reopen comment lists the history: first seen and every reopen;
  • it is never closed automatically again: a resolved notification only comments.

The flag stays on the row until the key gets a new task. Because the task is assigned to operator, it gets no triage task: the item waits for a person.

Waiting for a person

An incident whose last run stopped for a person is not sent back to operator: it waits in Needs attention until a person acts.

  • waits_for_person is true when the task's last finished implementation run (the newest task_runs row with role implementation and an outcome) has a non-empty options array in its handoff (task_runs.digest). Review runs do not count. A later implementation run without options clears it. The value is computed when the task is read; no column or migration was added.
  • Reopen. When the alert reopens such an incident, it moves back to the Backlog but is parked in Needs attention with reason incident_waits_for_person ("Incident waits for a person") instead of being queued. The item's detail is "The last run left this incident to a person and the alert still fires; a further run would stop at the same place.", and it carries that run's options. The reopen comment adds "The last run left this incident to a person, so it waits in Needs attention instead of another run."
  • Flapping wins. A reopen that makes the key flapping parks it as incident_flapping, not incident_waits_for_person.
  • Merge while firing. When a pull request of the incident (for example its report) merges while the incident's status is firing and waits_for_person is true, the task is not completed. It stays open in its column and is parked the same way, with the same reason, detail and options. Any other merge completes the incident as before (Merged pull requests).

The merge check needs both conditions: a run that fixed the incident often has its pull request merged before the alert resolves, and that merge still completes it (PR #579).

Resolved

A resolved notification sets the row's status to resolved and clears its fingerprints, then:

The incident What happens Answer
has no open task (unknown key, or its task is done) Nothing ignored
is a member of an umbrella The umbrella's list shows it resolved storm
is flapping Comment: it stays open for a person to decide kept
had a run since it opened Comment: check that it no longer fires, then close it kept
otherwise Comment "Resolved by itself at …", and the task is closed closed

"A run worked on it" is read as: the task has a run (any row in task_runs) that started at or after the time the incident was created or last reopened (opened_at), whether that run is still going or has finished. A run from before the last reopen does not count.

Storm cap

With 5 (MaxOpenIncidents) or more open own incidents on the cluster, a key that would get a new task gets none:

  • it is listed on the cluster's open umbrella task, titled Incident storm on `<cluster>`, priority high, routed like any incident, in the project the notification's repository label picks (else Skatzi/platform's). The first such key creates the umbrella; its row has role umbrella and a key with only the cluster set;
  • the key's row has role member and points at the umbrella task;
  • the umbrella's description is rewritten whenever a member is added, its alerts change or it resolves: a first line to check which alerts still fire, the open incident tasks of the cluster, and a table of the members with alertname, namespace, component, severity, status, first and last seen;
  • the operator closes the umbrella; it is never closed automatically. Once it is done, a member key that fires again gets its own task, or a new umbrella when the cap is still reached.

Reopening is not capped: an own incident closed under 24 hours ago reopens even during a storm.

Open questions

  • Prod go-live: the endpoint answers 503 until the OpenBao key exists and tasks-prod restarts with it. The person task that stores the token, #1516, was still open on 2026-10-24; which Taskbase release runs in prod was not checked for this page. Task #1516 gives the check once the token is live (not run from this page): a request with a wrong token answers 401, not 503.
curl -s -o /dev/null -w '%{http_code}' -X POST https://taskbase.skatzi.com/api/webhooks/alertmanager \
  -H 'Authorization: Bearer wrong'