Skip to content
Back to skills

Verify Alert Delivery

ASecurity

Model-check the alert notification pipeline (process event, flush group, silences, rule pause, resume and delete) with a TLA+ model and the Rust checker tla-mc. Use when a change touches `packages/app/src/server/alerting/delivery/`, `packages/app/src/data/alerting/rules/lifecycle.server.ts`, `pauseRule`/`resumeRule`/`deleteRule`, silence expiry or release, the transition writes in `evaluation/rule.ts`, or the `alert_events` / `alert_notification_group*` schema, or when you must show that ever...

  • 56 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
developmenttypescriptrustgobashnodegit

Works with

  • terminal
  • cli

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add everr-labs/everr --skill verify-alert-delivery --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Verify Alert Delivery?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Verify Alert Delivery
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/everr-labs-verify-alert-delivery/badge)](https://www.skillsdirectory.com/skills/everr-labs-verify-alert-delivery)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: verify-alert-delivery
description: Model-check the alert notification pipeline (process event, flush group, silences, rule pause, resume and delete) with a TLA+ model and the Rust checker tla-mc. Use when a change touches `packages/app/src/server/alerting/delivery/`, `packages/app/src/data/alerting/rules/lifecycle.server.ts`, `pauseRule`/`resumeRule`/`deleteRule`, silence expiry or release, the transition writes in `evaluation/rule.ts`, or the `alert_events` / `alert_notification_group*` schema, or when you must show that every alert notification still ends in exactly one outcome.
user-invocable: true
metadata:
  internal: true
---

# Verify alert delivery

Tests check the orders someone wrote down. This model checks every order in which the alerting jobs can interleave, for one rule with two instances, one silence and a few ticks of time.

## The promises

Each notifying journal row (`alert_events`, `kind = 'notifying'`: a fire or a resolve) is one notification chain.

| Invariant | Promise | Harm when broken |
|---|---|---|
| `ChainsEnd` | Once no job is left, every chain was delivered or has a terminal (`notification_suppressed`). | A firing alert that never pages and never says why. |
| `OneOutcome` | A chain that went out in a delivery never also gets a terminal. | History says an alert someone was paged for was suppressed. |
| `NeverRepeats` | Every notification carries at least one event no earlier one carried ("never repeats", `docs/alert-notifications.md`). | The same firing alert pages again with nothing new. |
| `ResolveAfterFire` | A resolve is announced only after its fire was. | A "Resolved" page for an alert nobody was paged about. |
| `HeldOnlyWhileSilenced` | Once a silence is canceled, every event it still holds has a release coming. | A canceled silence keeps holding a page until its original end. |
| `OneTerminal` | No chain gets a second terminal decision. The history table (`app.alert_events`) is a plain `MergeTree` and readers do not collapse rows by event id, so a terminal id derived from the event does not merge two writes. | History shows two outcomes for one alert. |

A fire that its own resolve replaced inside one flush counts as ended (the flap path in `groupNotificationPlan`). That is the code's design, not a relaxation.

## Files

```
.agents/skills/verify-alert-delivery/
  model/AlertDelivery.tla    the model; each action names the code it stands for
  model/AlertDelivery.cfg    bounds: Inst {"a","b"}, SIL {"a"}, MaxT 3, W 1, IV 2
  scripts/check.sh           runs tla-mc for both group kinds
  scripts/trace-diff.ts      turns a tla-mc trace into "what changed at each step"
```

Each invariant has a regression test on the real pipeline (pglite + chDB) in `packages/app/src/server/alerting/pipeline-chain-outcomes.integration.test.ts`. Its helpers replay a model trace: `runOnly(task)` runs one task's due jobs and holds the rest back, and `deferHook` runs another job right after a `deferSuppressedEvent` call returns.

## Run

Needs `tla-mc` 0.3.0, the Rust TLA+ checker (not TLC): `cargo install tla-mc --version 0.3.0 --locked`. Node 24 runs the TypeScript helper directly.

```bash
"$(git rev-parse --show-toplevel)/.agents/skills/verify-alert-delivery/scripts/check.sh" /tmp/alert-delivery-check
```

It checks every invariant for both group kinds: `default` (org default destination, survives a rule delete) and `direct` (the rule's own channels, cascaded on delete). Exit 0 means all hold, about five minutes on 8 workers. `tla-mc -compile` builds a native checker per config, cached under `~/.cache/tla-mc`, so the first run is the slowest. A failure leaves `<kind>-<invariant>.trace`, each step listing only the variables that changed.

Read every result, pass or fail, with the pstack `/statechart` skill. It shows each violation as its shortest path in plain words, and charts the states when the check passes.

## Does my change touch this?

Yes if it changes any of these, or what they read or write:

| Code | Model action(s) |
|---|---|
| `server/alerting/delivery/process-event.ts` `processAlertEvent` (and its silence loop), `endChainWithTerminal`, `processedStampGuard`, `claimNotificationGroup` | `ProcessStarts` .. `ProcessDispatches` |
| `server/alerting/delivery/suppression.ts` `eventStillFiring`, `deferSuppressedEvent` (the silence re-check under lock, with and without `groupId`) | `ProcessChecksFiring`, `ProcessDefer*` (`ProcessDeferLifted`), `FlushDefer*` (`FlushDeferLifted`) |
| `server/alerting/delivery/targeting.ts` `dispatchTargetForEvent` | `ProcessFindsTarget` |
| Channel deletes and creates (`alert_channels`, `alert_default_channels`), `directRuleChannels`, the default-tier join in the flush | `UserRemovesChannels`, `UserAddsChannels`, `ProcessFindsTarget`, `FlushReadsChannels` |
| `server/alerting/delivery/flush-group.ts` `flushAlertGroup` (claim tx, firing read, silence loop, channel and journal reads, commit tx, terminals) | `FlushClaims` .. `FlushCommits` |
| `server/alerting/delivery/grouping.ts` `groupNotificationPlan`, `memberVerdict`, `nextGroupFlushState`, `nextGroupFlushAt` | `Plan*`, `IsFlap`, `FlushChecksFiring`, `NextFlushState`, `NextGroupFlushAt` |
| `server/alerting/delivery/journal-reader.ts` `deliverableGroupMemberQuery`, `unannouncedFireEpisodes` | `FlushClaims` (`rows`, `ruleActive`), `FlushReadsChannels` (`unannounced`) |
| `data/alerting/rules/lifecycle.server.ts` `closeRuleLifecycle`, `cancelableNotifyingEventsFilter`, `orphanedDirectChainsFilter`; `rules/repository.ts` `pauseRule`, `resumeRule`, `deleteRule` | `UserPausesRule`, `UserResumesRule`, `UserDeletesRule` |
| `data/alerting/silences/repository.ts` `expireSilence` (cancel and release enqueue), `loadActiveSilences`; deferred `run_at = ends_at` | `UserCancelsSilence`, `SilenceEnds`, `ProcessStarts` gate |
| `server/alerting/evaluation/rule.ts` transition transaction (events + process-event enqueue) | `RuleFires`, `RuleResolves` |
| `data/alerting/delivery/tasks.ts` job keys and `jobKeyMode`; `defaults.ts` `ALERTING_DEFAULT_GROUP_BY` | `q`, `fq`, one group per rule |
| `db/schema/alerts.ts`: `alert_notification_group_events` primary key `(group_id, event_id)`, cascades | `mem` (one row per event), delete cascade |
| `server/alerting/maintenance/cleanup.ts` `cleanupAlertingHistory`, its stale-membership step | `CleanupSweeps` |

Not here: send-delivery (`send-delivery.ts`), retention, ClickHouse writes, evaluation scheduling, the `for` clock. A change only there does not need this check.

## Using it on a change

1. Find the touched code in the table. Mirror the change in the matching action: same reads, same guard, same transaction boundary. One transaction or one statement outside a transaction is one action. Do not merge two into one step or split one.
2. Run `check.sh`. It must exit 0.
3. On a FAIL, read the trace with `/statechart`.
4. Real bug or modeling error? Replay the trace on the real code as a case in `pipeline-chain-outcomes.integration.test.ts`, one step per action. If the real pipeline does it, it is a bug: report it with the steps in the code's words, and keep the case as its regression test once fixed. Do not weaken the invariant or the model to make it pass. If the real pipeline cannot do it, find the action that allows a step the code does not, fix that action, and say what you changed.

## What it has caught

All four broke at `b075a38f5` and were fixed in PR #722. Each regression test asserts the fixed outcome.

| Invariant | The bug | Fix |
|---|---|---|
| `ChainsEnd` | The flush deferred a silenced member, then deleted its membership in a later statement. A silence release between the two re-dispatched the event into the existing row, and the delete left it processed, in no group, never paged. | `deferSuppressedEvent(..., { groupId })` deletes the membership inside its transaction. |
| `NeverRepeats` | When every member left after drops and holds was already flushed, the plan fell back to the firing ones and paged them again. | `groupNotificationPlan` sends nothing unless one listed event is unflushed. |
| `ResolveAfterFire` | A lone resolve was always announced, also when its fire had ended with `no_longer_firing`. | `unannouncedFireEpisodes` feeds `groupNotificationPlan`, which drops such a resolve with a terminal. |
| `OneOutcome` | A flushed fire held by a later silence, or left without channels, got a terminal after its page. | Flushed members are left out of silence deferral and of `noChannelDrops`. |

Review of PR #722 then found three gaps the model did not cover yet. Each was added to the model, failed there on the code before its fix, and passes after:

| Invariant | The bug | Fix |
|---|---|---|
| `ResolveAfterFire`, `OneOutcome` | A fire a flush dropped with `no_channels` stayed in the group as flushed. Once a channel existed again, its resolve paged "Resolved", or a later page listed the fire on top of its terminal. | A `no_channels` drop leaves the group, and a resolve asks the journal whether its fire was delivered even when the fire is in the batch. |
| `HeldOnlyWhileSilenced` | A cancel between the silence read and the defer transaction released nothing, then the defer held the page until the silence's original end. | `deferSuppressedEvent` locks and re-checks the silence first, and returns `"lifted"` when it no longer holds. |
| (no invariant) | A paged fire skipped because of a silence kept its group row after its instance stopped firing, with no flush left to remove it. | The row stays only while the fire still fires with no resolve in the batch. Mirrored in `FlushChecksSilences`. |

A second review round found that a paged fire's row could still outlive its instance in other ways: a resolve that ends at process time (silenced, or no target) never joins the group, and a flush that read the instance as firing writes the row back after the resolve. A scratch invariant ("once idle, a paged fire still in a group is still firing") failed on both. Deleting the row at process time cannot close the second order, so the hourly cleanup removes a paged fire's row once its instance no longer fires (`CleanupSweeps`). The model checks that the sweep, at any point, changes no outcome. It does not check that every row is eventually swept: the sweep removes all of them by construction.

Code review then asked whether one event could get two terminal decisions. `OneTerminal` was added and failed on the direct kind: a rule delete during a flush cascades the group and writes `rule_deleted` for the unflushed members, then the flush's commit finds the group gone but still wrote its own terminals after the transaction. The flush now writes them only when its commit found the group, mirrored in `FlushCommits`. With that fixed, it failed again: a delete after the flush claimed a silenced member leaves the stamp the flush read, so the defer passed its guard and wrote a silenced terminal on top of `rule_deleted`. The defer now writes nothing when its own membership row is already gone, mirrored in `FlushDeferCommits`.

## Scope and assumptions

Verified: every interleaving of the actions above with 2 instances of 1 rule (each fires once and resolves once), 1 silence matching instance `a` (canceled or expired at any point), pause, resume and delete at any point, the group's channels removed and added back at any point, the cleanup sweep at any point, time 0..3 ticks with group wait 1 and group interval 2, `for_secs = 0`, both group kinds. About 124 million distinct states for `default` and 90 million for `direct`.

Assumed or left out:

- No crash between a commit and the next step. Graphile retries and ClickHouse write failures are not modeled. Terminals are recorded with the commit that owes them.
- Two jobs with the same key never run at once (a `replace` while running is modeled as one queued rerun).
- A rule delete is one atomic step. In the code, `closeRuleLifecycle` reads the orphaned memberships before its cascade waits on the flush's group lock, so a flush that commits in that gap can deliver a member the delete also gives `rule_deleted` (a delivery and a terminal on one chain). A flush defer in that gap does the same: it holds the member, and the re-dispatch after the silence ends writes `no_longer_firing` on top of `rule_deleted`. Known, older than PR #722, not fixed; locking the rule's direct groups before that read would close it.
- One silence, created once. A cancel's release job and the stale deferred job re-run the same decision, so one per-event flag (`released`) stands for both.
- An instance fires at most once (no second episode after a resume or a resolve). So a held fire superseded by a later fire of the same instance under one silence is out; today it ends with no outcome of its own. `pending` (`for_secs > 0`) and muted (`suppressed`) chains are out.
- One group per rule. A rule edit can put a fire and its resolve in two groups (severity, direct or default tier), whose flushes may overlap, so the journal read in one can go stale.
- A membership row left behind breaks no invariant here. Rows are checked only through the chains they end, and the cleanup sweep removes a paged fire's row by construction.
- The silence's matchers select instances, so it treats a fire and its resolve alike. A silence that matches only one of them (a `status` matcher) is out; the flush judges a fire again when a silence took only its resolve, and `pipeline-chain-outcomes.integration.test.ts` covers it.
- The journal read's lower bound (`occurred_at` from the episode id, minus an hour of clock slack) is not modeled: the model has no clocks.
- The member claim cap (`FLUSH_GROUP_MEMBER_CLAIM_CAP`) is not modeled: every flush claims all members.
- `send-delivery.ts` is out: "delivered" means linked to an `alert_deliveries` row, including one later withheld at send time.
- Journal retention is out: a fire is "unannounced" only while its row exists, as in `unannouncedFireEpisodes`.
- Channels are one switch for the group: the default kind has one tier, and a channel deleted between the flush and the send is out (send-delivery withholds it).
- `ChainsEnd` is checked only in reachable states where no job is queued or running. A pass does not prove that the queue drains: a flush booked after `MaxT` (for a fire dispatched at the last tick) never runs, and its chain is not checked.
- A pass covers these bounds, not every size.

## Sync record

Verified against commit `b8358efadf06b14ef4b73d9aad6bbf8c12d539bd` (2026-11-30): every action re-read against the code in the table, `check.sh` passed for both kinds, and `pipeline-chain-outcomes.integration.test.ts` passed. Before the fixes, each invariant failed on its own counterexample, and each counterexample reproduced on the real pipeline. A scratch removal of `isNull(alertEvents.processedAt)` from `processedStampGuard`, mirrored in the model, broke `OneOutcome`.

To see what changed since: `git diff b8358efadf06b14ef4b73d9aad6bbf8c12d539bd -- <paths from the table>`. Move this commit forward only after you have re-read each touched action against the code at the new commit and `check.sh` passes. If you only ran the check, the record stays where it is.

Files in this skill

  • SKILL.md14.9 KB
  • model/AlertDelivery.cfg306 B
  • model/AlertDelivery.tla29 KB
  • scripts/check.sh1.8 KB
  • scripts/trace-diff.ts2.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.