Files
hapi/docs/adr/0013-ntfy-notifications.md
2026-11-27 15:19:32 -05:00

4.4 KiB
Raw Permalink Blame History

Notifications are durable records delivered by one CronJob; platform alerts bypass hAPI

hAPI's Notifications are database records addressed to one Person or to the Household, written by hapi notify <check> CronJobs (ADR-0012) and published to ntfy at notify.bobbypalko.com by a single hapi notify deliver CronJob. Platform alerts are a separate lane: CI, Flux, vmalert and Kuma publish straight to Owner-only ntfy topics with their own credentials and never touch hAPI, because they must work when hAPI or its database is down. ntfy is the only channel in v1: no preferences, no read state, no Notifications API; a Person opts out by muting in the ntfy app.

Considered Options

  • Routing platform alerts through hAPI (one Notification model for everything). Rejected: an alert that hAPI is down can't depend on hAPI.
  • Each check delivering what it wrote, or every check draining all pending Notifications. Rejected: a budget run sending Token reminders is surprising, and an ntfy outage would fail every check. One deliver job keeps checks pure writers and isolates ntfy failures to one CronJob.
  • Checks over Personal domain data (e.g. a Person's Budget). Deferred to v2 with the Personal importer: they'd need scheduled writes for a Person, which ADR-0012 forbids.
  • Per-Person preferences and a frontend inbox. Deferred: the records already support an inbox and read state later.

Consequences

  • ntfy access: the server denies anonymous read and publish. The Owner manages users by hand from a runbook in docs/ (also an off-boarding step alongside Token revocation): a read-only user per Person for hapi-p-<person-id> and hapi-household; the Owner's user also reads ops and ops-urgent; each sender (hAPI, vmalert, Flux, CI, Kuma) has its own publish-only user limited to its topics. hAPI's, vmalert's and Flux's tokens come through SOPS (ADR-0008), CI's is a Gitea secret, Kuma's lives in Kuma. Topics are named by id, never by name. upstream-base-url points at ntfy.sh for iOS (only a poll request leaves, never content), the cache stays at 12 h, attachments are off.

  • Content: a short title and a link to the resource. Never amounts, balances, Measurements or other domain values.

  • v1 checks (all run as the scheduler Bot, read only Household and platform data):

    Check Recipient Fires Schedule
    tasks Household once on entering lead_days, once on overdue, per due occurrence (a Service or snooze starts the next) daily 08:00
    jobs Household a Job ends failed or expired every 15 min
    budget Household a Household Budget Category goes into the red this month (Banked: its banked balance goes negative); refires only after it recovers hourly
    tokens the Token's Person, or the Owner for Bot Tokens 30 and 7 days before expiry daily
  • Record: recipient (Person or Household), kind, dedupe_key (unique with kind; it is the "already notified" ledger), title, body, priority 1–5, optional link, created_at, delivered_at, attempts. hapi jobs sweep deletes delivered Notifications after 180 days.

  • Delivery: hapi notify deliver every 2 min publishes pending Notifications oldest first, using the Notification id as ntfy's message/sequence id so retries don't double-push. It gives up after 24 h; a vmalert rule fires on undelivered Notifications that old. It counts as one more pool-1 CronJob in ADR-0012's connection rule.

  • Breakglass fails closed: hapi db breakglass publishes a priority-5 Household alert synchronously (and records a Notification) before opening the session, and refuses to start if the publish fails. Bypassing the wrapper with raw credentials remains the residual risk ADR-0009 accepts.

  • Platform topics and priorities: ops (Flux, vmalert, CI) and ops-urgent (Kuma down, the Watchdog). Priority 5: Kuma down, breakglass. 4: vmalert critical, Flux reconcile/rollout failure, Task overdue. 3: CI failure, Kuma degraded, Job failed/expired, Token expiring in 7 days. 2: Task due soon, budget overspend, Token expiring in 30 days.

  • Importer staleness needs no hAPI check: the SimpleFIN Bot already fails on a non-empty errors array and Kuma's 13 h push monitor catches it (ADR-0011).

  • Egress to notify.bobbypalko.com:443 is needed from hAPI's CronJobs and Flux's notification-controller (vmalert's is already allowed by ADR-0009); the policies themselves belong to cluster hardening.