Design draft: alerts, connectors and fleet traffic
One alert engine in the console with Slack, email, SMS and signed webhook connectors for operators, accounts and apps; a disk-full forecast; a /fleet/traffic page (layout A). Paul's rulings from the 2026-10-30 conversation are in section 2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+483
−0
docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md+483 −0
CI passed — run details
Intent
Attributed to this commit: 30.1 g CO₂e (2,900,497 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-alerts, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md b/docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md| new file mode 100644 |
| index 000000000..7c2ce757c |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md |
| @@ -0,0 +1,483 @@ |
| +# Alerts, connectors and fleet traffic |
| + |
| +Status: draft for Paul, 2026-10-30. Branch `design-fleet-alerts`. |
| + |
| +One alert engine, with connectors (Slack, email, SMS, signed webhook), |
| +serving three audiences: fleet operators, account owners and app owners. |
| +Plus a `/fleet/traffic` page showing all traffic across every edge, |
| +healthy and malicious. Planned in three parts (§11). |
| + |
| +Words used here: **operator** means a platform operator (the |
| +`users.operator` bit, the `/fleet` pages). **Managed fleet** means a |
| +customer's own boxes (`fleets/<name>/`), which this design does not |
| +cover in v1 (§3). |
| + |
| +## 1. Why |
| + |
| +Paul, 2026-10-30: "I would have liked to have got a notification before |
| +it happened so that I could mitigate before anything died (eg a disk |
| +running out of space)." |
| + |
| +The disk has filled twice on flagship (2026-09-06 and 2026-10-01), and |
| +both times someone found it by hand. Today: |
| + |
| +- Box rules (disk 90%, memory, CPU, GeoIP; `internal/metrics/alert.go`) |
| + fire at a fixed threshold, too late to act. Nothing forecasts. The |
| + daily metric rollups are kept forever, and nothing reads them. |
| +- Delivery is in pieces. Boxes page a webhook or SNS topic |
| + (`internal/alerting`). The console's alert watcher |
| + (`internal/console/alertwatch.go`) sends Keymail to operators only. |
| + The console's `deliver()` (`internal/console/delivery.go:41`) sends |
| + real email (Keymail first, SES fallback) for invites and plan-cap |
| + notices. There's no chat, no SMS, and no per-person routing. |
| +- End users get one early warning: plan caps notify the owner at 80% |
| + (`internal/console/plangrace.go`, `plangracepass.go`). Nothing tells |
| + them their app is down, failing or overloaded. |
| +- Traffic is counted per app. Request summaries (2xx/3xx/4xx/404/5xx, |
| + protection block/watch, wakes) go into each app's log stream |
| + (`internal/reqrec`). Rate-limit refusals go into the daily usage files |
| + (`internal/usage/edge.go` `EdgeRow`). Nothing adds these up across the |
| + fleet. Unknown-host requests aren't counted |
| + (`internal/edge/edge.go` `unknownHost`). The `/fleet` pages have no |
| + traffic view. |
| + |
| +## 2. What Paul decided (2026-10-30, in conversation) |
| + |
| +1. **Warn before it breaks.** The point is time to act, not news of a |
| + failure. Disk filling is the reference case. |
| +2. **Chat first, Slack first.** Paul would take warnings in Slack. |
| +3. **Same alert at 3am as at noon** by default. Quiet hours or |
| + escalation are an option for those who want it, never the default. |
| +4. **One engine, three levels:** fleet operators, accounts, apps. |
| +5. **End users get ready-made alerts** they switch on and point at a |
| + connector, not a rule builder. The ones named: the app slowed down, |
| + the app is too busy, the app has fatal errors. "The app is down" was |
| + added in conversation and accepted. |
| +6. **Fleet traffic page uses layout A:** four answer tiles first |
| + (healthy, abuse, load, capacity), then a fleet-wide requests chart, |
| + then busiest apps and bad traffic. Paul's purpose: "make sure that |
| + everything is OK, that nobody is abusing the system, that I'm not |
| + overloaded, that everything is running within capacity." |
| +7. **Anti-goal: noise.** Paul would mute alerts that are "just repeated |
| + noise of things that weren't actually of any concern." |
| +8. **Order:** engine and connectors for operators, then the traffic |
| + page, then account and app alerts. |
| + |
| +Everything else in this document is the author's call and is marked |
| +where it matters. |
| + |
| +## 3. Goals, non-goals, anti-goals |
| + |
| +### Goals |
| + |
| +- An operator gets a Slack message days before a disk fills, with the |
| + box, how long is left, and what to do. |
| +- Operators manage connectors and fleet rules from `/fleet/alerts`. |
| + Nothing needs `host.env` edits. |
| +- `/fleet/traffic` answers the four questions at a glance and agrees |
| + with the alerts. |
| +- An account owner can switch on "app is down", "errors", "too busy" |
| + and "slow" for any app and send them to Slack, email, SMS or a |
| + webhook. |
| +- Plan-cap notices move onto the same engine, so owners can route them |
| + to Slack as well. |
| + |
| +### Non-goals (v1) |
| + |
| +- A general rule builder with custom metrics and expressions. Operators |
| + can tune thresholds on built-in rules. End users can't. |
| +- On-call rotations, acknowledgement and escalation chains (PagerDuty |
| + territory). A generic webhook can feed PagerDuty or Opsgenie. |
| +- Managed-fleet owners alerting on their own boxes. The data model must |
| + not rule it out (§5.1 scope), but v1 doesn't build it. |
| +- Log-based alerts ("tell me when my logs say X"). |
| +- Replacing the box-side sinks and the CloudWatch memory alarm. They |
| + stay as the backstop for when the console itself is down (§8). |
| + |
| +### Anti-goals |
| + |
| +- **Noise.** An alert nobody acts on is a bug. §6 is binding, not |
| + advice. |
| +- **Contradiction.** The traffic tiles and the alerts must read the same |
| + state. A tile saying OK while Slack says disk is filling is a failure. |
| +- **A spam relay.** End-user connectors must not let anyone use CARLOS |
| + to send email or SMS to people who didn't agree, or POST to internal |
| + addresses (§5.3). |
| +- **A new S3 polling cost.** See §9. |
| + |
| +## 4. The pieces |
| + |
| +``` |
| + boxes ──heartbeat (5 min, private block)──┐ |
| + ──alerts/boxes/<box>.json (on change)┤ |
| + ▼ |
| + console: alert engine (one pass, claim worker) |
| + │ rule state in console.db |
| + │ traffic series in console.db |
| + ▼ |
| + notifier ──> connectors: Slack · email · SMS · webhook |
| + │ |
| + /fleet/alerts /fleet/traffic account + app Alerts tabs |
| +``` |
| + |
| +- **Signals** are produced where the data already lives. Box-level and |
| + per-app conditions are evaluated on the box that sees them. The box |
| + reports them in files the console already reads (§7). |
| +- **The engine** runs in the console as one claim worker, replacing |
| + today's alert watcher. It merges signals from every box into |
| + *incidents*, decides who is told, and records history. |
| +- **The notifier** delivers each message through the subscriber's |
| + connectors, with retries. |
| + |
| +## 5. Connectors and subscriptions |
| + |
| +### 5.1 Connector |
| + |
| +A connector is a named destination owned by a *scope*: |
| + |
| +- `fleet`: operators only |
| +- `account:<sqid>` |
| + |
| +App-level alerts use the app's account's connectors. My call: one Slack |
| +channel per account is the common case, and per-app connectors would |
| +multiply setup. |
| + |
| +| Kind | Setup | Verification before first use | |
| +|---|---|---| |
| +| Slack | paste an incoming-webhook URL | a test message is sent, and the person confirms they saw it | |
| +| Email | an address | a confirm link is sent to the address, and nothing else goes there until it's clicked | |
| +| SMS | a phone number | a six-digit code is sent, and the person types it back | |
| +| Webhook | an https URL | a signed test POST that must answer 2xx | |
| + |
| +- **Slack v1 is the incoming-webhook URL.** A Slack app with sign-in is |
| + later, if wanted. Only `https://hooks.slack.com/` URLs are accepted. |
| + The message uses Slack's `blocks` format with a plain `text` fallback. |
| +- **Webhook** payloads are JSON, signed with the console's Ed25519 key |
| + in the `Carlos-Signature` header, in the same scheme as `mailpush.go` |
| + so receivers verify both alike. The body is versioned (`"v":1`). |
| + This is how PagerDuty, Discord (via its Slack-compatible path), |
| + Teams relays and home-made bots connect. |
| +- **Email** goes through `deliver()`, so Keymail first and SES fallback. |
| + Every message carries an unsubscribe link that disables that |
| + connector. |
| +- **SMS** goes through a provider adapter. The AWS adapter is SNS SMS. |
| + SMS text is at most 160 characters: subject, scope, a short link. |
| + |
| +Connector secrets (Slack URLs, webhook URLs) are sealed at rest and |
| +never shown again after saving. The page shows the host and the last |
| +four characters. The builder picks the sealing mechanism the console |
| +already uses for app secrets. |
| + |
| +### 5.2 Subscription |
| + |
| +A subscription is (scope, alert, connectors, options): |
| + |
| +- **Fleet:** each built-in fleet rule (§7.1) has a list of connectors |
| + and a threshold the operator can change. |
| +- **Account:** "plan caps" and the account-wide defaults for app alerts. |
| +- **App:** each ready-made app alert (§7.3) is on or off, and uses the |
| + account's connectors unless it lists its own subset. |
| +- **Options** on any subscription: |
| + - quiet hours, with a time zone and window, where only `incident` |
| + level breaks through |
| + - "also send to" a second connector after N minutes still firing |
| + |
| + Both are off by default (ruling 3). |
| + |
| +Who can change what (my call): |
| + |
| +- operators: fleet |
| +- account owners: account and app |
| +- members: can see the Alerts tabs and history, and can add an email |
| + connector for themselves only |
| + |
| +### 5.3 Abuse guards (binding) |
| + |
| +- **Email and SMS:** confirmed opt-in only, as in §5.1. Unconfirmed |
| + connectors receive nothing beyond the confirmation itself. |
| + Confirmations are rate limited: 5 per account per hour and 20 per |
| + day, the same shape as `emailsignin_limits.go`. |
| +- **SMS cost cap:** my call is SMS for end users only on paid plans, at |
| + most 100 messages per account per month. Past the cap, messages fall |
| + back to the account's other connectors and the owner is told once. |
| + Operators are uncapped. |
| +- **Webhook and Slack URLs:** |
| + - must be https on port 443 |
| + - the resolved address is checked at send time against loopback, |
| + private, link-local, CGNAT (Tailscale's 100.64/10), metadata and |
| + the fleet's own box addresses |
| + - redirects are not followed |
| + - the response body is never read beyond 1 KiB |
| + - a 5-second timeout |
| + |
| + mailpush only ever POSTs to platform hosts, so this guard is new |
| + code. It needs its own tests. |
| +- **Failing connectors:** a connector that fails for 24 hours is |
| + suspended and the account owner is emailed once, as mailpush does. |
| + |
| +## 6. Noise rules (binding) |
| + |
| +1. **One message on fire, one on clear.** Nothing repeats while the |
| + condition holds. An incident still open after 24 hours gets one |
| + daily reminder, at most. |
| +2. **Group.** One rule firing on several boxes, or several apps of one |
| + account, within 5 minutes is one message listing them. A new member |
| + joining an open incident updates the group, with no new message, |
| + until the group is 30 minutes old. After that it sends at most one |
| + "now also" message per hour. |
| +3. **Hold before firing.** Each rule states a sustain window. A |
| + forecast fires only when the trend has held for its window (§7.2), so |
| + a burst of writes never says "full in 2 hours". |
| +4. **Hysteresis.** Each rule clears at a gentler level than it fires |
| + (today's box rules clear 5 points below; keep that). |
| +5. **Every message says three things:** what is wrong, how long you |
| + have, what to do. It links to the incident page and to a snooze |
| + (1 hour, 1 day, 1 week, scoped to that rule on that box or app). |
| +6. **Defaults rarely fire.** Ready-made thresholds start conservative |
| + (§7.3). Each rule shows how many times it fired in the last 30 days |
| + and how often it cleared within 10 minutes, so a noisy rule is easy |
| + to spot. |
| +7. **No flapping.** A rule that fires and clears 3 times in an hour |
| + becomes one open incident marked "flapping" until it has been clear |
| + for an hour. |
| + |
| +## 7. Signals |
| + |
| +### 7.1 Fleet rules (operators) |
| + |
| +| Rule | Where evaluated | Level | Default | |
| +|---|---|---|---| |
| +| Disk full forecast | box | warning | full within 72 h, trend held 2 h | |
| +| Disk full now | box | incident | 90% (exists) | |
| +| Memory, CPU | box | warning | exist today, unchanged | |
| +| GeoIP database | box | warning | exists | |
| +| Box silent | console | incident | no heartbeat for 15 min | |
| +| Service down | console | incident | from the heartbeat's probe health | |
| +| Region has no room | console | incident | exists (`nocapacity.go`), moves onto the engine | |
| +| Certificate expiring | console | warning | any served host whose cert expires within 14 days (`CertExpiresAt`) | |
| +| Fleet 5xx rate | console | warning | above 1% for 15 min, at least 500 requests | |
| +| Abuse surge | console | warning | blocked + watched above 5x the 7-day same-hour median, at least 1,000 requests | |
| +| Alert delivery broken | console | warning | a box reports `alerts=not-delivered` | |
| + |
| +The **disk forecast** is computed on the box from its own samples: |
| +- a least-squares line over the last 6 hours of disk-used bytes, |
| + refitted each minute |
| +- it fires when the projected time to 100% is under the threshold |
| + and has stayed under it for the hold window |
| +- it clears when the projection passes 1.5x the threshold |
| +- the box reports `disk_full_eta` in its heartbeat as well |
| + |
| +Other forecasts (memory creep, a region filling) are left for later. |
| +The same fitting function should be reusable. |
| + |
| +The existing console pages that call `alerting.Page` (moves recovery, |
| +egress conflict, lifetimes, claim loss) become engine rules too. They |
| +keep their current SNS/webhook path as well, as the backstop (§8). |
| + |
| +### 7.2 Where box signals travel |
| + |
| +No new objects: |
| + |
| +- Box rule state keeps going to `alerts/boxes/<box>.json`, written only |
| + on change. The forecast rule is added there. |
| +- Per-app conditions evaluated at the edge (§7.3) are added to the same |
| + file as a bounded list (at most 200 app entries per box, firing ones |
| + only). |
| +- Traffic counters ride the 5-minute status heartbeat's private |
| + `Metrics` block (§10.1). |
| + |
| +### 7.3 Ready-made app alerts (end users) |
| + |
| +Each app alert is evaluated on every edge for every app, in memory, |
| +from counters the edge already keeps. The box reports only firing |
| +entries. The console decides who hears about it. My call: this keeps |
| +subscription state off the boxes entirely. |
| + |
| +| Alert | Condition (default) | Data | |
| +|---|---|---| |
| +| App is down | at least 5 requests in 5 min and every one failed (502/503/504, or a wake that failed), or the upstream probe failing for 5 min | reqrec counters, wake results, probe health | |
| +| Errors | 5xx above 5% of at least 50 requests over 10 min | reqrec counters | |
| +| Too busy | rate-limit shed + ceiling above 2% of requests for 10 min, or memory above 90% of the app's limit for 10 min | `EdgeRow.RateShed`/`RateCeiling` counters, unit memory samples | |
| +| Slow | p95 response time above 3 s over at least 50 requests for 10 min | **new**: edge timing (§10.2) | |
| +| Plan caps | as today, 80% and grace notices | `plangrace.go`, re-routed | |
| + |
| +- Hibernating apps are not "down". |
| +- A wake that succeeds is not an error. |
| +- An app with no requests raises nothing. |
| + |
| +Owners can switch each one on or off but not change thresholds in v1. |
| +New apps start with "down" and "errors" on, sending email to the |
| +owner. Existing apps start with everything off. My call: this matches |
| +how the analytics on-ramp treated existing accounts. |
| + |
| +## 8. When the console is the thing that broke |
| + |
| +The engine lives in the console, so a dead console box means silence. |
| +The existing paths stay on as the backstop and are not part of this |
| +design: |
| + |
| +- each box's `CARLOS_ALERT_WEBHOOK` / `CARLOS_ALERT_SNS_TOPIC_ARN` |
| +- the per-host CloudWatch memory alarm to SNS email |
| + |
| +The plan adds one rule: on the box that runs the console, the agent |
| +pages its own sinks if the console's engine has not written its |
| +heartbeat for 10 minutes. Flagship needs `CARLOS_ALERT_WEBHOOK` set to |
| +a Slack URL for that to reach anyone. That's a one-line `host.env` |
| +change per box, listed in the roll notes. |
| + |
| +## 9. Request budget |
| + |
| +Steady state, nothing changing, with N boxes: |
| + |
| +- **Box writes:** no new objects. The heartbeat grows by about 2 KB. |
| + `alerts/boxes/<box>.json` is written on change only, as today. |
| +- **Console reads:** |
| + - The engine replaces the alert watcher's every-minute read of |
| + `alerts/boxes/` (1 LIST + N GETs a minute today). It reads those |
| + files every minute with conditional GETs (`If-None-Match`), so |
| + unchanged files cost a 304. That's the same request count as today. |
| + - Heartbeats are already read by `status.LoadBoxes`. The engine reads |
| + them every 5 minutes on its own pass, with conditional GETs: about |
| + 288 x N GETs a day, roughly 2,900 a day for 10 boxes. |
| +- **Traffic page:** reads console.db only, so no store requests. |
| +- **Delivery:** no store requests. |
| + |
| +The plan includes a test that counts store calls for one engine pass |
| +with nothing changed. |
| + |
| +## 10. Fleet traffic (`/fleet/traffic`, layout A) |
| + |
| +### 10.1 Data |
| + |
| +Each edge keeps 5-minute fleet counters in memory and puts the last |
| +completed window in the heartbeat's private block: |
| + |
| +- requests by class: 2xx, 3xx, 4xx, 404, 5xx |
| +- protection: blocked, watched |
| +- rate-limit shed and ceiling, plan-throttled |
| +- unknown host: newly counted at `unknownHost` |
| +- top 10 apps by requests: (account, app, requests, 5xx) |
| +- top 10 bad paths: the masked path from reqrec, with hits |
| +- top 10 blocked or watched sources: client hash and country, with hits |
| +- top 10 unknown hostnames, cut to 253 characters and treated as hostile |
| + text everywhere they're shown |
| + |
| +The console's engine pass writes these into a console.db series: |
| +- 5-minute rows kept for 7 days |
| +- hourly rollups kept for 90 days |
| + |
| +History starts when the feature is first rolled. There's no backfill. |
| + |
| +**A missed window** (a heartbeat the console didn't read in time) is a |
| +gap in the chart. It is not shown as zero, and it is not estimated. |
| + |
| +### 10.2 Slow needs timing |
| + |
| +The edge starts timing each proxied request, from when the request is |
| +accepted to the first response byte. It keeps a small per-app histogram |
| +per 5-minute window (fixed buckets, so it merges across boxes). This |
| +feeds "Slow" (§7.3) and a p95 line on the traffic page. It ships with |
| +part 3. |
| + |
| +### 10.3 The page |
| + |
| +From the approved mockup (layout A): |
| + |
| +- **Four tiles:** Healthy, Abuse, Load, Capacity. Each tile is OK or |
| + Watch with one line of evidence. A tile is Watch exactly when one of |
| + its rules (§7.1) has an open incident, and it links to that incident. |
| + This keeps the page and the alerts from disagreeing. |
| + |
| + | Tile | Rules | |
| + |---|---| |
| + | Healthy | fleet 5xx rate, service down, box silent | |
| + | Abuse | abuse surge | |
| + | Load | CPU, memory | |
| + | Capacity | disk forecast, disk full, region has no room, certificate expiring | |
| + |
| +- **Chart:** requests per hour across every edge, stacked as served, |
| + 4xx, 5xx, and blocked or refused. The range is 24 h by default, with |
| + 7 d and 30 d available. A region filter is my call. |
| +- **Busiest apps:** requests and 5xx. Each row links to the app's |
| + operator view. |
| +- **Bad traffic:** |
| + - top probe paths |
| + - top blocked sources |
| + - unknown hostnames |
| + - rate-limit refusals by app |
| + |
| + Each links to detail. |
| +- Added to `opRail` between Dashboard and People. |
| +- The `/fleet` dashboard's needs-attention list reads open incidents |
| + from the engine. |
| + |
| +## 11. Plans |
| + |
| +Rule 6 (something Paul can see lands first) shapes the order. |
| + |
| +1. **Engine, connectors and fleet rules.** Engine and history tables, |
| + notifier, the Slack and webhook connectors (with §5.3 guards), email |
| + through `deliver()`, the disk forecast on the box, every §7.1 rule, |
| + and the `/fleet/alerts` page (Connectors, Rules, History). The alert |
| + watcher retires. |
| + - **First merge Paul can see:** a Slack message to the operators' |
| + channel for a forecast disk on dev. |
| + - **SMS adapter:** in this plan, for operators. |
| + - **Switch-on:** at its release. |
| +2. **Fleet traffic.** Edge fleet counters, unknown-host counting, |
| + heartbeat fields, console.db series, the `/fleet/traffic` page. |
| + - **Switch-on:** at its release. |
| +3. **Account and app alerts.** Edge per-app conditions, edge timing, |
| + the account and app Alerts tabs, member self-serve email, SMS for |
| + paid plans, and plan caps re-routed. |
| + - **Switch-on:** at its release. New apps get the defaults from |
| + §7.3. |
| + |
| +User-facing copy (pages, messages, email, SMS) goes through copy review |
| +in each plan. |
| + |
| +## 12. Provider boundary |
| + |
| +| Piece | AWS? | |
| +|---|---| |
| +| Engine | core | |
| +| Slack connector | core | |
| +| Webhook connector | core | |
| +| Email connector | core through Keymail; the SES fallback is an AWS adapter | |
| +| SMS connector | the AWS adapter is SNS SMS; an interface allows Twilio and others later | |
| +| Traffic page and counters | core | |
| +| CloudWatch memory alarm and SNS backstop | AWS adapter, unchanged | |
| + |
| +A deployment without AWS loses SMS and the SES email fallback, and |
| +keeps Slack, webhook and Keymail email. Core packages don't import the |
| +AWS SDK. |
| + |
| +## 13. Testing |
| + |
| +- **Engine:** a table-driven simulation over a timeline of signals |
| + checks each §6 rule: |
| + - one fire and one clear |
| + - grouping |
| + - flapping |
| + - daily reminder |
| + - quiet hours with incident-only breakthrough |
| +- **Disk forecast:** |
| + - a steady fill fires once |
| + - a burst then flat does not fire |
| + - a deletion clears it |
| +- **URL guard:** every refused address class, a DNS answer that changes |
| + between check and connect (dial to the checked IP), and a redirect. |
| +- **Opt-in:** an unconfirmed email or SMS connector receives nothing. |
| +- **Request budget:** a store-call count for an idle engine pass. |
| +- **Tiles:** the tile state is the incident state (one source). |
| + |
| +## 14. Left to the builder |
| + |
| +- Table shapes, names, and the incident ID format. |
| +- The Slack block layout, within copy review. |
| +- The sealing mechanism for connector secrets, reusing an existing one. |
| +- Histogram bucket boundaries for timing. |
| +- Whether the engine's heartbeat reads share `status.LoadBoxes`' cache. |
| +- The SMS sender ID and origination setup on AWS. This needs scoped |
| + approval under the production infrastructure rule before it's |
| + created. |