carlos / platform Public

Fleet alerts Plan 2 plan rev 3: Paul's rulings 9 and 10 in spec and plan

Paul, 2026-11-01, after stopping rule 2 fired at plan review R2: fleet 5xx
rate and abuse surge close themselves an hour after their last crossing
('no further reports'), and traffic is counted once, at ingress, by final
status. Spec §2, §6.4, §7.1 and §10.1 amended; plan Task 2 and Task 5
rewritten; R2 dispositions added.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev dba81e2f212cbd598a0b13487ad8ea6a4a9a7ffe parent 07d0a83
3 files changed, +180 −139
  • docs/superpowers/plans/2026-11-01-fleet-alerts-2-traffic.md +121 −135
  • docs/superpowers/reviews/CODEX-BUILD-BRIEF-fleet-alerts-2.md +41 −0
  • docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md +18 −4
diff --git a/docs/superpowers/plans/2026-11-01-fleet-alerts-2-traffic.md b/docs/superpowers/plans/2026-11-01-fleet-alerts-2-traffic.md
index dcd460a93..39d462ccf 100644
--- a/docs/superpowers/plans/2026-11-01-fleet-alerts-2-traffic.md
+++ b/docs/superpowers/plans/2026-11-01-fleet-alerts-2-traffic.md
@@ -1,4 +1,4 @@
-# Fleet alerts Plan 2: fleet traffic. Implementation Plan (rev 1)
+# Fleet alerts Plan 2: fleet traffic. Implementation Plan (rev 3)
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
@@ -17,13 +17,19 @@
**Review history:**
- Astra R1 on 95377f52 was NOT READY, with 4 P1s and 1 P2 (`docs/superpowers/reviews/CODEX-FINDINGS-fleet-alerts-2-plan-R1.md`). Every finding is accepted. Dispositions are at the end.
-- This is rev 2, for round 2.
+- Astra R2 on b7ae2e33 was NOT READY, with 4 P1s and 1 P2 (`CODEX-FINDINGS-fleet-alerts-2-plan-R2.md`). Two fault families recurred, so stopping rule 2 fired (amadan discussion 497).
+- Paul ruled on 2026-11-01 ("Yes" to both cuts):
+ 1. `fleet_5xx` and `abuse_surge` are self-closing events.
+ 2. Every answer is counted once, on the box the visitor connected to, by its final status.
+
+ Both are recorded in the spec (§2, items 9 and 10).
+- This is rev 3, for round 3, the last. Rev 3 rewrites the counting (Global Constraints, Task 2) and the rules (Global Constraints, Task 5) to those rulings. The R1 and R2 mechanisms they replace (delivered flags, coverage, watermark, cursor, hysteresis) are gone.
## Recon: what main already counts (2026-11-01, at 11c8c864)
| §10.1 needs | What exists | Plan 2 does |
|---|---|---|
-| requests by class | `reqrec.Recorder` counts 2xx/3xx/4xx/404/5xx per app and minute (`internal/reqrec/recorder.go:123-131`). It is nil without a log sink or with `CARLOS_EDGE_RECORDS=off`. `usage.EdgeRow` has requests but no class. | Count at the same choke point, the observer defer in `Edge.ServeHTTP` (`internal/edge/edge.go:2185-2199`), and in `serveAssetFar`'s defer (`assetcatch.go:1074-1093`). It doesn't depend on the recorder. |
+| requests by class | `reqrec.Recorder` counts 2xx/3xx/4xx/404/5xx per app and minute (`internal/reqrec/recorder.go:123-131`). It is nil without a log sink or with `CARLOS_EDGE_RECORDS=off`. `usage.EdgeRow` has requests but no class. | Count at ingress, in one wrapper at the top of `Edge.ServeHTTP` and the :80 handler, by final status (Paul, 2026-11-01). It doesn't depend on the recorder. |
| blocked, watched | `observeGuardCount` puts them in the usage edge day (`guard.go:106-117`, `usagemeter.go:100-120`). Burst rules are excluded. `/fleet/protection` reads them. | Count from the same verdict in the same call, with the same burst exclusion, so `/fleet/traffic` and `/fleet/protection` agree. |
| rate-limit shed, ceiling, plan-throttled | In `EdgeRow` (`usage/edge.go:34-40`). Observe mode counts would-be refusals as refusals. | Count enforced refusals and observed (would-be) refusals apart. |
| unknown host | Not counted (`edge.go:2884` `unknownHost`). | New counter at the two outsider call sites. |
@@ -37,15 +43,22 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
- **Request budget (§9):** no new bucket objects and no new store calls. The engine's existing every-5th-pass heartbeat reads carry the windows. The traffic page reads console.db only.
- **Window:** 5 minutes, aligned to UTC multiples of 300 s. The heartbeat carries the last 3 completed windows. A window that began before the edge's counter started is never reported, so a restart is a gap, not a low count.
-- **Per window:**
- - Each request the edge answered for a route is counted once, as either refused or one status class.
- - `Requests == S2xx + S3xx + S4xx + S404 + S5xx + Refused`. 404 is not in `S4xx`, as in reqrec.
- - Unknown-host requests are counted only in `UnknownHost`.
- **Top lists:** 10 entries a window on the box, 20 in an hourly rollup.
-- **One counting owner per client answer (R1 #2).** The edge that writes the response to the client counts it, and no other edge does.
- - **Route answers.** A request this box serves for a route is counted in the `ServeHTTP` observer defer. That includes a hopped request whose answer goes back over the hop to the forwarding edge, because the forwarding edge doesn't count an answer the home delivered.
- - **Forwarded requests.** A request this box forwards by backhaul (`backhaulTo`) or region HA (`forwardHA`) is counted here only when the answer is local: an admission refusal (`backhaulAdmit` 429 or 503), a proxy `ErrorHandler` or `onError` 502/503, or `answerHolderUnreachable`. A response that came from the home is not counted here. The `ModifyResponse`/`onResponse` hook marks it delivered.
- - **Far-asset answers.** `serveAssetFar` owns every answer it writes, including its `backhaulAdmit` refusals and failed fills. The home skips traffic counting for the acknowledged fill hop (`out.unbilled`), the predicate billing already uses.
+- **Counting (Paul's ruling, 2026-11-01): every answer is counted once, on the box the visitor connected to, by its final status.**
+ - **The ingress counter.** One wrapper, installed first in `Edge.ServeHTTP` and in the :80 handler, records the final status of every answer.
+ - **Skipped requests.** It skips a request that arrived over a verified hop (`acceptHop`), over a fleet tunnel (`fromTunnel`), or from a door caller (`doorCallerFrom`, `hopDoorFrom`). The edge those came from counts them, or they are the platform's own calls. It also skips the status host, the tunnel hostname and the store door, which are not visitor traffic.
+ - **Classes, per window:**
+ - Refused: the status is 429 (every rate and plan refusal answers 429 through `writeRateLimited`, and so does a backhaul fair-share refusal), or the status is 404 and the response carries `X-Carlos-Ref` (the guard's block page, `guard.go:150-155`, which the hop does not scrub).
+ - Unknown host: the request reached `unknownHost`, which marks the ingress note. It counts only in `UnknownHost`.
+ - Otherwise the status picks the class. 1xx and 2xx (an upgrade's 101 included) count as `S2xx`, and 0 means 200.
+ - `Requests == S2xx + S3xx + S4xx + S404 + S5xx + Refused`. 404 is not in `S4xx`, as in reqrec.
+ - **Decision counters** are counted where the decision is made, beside the usage meter's call: `Blocked` and `Watched` in `observeGuardCount`, `RateShed`, `RateCeiling` and `RateObserved` in `noteRateLimited` (split by its `observe` flag), and `PlanThrottled` in `notePlanThrottled`. They are not part of the partition above. Blocked and watched equal the usage meter's guard counts by construction, so `/fleet/traffic` and `/fleet/protection` agree.
+ - **Lists:**
+ - Apps (requests and 5xx per account and app): counted where the route is served, under the predicate that bills it (`m.Record` in the `ServeHTTP` observer defer and in `serveAssetFar`'s defer). Each row means served requests.
+ - RateApps: at the decision sites above.
+ - Sources: at `observeGuardCount`, for guard matches.
+ - Paths: at ingress, for answers with status 404 (not-found probes and block pages alike).
+ - Hosts: at ingress, for unknown hosts.
- **Window wire size (R1 #5):**
- A completed window encodes to at most 12 KiB of JSON, so 3 windows are at most 36 KiB.
- `status.TrimTrafficWindow` enforces it. It drops the lowest-ranked entry of whichever list encodes largest, ties broken in the order Paths, Hosts, Apps, RateApps, Sources, until the window fits. Scalars are never dropped.
@@ -64,29 +77,17 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
- the console re-applies the same caps on ingest
- hostnames are never rendered as links
- **Retention:** 5-minute rows for 7 days, hourly rows for 90 days. There is no backfill. A missing window is a gap, never zero and never estimated.
-- **Coverage and evaluation (R1 #1, #3):**
- - A rule is judged on an *interval* of windows: 3 for `fleet_5xx`, 12 for `abuse_surge`.
- - An interval is *complete* when the pass read every listed heartbeat (no `unreadBoxes`) and every *expected box* has a row for every window in it. An expected box is one read this pass, not stale (`status.BoxStale(b, now, status.SnapshotPeriod)`), whose heartbeat carries traffic.
- - A silent or stale box is `box_silent`'s incident. The traffic rules judge the boxes that report.
- - The *watermark* is the oldest of the expected boxes' newest reported window starts. Intervals end at or before the watermark, so all their data has arrived.
- - Each heartbeat pass evaluates every interval end after the last one evaluated, up to the watermark, at most 12.
- - **Missing evidence never clears:**
- - If any interval meets the fire condition, the rule fires, complete or not.
- - If the rule is firing and any interval meets its stay condition, it stays firing.
- - It clears, or stays clear, only when the newest interval is complete.
- - Otherwise the state holds, with the subject reported unknown.
-- **Rules (spec §7.1), both warning level, subject `fleet`:**
- - `fleet_5xx`, over an interval of 3 windows (15 minutes):
- - fire: answered requests ≥ 500 and 5xx > threshold % (default 1) of them
- - stay: answered requests ≥ 500 and 5xx > half the threshold
- - `abuse_surge`, where B is blocked + watched over an interval of 12 windows (an hour):
- - with a full baseline:
- - fire: B ≥ 1,000 and B > multiple (default 5) × the median of the baseline hours
- - stay: B ≥ 500 and B > half the multiple × the median
- - the baseline hours are the `traffic_hours` row of the interval's middle UTC hour on each of the 7 previous days, each counted only with all 12 windows present
- - with fewer than 7 baseline hours (spec: "until 7 days of history exist"):
- - fire: B > 10,000
- - stay: B > 5,000
+- **Rules (Paul's ruling, 2026-11-01): `fleet_5xx` and `abuse_surge` are self-closing events.** Each opens when its threshold is crossed. It closes after an hour without another crossing, saying "no further reports" (the engine's Gone close, as for spec §6.8's one-off events). Missing data never produces a clear.
+ - A rule is judged on *intervals* of consecutive windows: 3 for `fleet_5xx` (15 minutes), 12 for `abuse_surge` (an hour). Each interval is summed over whatever validated rows console.db holds.
+ - Each heartbeat pass re-judges every interval whose last window starts within the last hour. Late windows are judged on the next pass, and there is no cursor to lose.
+ - If any of those intervals crosses, the pass adds a firing signal.
+ - If none crosses, the pass adds no signal and covers the rule, so `withGone` closes an open incident as "no further reports".
+ - A pass that couldn't list the heartbeats, or couldn't ingest, doesn't cover the rule, so the state holds.
+ - `fleet_5xx` crosses when answered requests are ≥ 500 and 5xx is > threshold % (default 1) of them.
+ - `abuse_surge`, where B is blocked plus watched over the interval:
+ - With a full baseline, it crosses when B ≥ 1,000 and B > multiple (default 5) × the median of the baseline hours. The baseline hours are the `traffic_hours` row of the interval's middle UTC hour on each of the 7 previous days. Each counts only when it is not partial: `windows == 12` and `box_windows == boxes*12`.
+ - With fewer than 7 such hours (spec: "until 7 days of history exist"), it crosses when B > 10,000.
+ - There is no hysteresis level for these two rules (spec §6.4 is amended). A rule that fires stays open for at least the hour after its last crossing, so it cannot flap.
- **Editable thresholds (§5.2), whole numbers:**
- `fleet_5xx` percent, bounds 1..50
- `abuse_surge` multiple, bounds 2..50
@@ -108,10 +109,10 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
## Review Focus
1. **A flood of junk:** 100,000 distinct random hostnames or paths in one window. Edge memory stays within the key caps, each window encodes to ≤ 12 KiB even with maximum-length keys full of `<`, and a `<script>` hostname renders as escaped text with no link. Tests in Tasks 2, 4 and 7.
-2. **Missed data is not zero:** a box that restarts, a heartbeat that can't be read, or a console down for 30 minutes. The chart shows a gap or a partial bar. `fleet_5xx` and `abuse_surge` never clear on incomplete intervals, and with heartbeats every 5-6 minutes no interval is skipped. A restarted box reports no partial window. Tests in Tasks 2, 4 and 5.
-3. **Counted once:** a backhauled request (delivered, refused at admission, or failed to dial), a region HA forward, a tunnelled request, a refusal (429 or a block page), a far-asset answer and its acknowledged home fill. Each client answer counts once fleet-wide, and a refusal is not also a 4xx. Blocked plus watched equal what the usage meter counted for `/fleet/protection`, except on acknowledged fills, where the meter counts at both edges. Tests in Task 2.
+2. **Missed data is not zero:** a box that restarts, a heartbeat that can't be read, or a console down for 30 minutes. The chart shows a gap or a partial bar. A rule never says "resolved": it closes only as "no further reports", an hour after its last crossing. A late window is still judged. A restarted box reports no partial window. Tests in Tasks 2, 4 and 5.
+3. **Counted once, at ingress:** a backhauled request (delivered, an early home 503, refused at admission, failed to dial), a home's 429 or block page crossing the hop, a region HA forward, a far-asset answer (filled, unacknowledged, fallback), a tunnelled request and a door call. Each client answer counts once fleet-wide, on the edge the visitor connected to, and a refusal is not also a 4xx. Blocked plus watched equal the usage meter's guard counts. Tests in Task 2.
4. **A forged or broken heartbeat:** windows with unaligned or future starts, negative or huge counts, more than 3 windows, over-long strings or lists. They are dropped or trimmed on ingest, and nothing panics. Tests in Task 4.
-5. **A quiet fleet:** under 500 requests with some 5xx never fires. Abuse surge with under 7 days of history uses the 10,000 floor. A zero median still needs 1,000. Tests in Task 5.
+5. **A quiet fleet:** under 500 requests with some 5xx never fires. Abuse surge with under 7 days of history, or with partial baseline hours, uses the 10,000 floor. A zero median still needs 1,000. Tests in Task 5.
---
@@ -123,7 +124,7 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
| `internal/status/snapshot.go` | `Probes.Traffic`, `BoxMetrics.Traffic` |
| `internal/reqrec/recorder.go` | `Recorder.ClientID` |
| `internal/edge/traffic.go` (new) | Window counter, bounded tops, `Edge.TrafficWindows` |
-| `internal/edge/edge.go`, `guard.go`, `ratelimit.go`, `planthrottle.go`, `assetcatch.go`, `answered.go` | Hooks: outcome refusal marks, the two defers, unknown host |
+| `internal/edge/edge.go`, `guard.go`, `ratelimit.go`, `planthrottle.go`, `assetcatch.go` | Hooks: the ingress wrapper, the skip and unknown-host notes, the decision sites, the served app list |
| `internal/host/agent.go` | `trafficSource`, enable on the agent's edge, `Probes.Traffic` |
| `internal/console/trafficstore.go` (new) | Tables, ingest with sanitising, hourly rollup, pruning, reads |
| `internal/console/trafficrules.go` (new) | `fleet_5xx` and `abuse_surge` evaluation, pure |
@@ -194,14 +195,11 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
- Create: `internal/edge/traffic.go`, `internal/edge/traffic_test.go`
- Modify:
- `internal/reqrec/recorder.go`: add `ClientID`
- - `internal/edge/answered.go`: `outcome` gains `refused bool` and `rate rateNote`
- - `internal/edge/edge.go`: the observer defer :2185, the unknown-host calls at :1986 and :2965
+ - `internal/edge/edge.go`: the top of `ServeHTTP` (the ingress wrapper), the hop accept at :1882, the door-caller and status-host branches, `unknownHost` :2884, the :80 handler near :2965, and the observer defer :2185
- `internal/edge/guard.go`: `observeGuardCount` :106
- - `internal/edge/ratelimit.go`: `rateAdmit` :126, `noteRateLimited` :159
- - `internal/edge/planthrottle.go`: :44-95
- - `internal/edge/assetcatch.go`: `serveAssetFar`'s defer :1074-1093, so that it covers every answer it writes
- - `internal/edge/edge.go`: around the backhaul calls at :1983-1985 (`backhaulTo`, `backhaulAdmit` :3899, the backhaul proxy's `ModifyResponse` and `ErrorHandler` near :4060-4075)
- - `internal/edge/forwardha.go`: `forwardHA` :180, with its `onError`, `onResponse` and `answerHolderUnreachable`
+ - `internal/edge/ratelimit.go`: `noteRateLimited` :159
+ - `internal/edge/planthrottle.go`: `notePlanThrottled` :44
+ - `internal/edge/assetcatch.go`: `serveAssetFar`'s defer :1074-1093 (app list only)
**Interfaces:**
- Consumes: Task 1 types.
@@ -209,59 +207,51 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
- `func (r *Recorder) ClientID(ip string, at time.Time) string`, which returns `ClientHash(r.saltFor(day), ClientKey(ip))`. It is nil-safe ("" for a nil recorder or no salt) and is never called with `r.mu` held.
- `type trafficCounter struct` (unexported) with:
- `func newTrafficCounter(now time.Time, clientID func(ip string, at time.Time) string) *trafficCounter`
- - `func (c *trafficCounter) request(ev trafficRequest)`
+ - `func (c *trafficCounter) answer(at time.Time, status int, blockPage bool, path string)`: an ingress answer. `blockPage` means a 404 carrying `X-Carlos-Ref`.
- `func (c *trafficCounter) unknownHost(at time.Time, host string)`
+ - `func (c *trafficCounter) served(at time.Time, account, app string, status int)`
+ - `func (c *trafficCounter) guard(at time.Time, blocked bool, clientIP, country string)`
+ - `func (c *trafficCounter) rate(at time.Time, account, app string, kind rateKind)`, where `rateKind` is shed, ceiling, observed or plan
- `func (c *trafficCounter) windows(now time.Time) []status.TrafficWindow`
- - `type trafficRequest struct { At time.Time; Account, App string; Status int; Refused bool; Guard guardCount; Path, ClientIP, Country string; Rate rateNote }`. `guardCount` is none, watch or block, already burst-excluded. `rateNote` holds shed, ceiling and observed flags plus a plan-throttled flag.
+ - `type ingressNote struct { skip, unknown bool; host string }`, carried on the request context from the top of `ServeHTTP`. `func noteIngressSkip(r *http.Request)` and `func noteIngressUnknown(r *http.Request, host string)` are nil-safe.
- `func (e *Edge) EnableTraffic(clientID func(string, time.Time) string)` and `func (e *Edge) TrafficWindows(now time.Time) []status.TrafficWindow`. The latter is nil when not enabled. The standalone `carlos edge` never enables it.
**Decisions:**
-- **Window rotation.** It happens lazily, under the counter's one mutex, on `request`, `unknownHost` and `windows`.
+- **Window rotation.** It happens lazily, under the counter's one mutex, on every call.
- A window whose end is ≤ now closes into a ring of 3.
- Each fully skipped 5-minute slot closes as a zero window.
- Windows that start before `ceil5(counter start)` are discarded.
- **`windows(now)`** returns the closed windows whose starts are among the 3 before `floor5(now)`, oldest first. An idle box reports zero windows, not nothing.
-- **Classification in the two defers.** The route path skips status-kind routes as the defer already does, and also skips `fromTunnel` requests, as `observeRecords` does: the hub counted them. A request is refused when `out.refused` is set (a rate or plan refusal) or the guard verdict blocked it.
- - Refused requests add to `Refused` and to no class.
- - Otherwise the status (0 means 200) picks the class.
-- **Blocked and watched** are counted in `observeGuardCount`, beside `m.RecordGuard`, under the same condition and with the same burst exclusion. Move the traffic call there, or call it with the same inputs, so the counts equal the usage meter's.
-- **Rate.** `rateAdmit` marks the request's outcome: `rate.shed` or `rate.ceiling` when enforcing, together with `refused = true`, and `rate.observed` in observe mode. `planThrottleAdmit` and `planUpgradeAdmit` mark `rate.plan` and `refused`. They reach the outcome with `outcomeFrom(r)`.
- - `serveAssetFar` must carry an outcome on its request, the same way, so its rate refusals reach its defer.
- - A refusal on a request with no outcome is still counted in the usage meter, as today. It doesn't reach the traffic counter, and a comment says so.
-- **Lists:**
- - Apps by route account and app.
- - RateApps for any rate or plan note.
- - Paths for 404s and guard matches (block or watch), keyed `reqrec.MaskPath(r.URL.Path)`.
- - Sources for guard matches only, keyed on `clientID(ip, at)`, or on `reqrec.ClientPrefix(ip)` when that is "". Country comes from `geoAnswerFrom(ctx).Country`. Call `clientID` before taking the counter's mutex.
- - Hosts from the unknown-host sites: the port is stripped, the host lower-cased and cut to 253 bytes, `strings.ToValidUTF8(…, "?")` is applied, and control characters become `?`.
-- **Unknown host** is counted only at `edge.go:1986` (after the far-asset and backhaul tries) and in the :80 handler at :2965. The door-caller sites at :1835, :1970 and :2120 are the platform's own calls and are not counted.
+- **The ingress wrapper.** The first statement of `ServeHTTP` wraps `w` in a status-capturing writer and puts a fresh `ingressNote` on the context. Its defer calls `answer` unless `note.skip`, or `unknown` instead when `note.unknown` is set. `noteIngressSkip` is called where the request is known to be a verified hop (right after `acceptHop` reports `hopped`), a tunnel delivery, a door caller, the status host, the tunnel hostname or the store door. The :80 handler gets the same wrapper.
+ - A hijacked or upgraded connection counts the status it wrote: 101 counts as `S2xx`.
+ - Nothing else in the request path changes. The existing observer defer keeps doing what it does today, plus `served`.
+- **`unknownHost`** calls `noteIngressUnknown` with the stripped host. A door caller's request is already skipped, so only outsiders count. The host is lower-cased and cut to 253 bytes, `strings.ToValidUTF8(…, "?")` is applied, and control characters become `?`.
+- **Decision sites.** `observeGuardCount` calls `guard` with the same verdict, the same burst exclusion and the same condition as `m.RecordGuard`. `noteRateLimited` calls `rate` (shed or ceiling, or observed when `observe`). `notePlanThrottled` calls `rate` with plan. Sources are keyed on `clientID(ip, at)`, or on `reqrec.ClientPrefix(ip)` when that is "". Country comes from `geoAnswerFrom(ctx).Country`. Call `clientID` before taking the counter's mutex.
+- **`served`** runs in the observer defer beside `m.Record`, under the same `!out.unbilled` condition, and in `serveAssetFar`'s defer beside its `Record`.
+- **Paths** are keyed `reqrec.MaskPath(r.URL.Path)`, for ingress answers with status 404.
- **Top-N** is taken at close by a stable sort on hits, descending, then key, ascending. Truncate to `TrafficTopN`, then apply `status.TrimTrafficWindow(&w, status.TrafficWindowMaxBytes)`.
-- **Forwarded requests (R1 #2).** A forwarded request gets a small status-capturing writer and a `delivered` flag on its context. The flag is set by the hop proxy's `ModifyResponse` (backhaul) or `onResponse` (`forwardHA`) when the home's response arrives.
- - When the call returns with `delivered` unset and a status written, the counter records one request with no app attribution and no list entries. A `backhaulAdmit` 429 counts as `Refused`, and any other status counts as its class.
- - A delivered response is the home's to count.
- - A home that hangs up mid-response after its headers arrived is the home's count. `delivered` was already set, so it is counted once.
-- **Acknowledged home fills.** The `ServeHTTP` defer's traffic call sits under `!out.unbilled`, as billing does. `serveAssetFar` at the far edge owns that client answer. `observeGuardCount` is unchanged, so `/fleet/protection` keeps counting as it does.
-
-- [ ] **Step 1: Write failing tests** in `traffic_test.go`, driving the counter with an injected clock:
- - `TestTrafficWindowsRotateAndKeepThree`: traffic in 5 consecutive windows. `windows` returns the last 3 completed windows, oldest first, with exact counts.
- - `TestTrafficIdleWindowsAreZero`: after 12 idle minutes, `windows` returns zero windows, not nil.
- - `TestTrafficPartialFirstWindowNotReported`: a counter started at 10:02 reports nothing for 10:00. At 10:15 it reports 10:05 and 10:10 only.
- - `TestTrafficClassesSumToRequests`: a mix of 200, 0, 301, 404, 403, 503 and refused requests. Assert `Requests == Answered()+Refused`, and that a refused 429 is not in `S4xx`.
- - `TestTrafficKeyCapsHold`: 100,000 distinct hosts and paths in one window. The internal map sizes stay ≤ 256 and ≤ 1024, `UnknownHost == 100000`, and each window encodes to ≤ 12 KiB.
- - `TestTrafficHostSanitised`: a 400-byte host with `\x00` and invalid UTF-8 is cut to 253 bytes, is valid UTF-8, and has no control bytes.
- - `TestTrafficTopNOrder`: ties are broken by key.
- - Through `ServeHTTP`, in an existing edge test harness with a usage meter:
- - `TestEdgeTrafficGuardMatchesUsageMeter`: in block mode, one blocked probe and one watched path. Traffic `Blocked`/`Watched` equal the meter's `GuardDelta` Block/Watch, and the blocked request is `Refused`.
- - `TestEdgeTrafficRateEnforcedVsObserved`: an enforcing refusal counts `RateShed` or `RateCeiling` and `Refused`. Observe mode counts only `RateObserved`, and the request is served and classed.
- - `TestEdgeTrafficTunnelNotCounted`
- - `TestEdgeTrafficBackhaulOwnership`, with two edges in one test, A forwarding to home B:
- - a delivered request counts once, at B, with its app
- - an admission 429 counts once, at A, as Refused
- - a saturated 503 counts once, at A, as S5xx
- - a dial failure (B closed) counts once, at A, as S5xx
- - `TestEdgeTrafficForwardHAOwnership`: the same three outcomes through `forwardHA`, including `answerHolderUnreachable`.
- - `TestEdgeTrafficFarAssetFillOnce`: a far-asset answer filled from the home counts once, at the far edge. The home's acknowledged fill hop adds nothing to traffic, while its usage-meter guard count is unchanged.
- - `TestEdgeTrafficUnknownHostOutsiderOnly`: an outsider's unknown host counts. A door caller's out-of-scope request does not.
+
+- [ ] **Step 1: Write failing tests** in `traffic_test.go`.
+ - Counter unit tests, with an injected clock:
+ - `TestTrafficWindowsRotateAndKeepThree`: traffic in 5 consecutive windows. `windows` returns the last 3 completed windows, oldest first, with exact counts.
+ - `TestTrafficIdleWindowsAreZero`: after 12 idle minutes, `windows` returns zero windows, not nil.
+ - `TestTrafficPartialFirstWindowNotReported`: a counter started at 10:02 reports nothing for 10:00. At 10:15 it reports 10:05 and 10:10 only.
+ - `TestTrafficAnswerClasses`: the statuses 200, 0, 101, 301, 404, a 404 block page, 429, 403 and 503. Assert `Requests == Answered()+Refused`, that the 429 and the block page are `Refused` and in no class, and that the plain 404 is in `S404`.
+ - `TestTrafficKeyCapsHold`: 100,000 distinct hosts and paths in one window. The internal map sizes stay ≤ 256 and ≤ 1024, `UnknownHost == 100000`, and each window encodes to ≤ 12 KiB.
+ - `TestTrafficHostSanitised`: a 400-byte host with `\x00` and invalid UTF-8 is cut to 253 bytes, is valid UTF-8, and has no control bytes.
+ - `TestTrafficTopNOrder`: ties are broken by key.
+ - Through `ServeHTTP`, in the existing edge test harnesses (two edges where the case needs a hop). Each case asserts the fleet sum of `Requests + UnknownHost` across both edges is exactly 1, and on which edge it landed:
+ - `TestEdgeTrafficIngressDirect`: a served 200 at the serving edge, which also gets the `served` app entry.
+ - `TestEdgeTrafficIngressBackhaulDelivered`: A forwards to home B and B answers 200. A counts the answer, B counts nothing at ingress, and B's app list has the app.
+ - `TestEdgeTrafficIngressBackhaulEarlyHome503`: B answers before its route observer (a stale home map, `edge.go:1956`). A counts one `S5xx`.
+ - `TestEdgeTrafficIngressBackhaulRefusals`: admission 429 (`Refused`), saturation 503 (`S5xx`), and a dial failure with B closed (`S5xx`). Each is counted at A.
+ - `TestEdgeTrafficIngressHomeRefusalKeepsClass`: B answers a rate 429 and a guard block page over the hop. A counts both as `Refused`. B counts `RateShed` or `RateCeiling` and `Blocked`.
+ - `TestEdgeTrafficIngressForwardHA`: a delivered forward and `answerHolderUnreachable`, each counted once, at the forwarding edge.
+ - `TestEdgeTrafficIngressFarAsset`: a far-asset answer filled from the home, an unacknowledged home answer, and a fallback forward. Each is counted once, at the far edge.
+ - `TestEdgeTrafficTunnelAndDoorSkipped`
+ - `TestEdgeTrafficUnknownHostOutsiderOnly`: an outsider's unknown host counts in `UnknownHost` and in no class. A door caller's out-of-scope request does not count.
+ - `TestEdgeTrafficGuardMatchesUsageMeter`: in block mode, one blocked probe and one watched path. Traffic `Blocked`/`Watched` equal the meter's `GuardDelta` Block/Watch.
+ - `TestEdgeTrafficRateEnforcedVsObserved`: enforcing counts `RateShed` or `RateCeiling`. Observe mode counts only `RateObserved`, and the request is served.
- `TestRecorderClientIDMatchesRecords`: `ClientID` equals the `cid` field the recorder writes for the same IP and day. A nil recorder returns "".
- [ ] **Step 2: Run, expect FAIL.** `go test ./internal/edge -run 'Traffic' -count=1` and `go test ./internal/reqrec -run ClientID -count=1`
- [ ] **Step 3: Implement.**
@@ -317,7 +307,6 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
- `func sanitizeTrafficWindow(w status.TrafficWindow, now time.Time) (status.TrafficWindow, bool)`
- `func (s *Store) IngestTraffic(byBox map[string][]status.TrafficWindow, now time.Time) (inserted int, err error)`
- `func (s *Store) PruneTraffic(now time.Time) error`
- - `func (s *Store) TrafficBoxRows(from, to int64) (map[string]map[int64]bool, error)`
- `func (s *Store) TrafficRange(from, to time.Time) (sum trafficSum, starts map[int64]bool, err error)`, read from 5-minute rows. `starts` is the window starts present.
- `func (s *Store) TrafficHours(from, to time.Time) ([]trafficHour, error)`, with `type trafficHour struct { Start time.Time; Windows, Boxes, BoxWindows int; Sum trafficSum }` and `func (h trafficHour) Partial(now time.Time) bool`. Hours with no row are absent, and the caller draws them as gaps.
@@ -365,67 +354,52 @@ The usage edge day is a bucket object read by `/fleet/protection`. Reading it fo
- Modify:
- `internal/console/alertsignals.go`: `heartbeatSignals` :~400, `alertRuleLevels`, `alertConsoleRules`, `alertThresholdDefaults`
- `internal/console/alertpages.go`: `alertRuleOrder` :213, `alertThresholdBounds` :218
- - `internal/console/alertnotify.go`: `alertCopy` draft keys, following the `rule.box_silent.*` set at :196-200
- - `internal/console/alertengine_pass.go`: `alertValueText` :731
- - `internal/console/alertstore.go`: add `AlertFiring`
+ - `internal/console/alertnotify.go`: `alertCopy` draft keys, following the `rule.box_silent.*` set at :196-200. The close uses the existing `clear.*.gone` copy.
+ - `internal/console/alertengine_pass.go`: `alertValueText` :731, `alertEngineState`
- Test: `internal/console/alertengine_pass_test.go` (`TestEnginePassFiveCycleRequests` :171)
**Interfaces:**
-- Consumes: Task 4.
+- Consumes: Task 4 (`TrafficRange`, `TrafficHours`, `IngestTraffic`, `PruneTraffic`).
- Produces, in `trafficrules.go`, all pure except `trafficSignals`:
- - `type trafficInterval struct { End int64; Sum trafficSum; Complete bool }`. `End` is the start of its last window.
- - `type trafficJudgement struct { Fire, Stay bool; Value float64 }`
- - `func fleet5xxJudge(sum trafficSum, thresholdPct float64) trafficJudgement`. `Value` is the 5xx percentage of answered requests.
- - `func abuseSurgeJudge(b int64, baseline []int64, multiple float64) trafficJudgement`. `baseline` is the qualifying same-hour totals, and fewer than 7 selects the floors. The median of 7 is the 4th value in order. `Value` is B.
- - `func combineTraffic(js []trafficJudgement, newestComplete, wasFiring bool) (firing bool, value float64, ok bool)`, which applies "missing evidence never clears" from the Global Constraints. `value` is the newest judgement's, or the firing one's when firing. `ok` false means hold.
- - `func trafficCoverage(expected []string, rows map[string]map[int64]bool, unread bool, starts []int64) bool`
- - `func trafficWatermark(expected []status.Box) (int64, bool)`: the oldest of each expected box's newest `Metrics.Traffic` start.
- - `func (s *Server) trafficSignals(ctx context.Context, boxes []status.Box, unread map[string]bool, settings map[string]alertRuleSetting, now time.Time, sig *alertSignals)`
- - `func (s *Store) AlertFiring(k alertKey) (bool, error)`: true when an open incident for k's scope and rule lists k's subject as a firing member.
- - `alertEngineState` gains `trafficEvaluated map[string]int64` (rule to the last interval `End` judged) and `trafficPrunedAt time.Time`.
+ - `func fleet5xxCrosses(sum trafficSum, thresholdPct float64) (bool, float64)`. The value is the 5xx percentage of answered requests.
+ - `func abuseSurgeCrosses(b int64, baseline []int64, multiple float64) (bool, float64)`. `baseline` is the qualifying same-hour totals, and fewer than 7 selects the 10,000 floor. The median of 7 is the 4th value in order. The value is B.
+ - `func trafficIntervalEnds(now time.Time) []int64`: the window starts within the last hour, `floor5(now)-60m` to `floor5(now)-5m`, oldest first.
+ - `func (s *Server) trafficSignals(ctx context.Context, settings map[string]alertRuleSetting, now time.Time, sig *alertSignals)`
+ - `alertEngineState` gains `trafficPrunedAt time.Time`.
- Rule IDs `fleet_5xx` and `abuse_surge`, both `alerting.LevelWarning`, both console rules. Threshold defaults are 1 and 5, with bounds {1, 50} and {2, 50}.
-- Task 4 adds `func (s *Store) TrafficBoxRows(from, to int64) (map[string]map[int64]bool, error)`, which reports for each box the window starts it has rows for.
**Decisions:**
-- **Ingest.** In `heartbeatSignals`, after `r.boxes` succeeds, call `IngestTraffic` with each box's `Metrics.Traffic`. Boxes with nil `Metrics` contribute nothing. Then call `trafficSignals(boxes, r.unreadBoxes, …)`.
+- **Ingest.** In `heartbeatSignals`, after `r.boxes` succeeds, call `IngestTraffic` with each box's `Metrics.Traffic`. Boxes with nil `Metrics` contribute nothing. Then call `trafficSignals`.
- If the listing failed, nothing is ingested or evaluated, and neither rule is covered, so their state holds.
- If ingest fails, `alertReadFailed` runs and neither rule is covered.
- After a successful ingest, call `PruneTraffic` when `now - trafficPrunedAt ≥ 1h`. A prune error is logged and fails the run, and evaluation still proceeds.
-- **Expected boxes.** These are boxes in `boxes`, not stale by `status.BoxStale(b, now, status.SnapshotPeriod)`, with a non-empty `Metrics.Traffic`. With none, both rules hold.
-- **Interval ends.** For each rule:
- 1. Judge every end `t` from `trafficEvaluated[rule]+5m` to the watermark, at most the newest 12. With no `trafficEvaluated` entry (after a console restart), judge only the watermark.
- 2. A `fleet_5xx` interval covers starts `t-10m..t`. An `abuse_surge` interval covers `t-55m..t`. Its baseline is the `traffic_hours` row at `floorHour(t-25m) - d*24h` for d = 1..7, counted only when its `windows == 12`.
- 3. `Complete` is `trafficCoverage` over the interval's starts.
- 4. Set `trafficEvaluated[rule]` to the watermark after judging.
-
- Because the watermark trails the slowest expected box, a box that publishes every 6 minutes delays judging. It doesn't skip any end.
-- **Signals.** An `ok` result adds one signal, keyed `(fleet, rule, "fleet")`, and covers the rule with no unknowns. A hold covers the rule with `unknown = {"fleet": true}`, so the member keeps its state and gets no Gone. `wasFiring` comes from `AlertFiring`.
+- **Judging.** For each end `t` in `trafficIntervalEnds(now)`:
+ - `fleet_5xx` sums starts `t-10m..t`.
+ - `abuse_surge` sums starts `t-55m..t`. Its baseline is the `traffic_hours` row at `floorHour(t-25m) - d*24h` for d = 1..7, counted only when not partial (`windows == 12` and `box_windows == boxes*12`).
+ - Each rule then gets one firing signal, keyed `(fleet, rule, "fleet")`, if any end crosses. Its `Value` is the latest crossing's. With no crossing it gets no signal. Either way the rule is covered with no unknowns (Global Constraints, rules).
- **Value text.** `fleet_5xx` reads like "1.4% of requests", `abuse_surge` like "12,400 an hour". The drafts are finalised in Task 6.
- [ ] **Step 1: Write failing tests.**
- - `TestFleet5xxJudgeTable`, rows of (answered, 5xx, threshold) and the expected Fire and Stay:
- - (499, 100, 1): F, F
- - (500, 6, 1): T, T
- - (500, 5, 1): F, T
- - (1000, 6, 1): F, T
- - (1000, 5, 1): F, F
- - (400, 50, 1): F, F
- - `TestAbuseSurgeJudgeTable`:
- - median 300: 1,501 fires and 1,500 doesn't (spec "above 5x"); 999 doesn't, even with a median of 0; 1,000 with a median of 0 fires; 751 stays, 750 doesn't; 499 doesn't stay
- - 6 baseline rows: 10,001 fires, 10,000 doesn't; 5,001 stays, 5,000 doesn't
- - `TestCombineTrafficMissingEvidenceNeverClears`:
- - an incomplete interval that fires: firing
- - incomplete, quiet and was firing: hold
- - newest complete and quiet: clear
- - an older interval fires while the newest is quiet: firing
- - `TestTrafficCoverageOneBoxCannotHideAnother` (R1 #1): box A has all windows and B misses one. Incomplete. With B's heartbeat in `unread`, also incomplete.
- - `TestTrafficSignalsHeartbeatCadenceNoSkippedInterval` (R1 #3): engine passes at minute offsets 0, 1, … with heartbeats every 5.5 minutes from two unaligned boxes, and a 5xx breach confined to one 15-minute interval. The rule fires exactly once, and every interval end in the run is judged exactly once.
- - `TestTrafficSignalsGapKeepsState`: an open `fleet_5xx` incident, then a pass whose newest interval is incomplete and quiet. No Gone signal, and the incident stays open.
- - `TestTrafficSignalsStaleBoxNotExpected`: a stale box with old windows doesn't block a clear.
- - `TestTrafficSignalsListingFailedNoCover`
+ - `TestFleet5xxCrossesTable`, rows of (answered, 5xx, threshold) and the expected result:
+ - (499, 100, 1): no
+ - (500, 6, 1): yes
+ - (500, 5, 1): no
+ - (100000, 1001, 1): yes
+ - `TestAbuseSurgeCrossesTable`:
+ - median 300: 1,501 crosses, 1,500 doesn't (spec "above 5x"), 999 doesn't
+ - median 0: 999 doesn't, 1,000 does
+ - 6 baseline rows: 10,001 crosses, 10,000 doesn't
+ - `TestAbuseBaselineSkipsPartialHours` (R2 #5): seven rows with `windows == 12` but `box_windows < boxes*12` give an empty baseline, so the floor applies.
+ - `TestTrafficSignalsSelfClosing`, driven through engine passes with a fake clock:
+ - a crossing at 10:00 opens one incident
+ - more crossings keep it open
+ - it closes at the first heartbeat pass after an hour with no crossing, with close reason `alertCloseGone` and the "no further reports" copy
+ - `TestTrafficSignalsMissingDataNeverClears`: an open `fleet_5xx` incident, then passes where every box's heartbeat is unreadable for 30 minutes. It stays open. Once reads resume with no crossing, it closes as "no further reports" an hour after the last crossing, never as resolved.
+ - `TestTrafficSignalsLateWindowJudged`: a crossing window that arrives one heartbeat pass late still opens the incident.
+ - `TestTrafficSignalsCommitFailureRetried` (R2 #4): the only crossing's commit fails once. The next pass, which re-judges the hour, opens it exactly once.
- `TestEnginePassFiveCycleRequests` (extend): heartbeats now carry 3 traffic windows each, and the pass's store call counts are exactly the existing assertion's.
- `TestAlertRuleOrderCoversEveryRule` (existing) passes with both rules added.
-- [ ] **Step 2: Run, expect FAIL.** `go test ./internal/console -run 'Fleet5xx|AbuseSurge|CombineTraffic|TrafficCoverage|TrafficSignals|EnginePassFiveCycle|AlertRuleOrder' -count=1`
+- [ ] **Step 2: Run, expect FAIL.** `go test ./internal/console -run 'Fleet5xx|AbuseSurge|AbuseBaseline|TrafficSignals|EnginePassFiveCycle|AlertRuleOrder' -count=1`
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run, expect PASS.**
- [ ] **Step 5: Commit.** `git commit -m "console: fleet 5xx and abuse surge rules on the traffic series"`
@@ -565,6 +539,8 @@ Tasks 6 and 7 may swap order. Task 7 renders drafts until Task 6 lands, and Task
## R1 dispositions (Astra, `CODEX-FINDINGS-fleet-alerts-2-plan-R1.md`)
+In rev 3, Paul's rulings of 2026-11-01 replace the mechanisms named under #1, #2 and #3. #4 and #5 stand as written.
+
1. **P1, one box hides another's missing windows.** Accepted.
- Completeness is now per expected box and window, and fails on any unread heartbeat.
- Missing evidence never clears; it can still fire.
@@ -584,3 +560,13 @@ Tasks 6 and 7 may swap order. Task 7 renders drafts until Task 6 lands, and Task
- It is applied at the edge and on ingest.
- The worst-case test uses maximum-length `<` keys.
+## R2 dispositions (Astra, `CODEX-FINDINGS-fleet-alerts-2-plan-R2.md`)
+
+Stopping rule 2 fired on two families (discussion 497), and Paul chose both cuts on 2026-11-01.
+
+1. **P1, a restarted box leaves the expected set.** Removed by ruling 1. There is no expected set: rules fire only on a crossing and close only as "no further reports", so missing data can't produce a clear.
+2. **P1, delivered and unbilled owners lose or duplicate answers.** Removed by ruling 2. The ingress edge counts every client answer by its final status, so a home's early 503, unacknowledged fills and fallback forwards all reach the one wrapper. A home's refusal keeps its class across the hop: 429, or 404 with `X-Carlos-Ref`. Task 2 tests each named case.
+3. **P1, rejected timestamps steer the watermark.** Removed with the watermark. Judging reads only validated rows.
+4. **P1, the cursor advances before commit.** Removed with the cursor. Each pass re-judges the last hour, and `TestTrafficSignalsCommitFailureRetried` pins that.
+5. **P2, baselines accept partial hours.** Accepted. A baseline hour needs `windows == 12` and `box_windows == boxes*12` (`TestAbuseBaselineSkipsPartialHours`).
+
diff --git a/docs/superpowers/reviews/CODEX-BUILD-BRIEF-fleet-alerts-2.md b/docs/superpowers/reviews/CODEX-BUILD-BRIEF-fleet-alerts-2.md
new file mode 100644
index 000000000..cfb120102
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-BUILD-BRIEF-fleet-alerts-2.md
@@ -0,0 +1,41 @@
+# Build brief: fleet alerts Plan 2 (fleet traffic)
+
+You are the implementer. The worktree is `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/fleet-alerts-2-traffic`, on branch `fleet-alerts-2-traffic`. Work only inside it.
+
+Plan: `docs/superpowers/plans/2026-11-01-fleet-alerts-2-traffic.md`. Spec: `docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md`. Read the plan's header, Global Constraints, Review Focus and the tasks you are given, and the spec sections the plan names, before you write code. The plan's review dispositions, at the end of the plan, name mechanisms earlier reviews paid for. Build them as written, not a variant.
+
+Each run's prompt names the tasks for that run. Do those tasks in order and nothing else.
+
+## How to work
+
+- Use TDD as each task's steps say: write the failing tests, run them and see them fail, implement, then run them and see them pass.
+- Commit once per task, with the task's commit subject. Subjects stay under 80 characters. The body says what changed and anything a reviewer should know. End every commit message with:
+
+ Co-Authored-By: GPT-6 Astra (codex) <noreply@openai.com>
+
+ Stage with `git add -A .`, then check `git status --short` for stray files before committing.
+- If the plan is wrong about the code, for example a line moved or a name differs, follow the code. Note the drift in the commit body. If the plan is wrong about a decision, for example a mechanism can't work as written, stop. Write what you found to `$TMPDIR/fleet-alerts-2-blocker.md` and end the run. Don't invent a different mechanism.
+- Don't push, merge, rebase or force anything. Never `git stash`, `git worktree prune`, `git clean`, or delete files by pattern. Don't create `.claude/HANDOFF.md`.
+- Don't touch the network, any AWS account or any dev box.
+
+## Verification budget (memory `verification-budget`)
+
+1. Mutation checks only on refusal, security, termination and lifecycle paths: at most about 10 per task, each run with targeted `-run` tests.
+2. Local test runs: once with `-count=1`, plus one `-race` run of the touched packages. Use repeat counts only for a test with a known or suspected flake.
+3. Scope: run only the touched packages, with targeted `-run` patterns. CI runs the full suite. Never run `go test ./...`.
+4. Run `gofmt -l` on touched files, and `go vet` on touched packages, before each commit.
+
+## Environment
+
+- Use the default Go build cache (`~/.cache/go-build`). Don't set `GOCACHE`, `GOMODCACHE` or `GOTMPDIR`. Use `GOFLAGS=-mod=mod GOPROXY=off`.
+- Put scratch files under `$TMPDIR` and remove them at the end.
+- `internal/console` tests take 1-2 minutes per run, so pick narrow `-run` patterns.
+
+## At the end of each run
+
+Write a summary as your final message:
+- the commits, as SHA and subject
+- tests run, with their results
+- the mutation checks done and what each caught
+- any drift from the plan
+- anything you were unsure of
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 cb78c2a7e..44ccf8d03 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
@@ -63,6 +63,13 @@ both times someone found it by hand. Today:
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.
+9. **Fleet 5xx rate and abuse surge close themselves** (2026-11-01, Plan 2
+ plan review). Each opens when its threshold is crossed and closes after
+ an hour without another crossing, saying "no further reports". Missing
+ data never produces a clear.
+10. **Traffic is counted once, at ingress** (2026-11-01, Plan 2 plan
+ review). Every answer is counted on the box the visitor connected to,
+ by its final status.
Everything else in this document is the author's call and is marked
where it matters.
@@ -293,7 +300,9 @@ and the rest are warnings.
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).
+ (today's box rules clear 5 points below; keep that). Fleet 5xx rate and
+ abuse surge have no clear level: they close themselves an hour after
+ their last crossing (§2, item 9).
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).
@@ -327,8 +336,8 @@ and the rest are warnings.
| 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 in a later plan (cut from Plan 1, Paul 2026-10-31) |
| Certificate expiring | console | warning | any served host whose cert expires within 14 days (`CertExpiresAt`) |
-| 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 |
+| Fleet 5xx rate (Plan 2) | console | warning | above 1% for 15 min, at least 500 requests. Closes an hour after the last crossing, "no further reports" (§2, item 9) |
+| 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. Closes an hour after the last crossing, "no further reports" (§2, item 9) |
| 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
@@ -487,7 +496,12 @@ 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
+- requests by class: 2xx, 3xx, 4xx, 404, 5xx, and refused. Each answer is
+ counted once, on the box the visitor connected to, by its final status
+ (§2, item 10). A 429, or a 404 carrying the block page's reference
+ header, counts as refused. The protection and rate-limit counters below
+ are counted where the decision is made, as the usage meter counts them.
+ The top apps list is counted where the app is served.
- protection: blocked, watched
- rate-limit shed and ceiling, plan-throttled
- unknown host: newly counted at `unknownHost`