carlos / platform Public

design: console Protection tab rev 2 (Astra builder check settled as calls)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev f2b88b4b09d6d0e7ed11b7e72ef50661180d2d65 parent dddc969
2 files changed, +144 −53
  • docs/superpowers/specs/2026-10-30-console-protection-tab-design.md +121 −53
  • docs/superpowers/specs/CODEX-FINDINGS-CONSOLE-PROTECTION-TAB.md +23 −0

CI passed — run details

diff --git a/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md b/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md
index 0089ff9cb..9d4f99b98 100644
--- a/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md
+++ b/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md
@@ -1,6 +1,8 @@
# Console Protection tab: how much bad traffic the edge catches
-Status: draft for Paul, 2026-10-30. Branch `design-console-protection-tab`.
+Status: draft for Paul, 2026-10-30, revision 2. Branch
+`design-console-protection-tab`. Builder check by Astra on rev 1 (8 points,
+all settled as calls in §7).
Builds on the edge request protection design
(`docs/superpowers/specs/2026-10-24-edge-request-protection-design.md`,
@@ -37,12 +39,9 @@ Goals:
whether protection is watching or blocking.
2. A breakdown by what the requests were after, in plain words (secret
files, WordPress, PHP admin tools...), from the catalogue's groups.
-3. The rate-limit refusals the edge already counts (shed, per-client
- ceiling, plan throttle) on the same page, as the other half of "bad
- traffic".
-4. A platform-wide view for system operators: the same totals across every
+3. A platform-wide view for system operators: the same totals across every
app, so Paul can see protection working on the whole flagship at once.
-5. A way from any count to the requests behind it (the Logs tab, filtered
+4. A way from any count to the requests behind it (the Logs tab, filtered
to protection records).
Non-goals (v1):
@@ -55,6 +54,15 @@ Non-goals (v1):
(§6.2, §5.6); this design leaves room for them but builds none.
- A CLI command. The tab reads a JSON door, so a `carlos` command can
follow cheaply.
+- Rate-limit refusals. *My call (builder check 8):* the stored counters
+ cannot tell a refusal from an observe-mode "would have refused" across a
+ window, and the plan throttle always enforces, so showing them honestly
+ needs its own stored mode. They are about load, not attacks; they get
+ their own section once that is fixed.
+- Burst-mode rules (the five `probe/admin` rules). *My call (builder
+ check 1):* no burst limit exists yet, so today every match of an admin
+ path is filed as a watch, and real admins use those paths. They are left
+ out of every count on this page until the burst limit ships.
Anti-goals (a failure even if it works):
- **A number that overstates.** A request counted twice (hub and fleet box,
@@ -85,36 +93,58 @@ hop and rate counters:
- `guard_block`: requests a protection rule blocked.
- `guard_watch`: requests a protection rule matched and let through.
-Both are inside `Requests`, never added to it. They are counted at the
-moment the edge files a Match record (`observeRecords`,
-`internal/edge/reqrecords.go`), by the same rule, so they are counted
-exactly once fleet-wide (the box that answered, not the box that forwarded
-over a tunnel). They are counted whether request records are on or off
-(`CARLOS_EDGE_RECORDS=off` stops records, not counts). Counts are exact:
-unlike records, they are never sampled.
-
-A burst-mode rule's match counts only when the edge treats it as a watch or
-block (the limit was passed), never below its limit.
-
-Per host, per **day** (not per hour, to keep the object small): the counts
-by catalogue group, keyed `<tier>/<group>` (`hard/secrets`,
-`probe/wordpress`...), with the same owner label. The catalogue has 16
+- `guard_checked`: requests the protection checks ran on. This is the
+ page's denominator ("3% of the requests protection checked").
+
+All three are inside `Requests`, never added to it. They are counted by the
+rule the guard itself runs by (`internal/edge/edge.go`, where
+`newGuardState` is set): only on the first box to see a request, never for
+door calls, and never for a request a tunnel delivered, which the hub that
+forwarded it already checked. So each request is counted once fleet-wide.
+*My call (builder check 2):* the denominator is `guard_checked`, not
+`Requests`, because usage metering counts a tunnelled request on both legs
+and a share against it would be wrong.
+
+`guard_block` and `guard_watch` count at the moment the edge files a Match
+record (`observeRecords`, `internal/edge/reqrecords.go`), whether request
+records are on or off (`CARLOS_EDGE_RECORDS=off` stops records, not
+counts). Matches of burst-mode rules are not counted (§2).
+
+Counts are never sampled, but they are best effort like every usage
+counter: the usage flush does not re-queue a failed write
+(`internal/host/usage_loop.go`), so a failed flush loses that 5-minute
+window. *My call (builder check 5):* accepted; the copy never says
+"exactly".
+
+Per host and owner, per **day** (not per hour, to keep the object small):
+the counts by catalogue group, keyed `<tier>/<group>` (`hard/secrets`,
+`probe/wordpress`...). The catalogue has 16
groups today. *My call:* the map holds at most 32 keys, and anything past
that counts under `other`, so a future tier cannot grow it without bound.
*My call:* this sits on `usage.EdgeDay` as a host-keyed map beside `hours`,
not on the hourly row, because 24 copies of a group map per host would
multiply the object's size.
-Owner labelling follows `EdgeRow.SetOwner`: when a row or the group map
-changes account or app, the protection counters start again from zero,
-exactly as the rate-limit counters do.
-
-Per box, per hour: the protection mode the box was running
-(`watch` / `block` / `off` / `catalogue`, from `CARLOS_EDGE_PROTECT`,
-`internal/edge/guard.go`), written with every flush. This is how the
-console tells "nothing caught" from "not counting": an hour with traffic
-for the app but no mode on the box that served it was served by a box that
-does not count yet.
+Ownership (builder check 3):
+- On the hourly row, `SetOwner` resets all three protection counters when
+ the owner changes, as it does the rate-limit counters. Because the share
+ uses `guard_checked`, never `Requests`, no previous owner's traffic shows.
+- *My call:* the daily group map is keyed by host, account and app
+ together, so a transfer starts a new entry and erases nothing. Each owner
+ reads only their own entry, and its total matches their hourly rows.
+
+Per box, per hour: the set of protection modes the box ran in that hour
+(`watch`, `block`, `off` or `catalogue`, from `CARLOS_EDGE_PROTECT`,
+`internal/edge/guard.go`; a restart mid-hour can add a second). This gives
+the headline its "watching" or "blocking".
+
+"Nothing caught" versus "not counting" (builder check 4): an app is counted
+from the first hour any box wrote `guard_checked` for it ("counting
+since"). *My call:* that first hour, and its day, are marked partial,
+because the box may have switched binaries inside it. After that, an hour
+where the app had traffic but `guard_checked` is zero on every box is shown
+as not counted rather than as nothing caught. A partial window says so on
+the page.
### 3.2 Reading in the console
@@ -122,23 +152,35 @@ The console sums the app's rows (matching account and app, as
`rateLimitCounts` does in `internal/console/apiinstances_ratelimit.go`)
over every box's edge days in the window.
-It reads through the economics sweep's settled-day cache
-(`internal/console/usagedays.go`): settled days are read once and kept for
-6 hours, and the hourly economics pass already leaves the month's settled
-days there, so a Protection view usually reads only today and yesterday.
-It must read the same set of boxes the economics sweep reads, including
-fleet boxes under their status prefix. *Note:* `rateLimitCounts` reads only
-the root `usage/edge/` prefix today. If that misses fleet boxes, fix it in
-the same shared reader so both counts agree.
+Windows (builder check 7): *my call:* whole UTC days, the last 7 (or 30)
+including today, so the hourly totals, the bars and the daily group map
+all cover the same days. The page says "since <date>", not "in the last
+168 hours".
+
+Which boxes: every box that writes edge days, including fleet boxes under
+their status prefix. Builder check 6 found that nothing in the console
+reads fleet edge days today: the economics sweep reads only the root
+`usage/edge/` prefix (`internal/console/economicspass.go`), and the cache
+recognises fleet metrics paths but not fleet edge-day paths
+(`internal/console/usagedays.go`). The builder adds fleet edge days to the
+shared reader and the cache, and `rateLimitCounts` moves onto the same
+reader so the two never disagree about which boxes exist.
+
+Reads go through the settled-day cache (`internal/console/usagedays.go`):
+a settled day is read once and kept for 6 hours. The hourly economics pass
+fills it for root boxes in the current month only, so it helps but is not
+relied on.
### 3.3 Request budget
- Writes: none added. Counters ride the existing 5-minute conditional put.
-- Reads: a cold per-app view reads today's and yesterday's edge day for
- each metering box (about 2 × boxes GETs). Settled days come from the
- cache, which the economics pass fills at no extra cost. The operator view
- reads the same objects, since every app's rows are in them.
-- Object size: two integers per host-hour with matches, one group map per
+- Reads (restated after builder check 6): a cold 7-day view reads up to 8
+ edge days per metering box, root and fleet; with the cache warm, 2 per
+ box (today and yesterday). A cold 30-day view reads up to 31 per box. At
+ about a dozen boxes that is a few hundred GETs at most, a fraction of a
+ cent, and no background polling is added. The operator view reads the
+ same objects, since every app's rows are in them.
+- Object size: three integers per host-hour with traffic, one group map per
host-day, and one mode per box-hour. The builder measures the largest
flagship edge day before and after on a test fixture shaped like it, and
the result must stay well under `usageDayReadCap` and
@@ -159,7 +201,8 @@ The tab sits in the app nav between Analytics and Activity, labelled
we check it never stops a real visitor."
- Blocking: "In the last 7 days, protection blocked 1,284 requests to
this app."
- - With the share beside it: "That's 3% of its 41,200 requests."
+ - With the share beside it: "That's 3% of the 41,200 requests
+ protection checked."
- Nothing caught: "Nothing in the last 7 days looked like an attack."
- Not counting: "Protection counts started on 4 November." Or, when part
of the window was served by boxes that do not count: "Some of this
@@ -172,16 +215,12 @@ The tab sits in the app nav between Analytics and Activity, labelled
.git", "WordPress logins and admin pages", "PHP admin tools", "Database
dumps"...) and its count. The group names are copy, kept beside the
catalogue so a new group cannot ship without one.
-4. **Rate limits.** The rate-limit refusals for the same window: requests
- slowed because an instance was busy, requests from one client over the
- per-client ceiling, requests slowed by the account's plan. In observe
- mode these read as "would have been slowed".
-5. **See the requests.** A link to the Logs tab filtered to protection
+4. **See the requests.** A link to the Logs tab filtered to protection
records. If Logs cannot filter by record kind today, the builder adds
that filter.
-Window: 7 days by default, with a 30-day choice, both ending now. *My
-call:* no custom ranges in v1.
+Window: 7 days by default, with a 30-day choice, as whole UTC days
+(§3.2). *My call:* no custom ranges in v1.
### 4.1 Operator view
@@ -196,8 +235,8 @@ view.
### 4.2 The JSON door
The tab renders from one JSON endpoint per app (and one for the operator
-view) returning the window's totals, per-day rows, group counts, rate-limit
-counts, the modes seen and a `counting_since` / `partial` flag. The page
+view) returning the window's totals, per-day rows, group counts, the
+modes seen, `counting_since`, and which days are partial or not counted. The page
and any later CLI command read the same answer.
## 5. Constraints
@@ -224,3 +263,32 @@ and any later CLI command read the same answer.
Analytics tab).
- How the Logs filter link is expressed.
- The exact spot of the operator section.
+
+## 7. Builder check (Astra, rev 1) and what it changed
+
+Astra read rev 1 as a builder (`gpt-6-astra`, high effort) and raised
+eight points. The code citations were checked and held. What rev 2 does
+with each:
+
+1. No burst limit exists, so burst rules file a watch for every admin-path
+ request. Burst rules are left out of every count (§2).
+2. Usage metering counts a tunnelled request on both legs. The share uses
+ a new `guard_checked` counter, counted by the guard's own rule (§3.1).
+3. The share could expose a previous owner's traffic, and resetting a
+ daily group map on transfer would erase a day. `guard_checked` resets
+ with the owner; the group map is keyed by owner (§3.1).
+4. One mode per hour cannot certify a mid-hour upgrade. "Counting since"
+ comes from `guard_checked`, and the first hour and day are marked
+ partial (§3.1).
+5. A failed usage flush loses its window. Accepted as best effort; the
+ copy never says "exactly" (§3.1).
+6. The console reads no fleet edge days today, and the economics pass
+ warms the cache for root boxes in the current month only. The read
+ budget is restated for cold views, and fleet edge days join the shared
+ reader (§3.2, §3.3).
+7. Rolling windows cannot match a daily group map. Windows are whole UTC
+ days (§3.2).
+8. Rate-limit counters cannot separate observe from enforce, and the plan
+ throttle always enforces. Rate limits leave v1 (§2).
+
+This was review round 1 of at most three (AGENTS.md stopping rules).
diff --git a/docs/superpowers/specs/CODEX-FINDINGS-CONSOLE-PROTECTION-TAB.md b/docs/superpowers/specs/CODEX-FINDINGS-CONSOLE-PROTECTION-TAB.md
new file mode 100644
index 000000000..9c4930c59
--- /dev/null
+++ b/docs/superpowers/specs/CODEX-FINDINGS-CONSOLE-PROTECTION-TAB.md
@@ -0,0 +1,23 @@
+1. **Should v1 exclude burst rules entirely, or also implement the missing burst limiter?**
+ §3.1 assumes a burst match becomes a watch/block only after crossing a limit. Today `guardDecide` sets a verdict immediately, and burst matches become watch records without any threshold ([guard.go:103](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/guard.go:103)). A test explicitly expects one `/admin` request to produce a watch record ([guard_test.go:177](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/guard_test.go:177)). Counting existing Match records would violate the anti-goal. Excluding burst rules and implementing enforcement are substantially different scopes.
+
+2. **Should protection totals and their request denominator follow the existing recorder’s attribution, or the design’s “box that answered” rule?**
+ Those rules differ for tunnels: the forwarding hub records the request; the receiving fleet box skips it ([reqrecords.go:62](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/reqrecords.go:62)). Guard checks follow that same arrangement ([edge.go:2020](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/edge.go:2020)). Usage metering, however, does **not** exclude tunnel-delivered requests ([edge.go:2034](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/edge.go:2034)). Summing root and fleet `Requests` can therefore count both legs while counting protection once. The answer determines whether this needs a separate request denominator or changes to existing metering.
+
+3. **Does ownership isolation include the request denominator, and must group counts reconcile with headline totals after a host changes owners?**
+ `SetOwner` resets refusal counters but deliberately retains `Requests` under the new owner’s label ([edge.go:49](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/usage/edge.go:49)). Thus the proposed share can expose the previous owner’s traffic count. Separately, resetting the proposed daily group map on transfer would erase the previous owner’s entire day of group counts, while their earlier hourly protection rows remain ([edge.go:91](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/usage/edge.go:91)). Preserving isolation and reconciliation requires more than copying the existing reset behavior.
+
+4. **What does `partial` certify when counting starts or protection mode changes midway through an hour?**
+ One mode per box-hour cannot distinguish an hour fully counted from an hour partly served by an older binary. Existing hourly totals are merged across flushes ([edge.go:91](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/usage/edge.go:91)), and protection mode is read at process startup ([guard.go:14](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/guard.go:14)). An upgrade at 10:30 could stamp a mode onto an hour containing uncounted traffic from 10:00. The answer determines whether the proposed mode field suffices or whether coverage needs additional timestamps or counters.
+
+5. **Does “exact” mean unsampled counts, or must counts also survive failed flushes and process restarts?**
+ The meter drains and clears its map before persistence ([usagemeter.go:82](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/usagemeter.go:82)). Failed usage writes lose that window; unlike analytics, usage is not requeued ([usage_loop.go:25](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/host/usage_loop.go:25), [usage_loop.go:51](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/host/usage_loop.go:51)). A later successful flush could record a mode without revealing the loss. Accepting best-effort totals, reporting gaps, and guaranteeing durable counts require different plans under the no-extra-writes constraint.
+
+6. **Can cold views exceed the stated two GETs per box, particularly for fleet traffic and windows crossing a month boundary?**
+ The economics sweep reads only root edge-day objects ([economicspass.go:496](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/console/economicspass.go:496)); its fleet reader fetches metrics rollups, not fleet edge days ([economicspass.go:870](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/console/economicspass.go:870)). The cache likewise recognizes fleet metrics paths but not fleet edge-day paths ([usagedays.go:122](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/console/usagedays.go:122)). Furthermore, the hourly filler reads only the current month ([economicspass.go:932](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/console/economicspass.go:932)). The claimed free cache warming therefore does not cover the required data. Meeting a strict budget would require changing the background read workload; accepting cache misses permits on-demand reads.
+
+7. **Are these rolling 168/720-hour windows, or UTC calendar-day windows, and may the group breakdown cover a different interval from the headline?**
+ A daily group map cannot exclude the early part of the first day of a rolling window. Existing rate-limit counts already round outward to whole hours ([apiinstances_ratelimit.go:169](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/console/apiinstances_ratelimit.go:169)), and usage assigns deltas to the flush’s hour rather than the requests’ hours ([edge.go:114](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/usage/edge.go:114)). The answer determines whether to change the window contract or the mandated daily aggregation shape.
+
+8. **Must rate-limit totals distinguish actual refusals from hypothetical refusals across the whole window?**
+ Observe and enforce decisions increment the same counters; the mode is not passed into the meter ([ratelimit.go:143](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/ratelimit.go:143), [ratelimit.go:159](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/ratelimit.go:159)). Existing data cannot separate them across boxes or mode changes. Also, plan throttling always enforces regardless of observe mode ([planthrottle.go:66](/home/paulca/.cache/tmp/claude-1001/design-console-protection-tab/internal/edge/planthrottle.go:66)), so §4’s blanket “would have been slowed” treatment is incorrect. Accurate historical distinctions require additional persisted information and an explicit treatment of older counts.
\ No newline at end of file