carlos / platform Public

Design: apply builder-check answers

Fleet-wide app thresholds from per-app counters; observe-mode refusals
excluded; separate alert signing key; one-off events self-close;
seeded operator email connectors; box sinks narrowed to incidents;
Slack payload shape for the backstop; 3-window heartbeat counters;
Plan 2 owns fleet 5xx and abuse surge; corrected code claims.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 9a99f7867af20e113965ea3c576e3cb76473309d parent 202ca6a
1 file changed, +130 −41
  • docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md +130 −41

CI cancelled — superseded by a newer push — run details

Intent

Human

<task-notification> <task-id>ab819910424bdc66b</task-id> <tool-use-id>toolu_01MGEovVywnt7TaSjdJdCqNW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6112a34e-476e-4b5e-8e07-f93a46fc6d50/tasks/ab819910424bdc66b.output</output-file> <status>completed</status> <summary>Agent "Builder check on alerts design" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I have 9 questions and 5 code claims that turned out wrong. The questions are ranked, most important first. ## Questions **1. Should box-side sinks keep paging every box rule once the engine is live, or only the "console engine silent" rule?** - Today `alertTick` sends every box rule event to that box's webhook and SNS topic (`internal/host/metrics_loop.go:525-537`). Adding the disk forecast as a box rule (§7.2) means it goes out there as well. - §8 asks for `CARLOS_ALERT_WEBHOOK` to point at a Slack URL "per box". Every disk, memory, CPU and forecast alert would then reach Slack twice: once raw from the box, once grouped from the engine. That breaks the noise rule. - The answer decides whether Plan 1 changes the agent's sink path, for example by gating box rules off the sinks while the engine's heartbeat is fresh. If it does, it also needs a Slack-shaped payload (see wrong claim 4). **2. For an app served by more than one edge, are app-alert thresholds per edge or across the fleet?** - Region HA pairs, apps placed on several boxes and apps in more than one region all exist. §7.3 evaluates each app on each edge and reports only the alerts that are firing. - With per-edge evaluation, an app with 30 requests on each of three boxes never reaches "≥50 requests", and one bad edge would make the app "down". - Fleet-wide thresholds would need boxes to send per-app counters, not just firing flags. That changes the alerts file, the heartbeat size (the ~2 KB estimate in §9) and the request budget. - §10.2 already says the per-app timing histogram "merges across boxes", which only works if per-app data reaches the console. So the spec contradicts itself here. **3. Which plan builds Fleet 5xx rate and Abuse surge?** - Plan 1 says "every §7.1 rule". Both of these rules read the edge fleet counters and the console.db series, which only exist in Plan 2. - Abuse surge also compares against a 7-day same-hour median, and history starts at first roll. What should it do before 7 days of data exist: stay silent, or fall back to an absolute floor? - The answer decides whether the fleet counters move into Plan 1. **4. How do one-off events become incidents, and how do they clear?** - "Region has no room" (`nocapacity.go`) and the `alerting.Page` callers (moves recovery, egress conflict in `hostsused.go`, lifetimes, claim loss) are single events with no clear signal. - §6 rule 1 (one message on fire, one on clear) and the tiles (Capacity is Watch "exactly when" an incident is open) both assume a state that clears. - Options include auto-closing after a fixed time, closing by hand, or closing when the same check next passes. The choice shapes the incident model and how long a tile stays Watch. **5. What is the signal for "Service down" and for "the upstream probe failing"?** - The heartbeat's probe table only covers routes with several upstreams and a health block (`internal/status/snapshot.go:620-632`). A normal app is never probed. - Is "service" meant to be platform services (the console, Keymail, the activator)? If so, nothing in the heartbeat reports them today. - If it means every probed app, operators get paged for customer outages. - Either way, "App is down" for most apps rests only on request failures and failed wakes. The answer adds or removes a new box-side probe. **6. Should "Too busy" count rate-limit refusals that only happened in observe mode?** - `RateShed` and `RateCeiling` also count requests the limit "would have refused" in observe mode (`internal/usage/edge.go:34-36`), and the edge rate limit is observe by default. - Counting them means alerting owners about refusals that never happened. Not counting them means the edge needs a separate enforced-only counter. **7. Which key signs webhooks, and how do receivers get its public half?** - The mail-events key is documented as "for this and nothing else" (`mailpush.go:135-140`), and its signed bytes carry the `carlos-mail-event` label (`mailpush.go:81`). - Reusing it lets a mail event be passed off as an alert, or the other way round. A new key needs a way to publish it. Mailpush hands its key to the app as an environment variable; outside receivers need it shown on the connector page or served at a URL. - "So receivers verify both alike" reads as same key, same label. That's probably not what's intended. **8. When the alert watcher retires, what do operators get on day one?** - Today each operator gets Keymail sent with their own grant (`alertwatch.go`, `grantRecipients`). §5.1 sends email through `deliver()`, which uses the console's federated identity and needs a confirmed connector. - Should the switch-on seed a confirmed email connector per operator, keeping the current mail? Or do operators get nothing until someone sets up Slack? - The answer decides whether Plan 1 includes a migration step and whether there's a regression window. **9. Smaller points, cheap to answer:** - **Quiet hours for app alerts.** §7.3 gives app alerts no level, but quiet hours let only `incident` through, so quiet hours would silence every app alert. - **New-app default email.** Does the owner's sign-in address count as confirmed under the opt-in rule in §5.3? - **Heartbeat windows.** Heartbeats are written every 5 minutes and read every 5 minutes, unaligned, and each carries only "the last completed window". Gaps in the chart would then be routine, not rare. May the heartbeat carry the last two or three windows? ## Wrong claims about the existing code 1. **§1, "daily metric rollups … nothing reads them".** The economics pass reads `metrics.DayRollup` for the usage sweep and fleet meters (`internal/console/economicspass.go:433-438`, `:873-878`). 2. **§5.3, "suspended and the account owner is emailed once, as mailpush does".** Mailpush suspends after 24 hours (`mailpush.go:96-101`) but emails nobody. The suspension only shows in the API (`internal/console/apimail.go:837-839`). 3. **§5.1, "signed with the console's Ed25519 key … same scheme as mailpush.go".** There is no general console key for this. Mailpush's key is single-purpose and its label is mail-specific (`mailpush.go:81`, `:135-140`), as in question 7. 4. **§8, "Flagship needs CARLOS_ALERT_WEBHOOK set to a Slack URL … a one-line host.env change".** - The webhook body is `{"kind":"page","level","subject","body"}` (`internal/alerting/alerting.go:124`), or the raw `metrics.Event` JSON for box rules (`internal/host/alertsink.go`, `deliver`). Neither has a `text` or `blocks` field, so Slack's incoming webhook would reject both. Code has to change first. - "To reach anyone" also overstates it: flagship boxes already deliver through SNS topics with confirmed email subscriptions (`alertsink.go` header comment). 5. **§7.1, the forecast fits "disk-used bytes" from the box's "own samples".** Samples carry only `DiskFrac` (`internal/metrics/sample.go:15`). Bytes appear only in the heartbeat (`DiskFreeBytes`, `snapshot.go:546`). This is easy to work around, but the claim as written is wrong. The other citations hold: the alert watcher and its every-minute LIST + GETs, `deliver()` at `delivery.go:41`, the `EdgeRow` counters, `unknownHost`, the claim workers, `GetIfChanged`, the `opRail` order, the 80% plan-cap warning, the 5/20 email limits, and `CertExpiresAt` reaching the console through heartbeat `Metrics.Aliases`.</result> <usage><subagent_tokens>117879</subagent_tokens><tool_uses>44</tool_uses><duration_ms>249406</duration_ms></usage> </task-notification>

Attributed to this commit: 4.86 g CO₂e (503,246 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
index 7c2ce757c..ecdb2bd2d 100644
--- 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
@@ -23,7 +23,8 @@ 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.
+ daily metric rollups are kept forever, and only the economics pass
+ reads them (`economicspass.go:433`). Nothing reads them for trends.
- 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.
@@ -120,9 +121,12 @@ where it matters.
/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).
+- **Signals** are produced where the data already lives:
+ - Box conditions (disk, memory, forecast) are evaluated on the box.
+ - Traffic and per-app numbers are counted at each edge and reported
+ as counters.
+ - The console adds the counters up across boxes and evaluates the
+ fleet-wide thresholds (§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.
@@ -152,9 +156,14 @@ multiply setup.
- **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`).
+- **Webhook** payloads are JSON with a versioned body (`"v":1`).
+ - **Signing:** a `Carlos-Signature` header in the same format as
+ `mailpush.go`, but with a new single-purpose alert key and its own
+ signed label (`carlos-alert`). Mailpush's key is documented as
+ mail-only (`mailpush.go:135-140`). A separate label means a mail
+ event can never be passed off as an alert, or the other way round.
+ - **Public key:** shown on the connector page and served at a fixed
+ console URL, so receivers outside CARLOS can verify.
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.
@@ -191,6 +200,18 @@ Who can change what (my call):
- members: can see the Alerts tabs and history, and can add an email
connector for themselves only
+**Day one for operators** (my call). When the alert watcher retires,
+each operator gets an email connector for their sign-in address,
+already confirmed, and subscribed to every fleet rule. Today's Keymail
+messages carry on through `deliver()` with no gap. Slack is added on
+top. A person's own sign-in address counts as confirmed everywhere,
+because signing in already proved they own it.
+
+**Levels.** Every alert is either `incident` (something is broken now)
+or `warning` (something will break, or is degraded). Quiet hours let
+only `incident` through. For app alerts, "App is down" is an incident
+and the rest are warnings.
+
### 5.3 Abuse guards (binding)
- **Email and SMS:** confirmed opt-in only, as in §5.1. Unconfirmed
@@ -213,7 +234,9 @@ Who can change what (my call):
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.
+ suspended, as mailpush suspends a hook (`mailpush.go:96-101`). Unlike
+ mailpush, which tells nobody, the scope's owners are told once
+ through their other connectors, or by email if there are none.
## 6. Noise rules (binding)
@@ -240,6 +263,14 @@ Who can change what (my call):
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.
+8. **One-off events close themselves.** Some sources report a single
+ event with no "cleared" signal: region has no room, moves recovery,
+ egress conflict, lifetimes, claim loss. Each one opens an incident
+ that closes when the source has been quiet for its window. For
+ region has no room, which re-reports hourly while it holds, the
+ window is 2 hours. For the others it's 24 hours. An operator can
+ also close one by hand. The clear message for these says "no
+ further reports" rather than "resolved".
## 7. Signals
@@ -252,16 +283,20 @@ Who can change what (my call):
| 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 |
+| Service down | console | incident | a platform service the fleet summary reports not up (`status/fleet.go:81`, the same source as the dashboard's "is down" line, `opdashboard.go:101`) |
| 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 |
+| Fleet 5xx rate (Plan 2) | console | warning | above 1% for 15 min, at least 500 requests |
+| Abuse surge (Plan 2) | console | warning | blocked + watched above 5x the 7-day same-hour median, at least 1,000 requests. Until 7 days of history exist: above 10,000 an hour |
| Alert delivery broken | console | warning | a box reports `alerts=not-delivered` |
+The two Plan 2 rules read the fleet counters (§10.1), which arrive with
+that plan.
+
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
+- a least-squares line over the last 6 hours of disk use, refitted each
+ minute. Samples carry only the fraction used (`sample.go:15`), so the
+ box converts it to bytes using the filesystem size from `statfs`.
- 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
@@ -276,28 +311,57 @@ 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).
+- **Box rule state** keeps going to `alerts/boxes/<box>.json`, written
+ only on change. The forecast rule is added there. No new object.
+- **Fleet traffic counters** (Plan 2) ride the 5-minute status
+ heartbeat's private `Metrics` block (§10.1). No new object.
+- **Per-app counters** (Plan 3) go in one new object per box,
+ `metrics/boxes/<box>/apps-window.json`, written every 5 minutes, and
+ only if some app had requests. It holds the last 3 completed 5-minute
+ windows for each app with requests, so a read that misses one write
+ loses nothing.
+
+ Per app and window it holds:
+ - requests and 5xx
+ - failed proxies (502/503/504) and failed wakes
+ - enforced rate-limit refusals: shed and ceiling, counted only when
+ the limit is enforcing (§7.3)
+ - the app's peak memory as a fraction of its limit
+ - the timing histogram (§10.2)
+
+ `metrics/` writes never bump the change index (`ChangeScope` reports
+ no scope for them).
+
+**Box-side sinks after the engine is live** (my call). Today every
+box rule event also goes to the box's own webhook or SNS topic
+(`metrics_loop.go:525-537`). Sending forecasts and warnings that way
+too would duplicate the engine's grouped messages. So:
+- box sinks keep only `incident`-level rules (disk full now) and the
+ console-silent rule (§8)
+- the forecast and every warning go through the engine only
### 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.
+Thresholds are fleet-wide. Each edge reports per-app counters (§7.2).
+The console adds up every box's windows, so an app served by three
+boxes is judged on its total, then evaluates the alerts and decides who
+hears. Subscription state never reaches the boxes.
+
+A per-edge view still matters for one case. When the fleet-wide numbers
+fire, the message names the box or boxes where the failures were, so
+"down on one edge of a pair" reads differently from "down everywhere".
+
+**Observe mode doesn't count.** The rate limit is in observe mode by
+default, and `RateShed`/`RateCeiling` count would-be refusals too
+(`usage/edge.go:34-36`). "Too busy" counts only refusals made while
+enforcing, from new counters the edge keeps alongside the existing
+ones. In observe mode, "too busy" rests on memory alone.
| 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 |
+| App is down | at least 5 requests in 5 min across the fleet, and every one failed (502/503/504, or a wake that failed) | per-app counters: failed proxies, failed wakes. No new probe: most apps aren't probed today (`snapshot.go:620-632`) |
+| Errors | 5xx above 5% of at least 50 requests over 10 min | per-app counters: requests, 5xx |
+| Too busy | enforced refusals above 2% of requests for 10 min, or memory above 90% of the app's limit for 10 min | per-app counters: enforced refusals, peak memory |
| 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 |
@@ -321,15 +385,24 @@ design:
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.
+heartbeat for 10 minutes.
+
+Flagship boxes already deliver through SNS topics with confirmed email
+subscriptions, so that backstop reaches Paul by email today.
+
+To make the backstop post to Slack too, `internal/alerting` learns one
+more payload shape. When the webhook URL is on `hooks.slack.com`, it
+sends Slack's `{"text": ...}` body instead of today's
+`{"kind":"page",...}` or raw `metrics.Event` JSON, which Slack would
+reject. After that, pointing a box's `CARLOS_ALERT_WEBHOOK` at a Slack
+URL is a one-line `host.env` change, 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.
+- **Box writes:** no new objects in Plans 1 and 2. The heartbeat grows
+ by about 6 KB (3 windows of fleet counters).
`alerts/boxes/<box>.json` is written on change only, as today.
- **Console reads:**
- The engine replaces the alert watcher's every-minute read of
@@ -339,6 +412,11 @@ Steady state, nothing changing, with N boxes:
- 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.
+ - **Plan 3** adds the per-app window object, the only new object here.
+ Each box writes it at most every 5 minutes, and the engine reads it
+ every 5 minutes. That's at most 288 PUTs and 288 GETs per box a day,
+ about 5,800 requests a day for 10 boxes. An idle box (no app
+ requests) writes nothing, and its read is a 304.
- **Traffic page:** reads console.db only, so no store requests.
- **Delivery:** no store requests.
@@ -350,7 +428,10 @@ with nothing changed.
### 10.1 Data
Each edge keeps 5-minute fleet counters in memory and puts the last
-completed window in the heartbeat's private block:
+3 completed windows in the heartbeat's private block. Heartbeats are
+written and read every 5 minutes with no alignment, so carrying 3
+windows means a late read loses nothing. The console de-duplicates by
+window start. Each window holds:
- requests by class: 2xx, 3xx, 4xx, 404, 5xx
- protection: blocked, watched
@@ -415,19 +496,27 @@ From the approved mockup (layout A):
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.
+1. **Engine, connectors and fleet rules.** This plan builds:
+ - the engine and its history tables, and the notifier
+ - the Slack and webhook connectors, with the §5.3 guards
+ - email through `deliver()`, with the seeded operator connectors
+ (§5.2)
+ - the disk forecast on the box
+ - every §7.1 rule except the two marked Plan 2
+ - box sinks narrowed, and the Slack payload shape (§7.2, §8)
+ - 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.
+ heartbeat fields, console.db series, the `/fleet/traffic` page, and
+ the fleet 5xx and abuse surge rules.
- **Switch-on:** at its release.
-3. **Account and app alerts.** Edge per-app conditions, edge timing,
+3. **Account and app alerts.** Per-app window object, enforced-only
+ refusal counters, 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