From debdeb6754a465c8141892161905209e9b00d7c8 Mon Sep 17 00:00:00 2001 From: Bobby Date: Fri, 27 Nov 2026 15:19:32 -0500 Subject: [PATCH] new: notifications through ntfy (ADR-0013) Co-Authored-By: Claude Opus 5.5 --- GLOSSARY.md | 2 +- docs/adr/0007-flux-pull-delivery.md | 2 +- docs/adr/0012-housekeeping-cronjobs.md | 2 +- docs/adr/0013-ntfy-notifications.md | 30 ++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 docs/adr/0013-ntfy-notifications.md diff --git a/GLOSSARY.md b/GLOSSARY.md index 15f3acc..0d0571e 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -63,7 +63,7 @@ _Avoid_: Author, owner, creator ### Notifications **Notification**: -A message hAPI keeps for a Person or the Household about something that needs their attention, delivered through one or more channels such as ntfy. +A message hAPI keeps for one Person or for the Household about something that needs their attention, delivered through one or more channels such as ntfy. A Notification to a Person is seen only by that Person; one to the Household by every Household member. Platform alerts to the Owner (from CI, delivery, or monitoring) are not Notifications. _Avoid_: Alert, event, message ### Smart home diff --git a/docs/adr/0007-flux-pull-delivery.md b/docs/adr/0007-flux-pull-delivery.md index 506f92f..a0790df 100644 --- a/docs/adr/0007-flux-pull-delivery.md +++ b/docs/adr/0007-flux-pull-delivery.md @@ -20,5 +20,5 @@ Every green merge to protected `main` reaches production, with no release tags a - **The CI write credential is a deploy key with write access**, stored as an Actions secret and allowlisted past `main`'s branch protection. The build workflow's path filter skips bump commits, so a bump doesn't trigger another build. - **Renovate runs nightly** on the same runner as its own bot user. It auto-merges only dev-only tooling. Anything that ships (runtime dependencies, base image, charts, Flux, Talos, OpenTofu providers) arrives as a PR the Owner merges. - **Not delivered through Flux:** the runner VM, Cilium, and the Linode CCM live in OpenTofu under `infra/`, and the Owner runs `tofu apply` over the tailnet. Talos and Kubernetes upgrades are a manual `talosctl` runbook. CI never holds the Tofu state key. -- **Failures notify through ntfy:** a final `if: failure()` step in each workflow, and Flux's notification-controller for failed reconciles and rollouts. Topics and auth are designed with notifications. +- **Failures notify through ntfy:** a final `if: failure()` step in each workflow, and Flux's notification-controller for failed reconciles and rollouts. Topics and auth: ADR-0013 (`ops` topic, each sender its own publish-only ntfy user). - **Deferred:** having Flux verify commit signatures, and signing images (cosign) with admission-time verification. Both guard against a compromised Gitea and belong together in cluster hardening. diff --git a/docs/adr/0012-housekeeping-cronjobs.md b/docs/adr/0012-housekeeping-cronjobs.md index d3e8614..29454d5 100644 --- a/docs/adr/0012-housekeeping-cronjobs.md +++ b/docs/adr/0012-housekeeping-cronjobs.md @@ -13,7 +13,7 @@ hAPI's recurring work is a small set of **Kubernetes CronJobs that run `hapi `; what they check is decided with ntfy delivery. Purging a removed Person's data stays an on-demand Owner CLI command, and Finance month rollover, Banked carry-forward and `date_review` need no schedule. +- **v1 inventory:** `hapi jobs sweep` every 15 min marks pending Jobs past `expires_at` as `expired` and deletes finished Jobs older than 90 days (replacing ADR-0006's `hapi jobs purge`). Reads derive `expired` from `expires_at` until the sweep catches up, so correctness never depends on how often it runs. The notification checks are CronJobs running `hapi notify ` (`tasks`, `jobs`, `budget`, `tokens`), plus `hapi notify deliver` every 2 min, which alone publishes to ntfy (ADR-0013). Purging a removed Person's data stays an on-demand Owner CLI command, and Finance month rollover, Banked carry-forward and `date_review` need no schedule. - **Principal:** work on Household data runs as a built-in **`scheduler` Bot**. A migration creates it, it can never hold a Token (so it can't be reached from the API), and the Owner gives it Household grants like any other Bot. Recorded by shows `scheduler`. Work on Personal data runs once per Person with `hapi.principal_id` set to that Person (ADR-0004), and is **read-only**: a scheduled write to Personal data needs a new decision. - **Event-triggered work** (e.g. a new Reading making a Task due) is picked up by the next scheduled check. Checks write **durable Notifications**, which double as the record of what was already notified. A Notification not yet delivered stays pending and is retried on the next run, so an ntfy outage loses nothing, and a future frontend inbox reads the same records. - **Connection budget (amends ADR-0004):** each housekeeping CronJob uses a pool of 1 with no overflow and `concurrencyPolicy: Forbid`. The rule becomes: app pods including surge × 10 + concurrently runnable CronJobs × 1 + ~6 ≤ 46. diff --git a/docs/adr/0013-ntfy-notifications.md b/docs/adr/0013-ntfy-notifications.md new file mode 100644 index 0000000..64ca6c8 --- /dev/null +++ b/docs/adr/0013-ntfy-notifications.md @@ -0,0 +1,30 @@ +# 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 ` 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-` 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.