carlos / platform Public

edge, console, host, usage: plans 4c review fixes (throttle before the cache, register upgrades before the check, plan change clears the throttle, track only governed accounts, count plan refusals)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 4342723d9d6d45f3362a03e6390bf6fd34424392 parent 13af0b2
18 files changed, +339 −37
  • docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md +13 −6
  • docs/superpowers/notes/plans-4c-ledger.md +6 −0
  • docs/superpowers/plans/2026-10-25-plans-4c-box-throttle.md +12 −0
  • docs/superpowers/specs/CODEX-FINDINGS-PLANS-4C-CODE.md +55 −0
  • internal/console/accountplans.go +6 −1
  • internal/console/planlimits_test.go +20 −0
  • internal/edge/edge.go +11 −6
  • internal/edge/planthrottle.go +30 −5
  • internal/edge/planthrottle_test.go +102 −0
  • internal/edge/usagemeter.go +11 −0
  • internal/host/agent.go +1 −0
  • internal/host/plans_pass.go +8 −0
  • internal/host/plans_throttle_test.go +17 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +2 −2
  • internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv +12 −9
  • internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv +13 −7
  • internal/usage/edge.go +6 −1
  • internal/usage/edge_test.go +14 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md b/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md
index c716dfcf5..14993acbe 100644
--- a/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md
+++ b/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md
@@ -5,31 +5,33 @@ Ruling `census-ruling-plans-4c-box-throttle`. Every change below keeps the dispo
| unit | change | read sites | what changed |
|---|---|---|---|
| `internal/activator/activator.go` `type Service` | body | unchanged (0) | gains the maxRunFor hook field beside idleFor (plans 4c). No read added. |
+| `internal/console/accountplans.go` `Store.SetAccountPlan` | body | unchanged (1) | the upsert also clears the account's throttle (plans 4c, Astra finding 3), so a plan change publishes without it. The same statement on the same table; no read added. |
| `internal/console/store.go` `Store.migrate` | body | unchanged (2) | adds the additive account_plans.throttle column (plans 4c). No read added. |
-| `internal/edge/edge.go` `Edge.ServeHTTP` | body | unchanged (22) | calls planThrottleAdmit before the rate limit on the serving path, and on an upgrade planUpgradeAdmit plus trackUpgrade (plans 4c); the new reads live in those units (plans-4c-units decision). The same read sites here. |
-| `internal/host/agent.go` `runAgent` | body | unchanged (5) | arms svc.SetMaxRunFor(planMaxRunFor) beside SetIdleFor, and e.SetPlanThrottleFor(planThrottleFor) plus the planAwakeThrottled close hook beside SetRateCeilingFor (plans 4c). No read added. |
+| `internal/edge/edge.go` `Edge.ServeHTTP` | body | unchanged (22) | calls planThrottleAdmit before the response cache, and on an upgrade trackUpgrade then planUpgradeAdmit (plans 4c, Astra findings 1 and 2); the new reads live in those units (plans-4c-units decision). The same read sites here. |
+| `internal/host/agent.go` `runAgent` | body | unchanged (5) | arms svc.SetMaxRunFor(planMaxRunFor) beside SetIdleFor, and e.SetPlanThrottleFor(planThrottleFor), e.SetPlanGovernedFor(planGoverned) and the planAwakeThrottled close hook beside SetRateCeilingFor (plans 4c). No read added. |
| `internal/host/plans_pass.go` `plansPass` | body | unchanged (3) | keeps each account's published throttle from its limits record in the cache beside its limits, and tells planAwakeThrottled when an account first becomes awake-throttled (plans 4c). The same bucket objects; no read added. |
-| `internal/activator/activator.go` `Service.sweepOnce` | sites | +whole:Route | after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. |
+| `internal/activator/activator.go` `Service.sweepOnce` | sites | +whole:Route | after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. This bypasses the inflight and held-for-tick protections the idle stop keeps, on purpose: escalated to the census owner by Astra. |
-Envelopes re-pinned: `internal/activator`, `internal/console`, `internal/edge`, `internal/host`, `internal/plans`.
+Envelopes re-pinned: `internal/activator`, `internal/console`, `internal/edge`, `internal/host`, `internal/plans`, `internal/usage`.
Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision.
Recorded dispositions, which each change must still satisfy:
- `internal/activator/activator.go` `type Service`: authority, task B,C,D,F,J4. Basis: rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows
+- `internal/console/accountplans.go` `Store.SetAccountPlan`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=PROPOSED-design-plans-and-caps;basis=root-input; console SQL on its own account_plans table, as its store siblings (J4).
- `internal/console/store.go` `Store.migrate`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-email-signin;identity=the console (cmd/console serve under console.service, user carlos-console);basis=adds the sessions.method column (default keymail, the backfill) and calls migrateEmailSignin; SQLite DDL on CONSOLE_DB; the existing site moves;rev3=census-ruling-plans-4-notices-grace;basis=calls migratePlanGrace last, which creates the console's own plan_cap_state table (plans 4a). No read added here; the new store units are the plans-4a-store decision.
- `internal/edge/edge.go` `Edge.ServeHTTP`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added
- `internal/host/agent.go` `runAgent`: authority, task B,C,D,F. Basis: rev3=census-ruling-seeded-instances;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with wireSeedPlacement called in the activator start's Configure step, before armMovesPass, and the startup sweep's result stored for the import rollback in Recover; read sites unchanged, offsets moved; main's B,C,D,F authority retained PROPOSED E46: captured claim selection and root journal mutation; root RPC outside service host exclusion; SQL/route data never grants root authority. Executing identity: service controller; root for inventory/retirement callbacks.;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=passes the agent's log sink to armRunsPass; reads unchanged;rev3=census-ruling-db-region-forward-1;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=arms the db-reads loop (armDBReads) beside armRunsPass in the activator start's Configure step; reads unchanged, offsets moved; main's authority retained;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=arms the change index (armChangeIndex) and starts the record view's backstop loop before the loops that read through it, and hands the edge the watch loader (edge.WithChangeWatch); read sites unchanged at the same offsets;rev3=census-ruling-edge-request-records;basis=builds the edge request recorder against the existing log sink and data dir (newRequestRecorder, passed os.Getenv and time.Now) and starts reqrecLoop on a minute ticker; no read added;rev3=census-ruling-design-edge-rate-limit-358;basis=arms the edge's plan rate-ceiling hook, e.SetRateCeilingFor(planRateCeilingFor), right after EnableUsage; read sites unchanged (5), offsets moved; no read added
- `internal/host/plans_pass.go` `plansPass`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=PROPOSED-plans-2-box-limits;basis=root-route; the agent's plans pass, serialised by its own mutex, reads its own routes' accounts and two bucket objects (the plans marker, each account's limits record) into a cache; planIdleFor only narrows the activator's idle window. No root decision.
- `internal/activator/activator.go` `Service.sweepOnce`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).
-Seal: `35f31d046603874ae62b32a60a4f4bf265a9e7fc0edd2fa48a2f9bcec3e3a615` → `eb7ea2158bceb592e91ef9a8ddd549cf1db56f7e508861aea12d5455e99494c8`.
+Seal: `3a7c2af84f411c06d01bfb1aca3fdc120c0418ee91847309ec67535f367f02a7` → `d12219c8f819556569d10bf590a6171f281ab882a112f716d784e31fb14adac1`.
Overlay: `internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
## Decision (hand-written, census-ruling-plans-4c-units)
-The plan throttle adds seven new units. Each is a new unit, so each is a decision. They have their own overlay, `internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv`, chained just before this one (seal → `35f31d04…`). Each is classed `legacy`/`accepted-legacy`, the same way as its sibling:
+The plan throttle adds ten new units. Each is a new unit, so each is a decision. They have their own overlay, `internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv`, chained just before this one (seal → `3a7c2af8…`). Each is classed `legacy`/`accepted-legacy`, the same way as its sibling:
| unit | sibling | what it does |
|---|---|---|
@@ -40,5 +42,10 @@ The plan throttle adds seven new units. Each is a new unit, so each is a decisio
| `Edge.trackUpgrade` | `Edge.rateAdmit` | registers an upgrade under its account so it can be closed |
| `internal/host/plans_pass.go` `planThrottleFor` | `planRateCeilingFor` | returns the account's published throttle while it is in force |
| `planMaxRunFor` | `planIdleFor` | 15 minutes for an awake-throttled instance, else 0 |
+| `Edge.notePlanThrottled` | `Edge.noteRateLimited` | counts and logs a plan-throttle refusal (Astra finding 5) |
+| `internal/edge/usagemeter.go` `UsageMeter.RecordPlanThrottled` | `UsageMeter.RecordRateLimited` | adds to the row's in-memory PlanThrottled counter |
+| `planGoverned` | `planIdleFor` | whether the account has a limits record, so its upgrades are tracked only then (Astra finding 4) |
+
+Astra also escalated `Service.sweepOnce`'s changed basis to the census owner. The continuous-awake ceiling stops an instance even with requests in flight or a tick due, which is the behaviour the spec asks for.
Every one of them only slows, shortens or closes what the account itself runs. None reads a path or value a tenant can name, and none grants anything.
diff --git a/docs/superpowers/notes/plans-4c-ledger.md b/docs/superpowers/notes/plans-4c-ledger.md
index e779cd4d4..bba87d1b6 100644
--- a/docs/superpowers/notes/plans-4c-ledger.md
+++ b/docs/superpowers/notes/plans-4c-ledger.md
@@ -12,3 +12,9 @@ Task 4: complete (commits 6215723..ed72cb3, tests: sh -c 'go test ./internal/edg
Task 5: Ruling: the ceiling skips an entry with a command in progress (e.cmd != nil), as the idle predicate does — a run is not cut mid-command — cost if wrong: a long command can hold an awake-throttled instance awake past 15 minutes.
Task 5: complete (commits ed72cb3..00541bd, tests: go test ./internal/activator/ -run 'MaxRunFor|IdleFor|MaxRun|Sweep' → ok github.com/carlosframework/platform/internal/activator (cached))
Task 6: complete (commits 00541bd..64bbf1e, tests: sh -c 'GOFLAGS=-buildvcs=false go test ./internal/provision/ -run 'Plan14RootReadCensus$|Plan9B8RecordWriteCensus$'' → ok github.com/carlosframework/platform/internal/provision 7.706s)
+Final: fixed (1) cache hits bypassed the throttle — TestThrottleAppliesToCacheHits RED→GREEN (plan check moved before the response cache; #358 still after it)
+Final: fixed (2) an upgrade could escape the close — TestUpgradeRegisteredBeforeTheThrottleCheck RED→GREEN, mutation-checked (register before asking the throttle)
+Final: fixed (3) a plan change republished the old throttle — TestPlanChangeClearsTheThrottle RED→GREEN (SetAccountPlan clears it; the pass re-sets within the hour)
+Final: fixed (4, re-graded Important: a plan requirement) plans-off upgrades were tracked — TestUpgradesUntrackedWhenNotGoverned, TestPlanGoverned RED→GREEN (SetPlanGovernedFor + host planGoverned)
+Final: fixed (5, re-graded Important: a plan requirement) refusals not counted — TestPlanThrottleRefusalCounted, TestPlanThrottledSumsAndResetsWithOwner RED→GREEN (EdgeRow.PlanThrottled)
+Final: census — Astra approved the existing units and envelopes except sweepOnce's changed basis and the ten new units, which go to Paul.
diff --git a/docs/superpowers/plans/2026-10-25-plans-4c-box-throttle.md b/docs/superpowers/plans/2026-10-25-plans-4c-box-throttle.md
index 0e54deaf1..7c8587cd8 100644
--- a/docs/superpowers/plans/2026-10-25-plans-4c-box-throttle.md
+++ b/docs/superpowers/plans/2026-10-25-plans-4c-box-throttle.md
@@ -247,3 +247,15 @@ The plan builds on Plans 4a and 4b, merged, and on the edge rate limiter (#358),
## Done when
Every task's tests pass and Review Focus 1–5 are pinned. The census card is approved. CI is green after merging current main, and Astra's whole-branch review has no open Critical or Important finding.
+
+## Astra review (2026-10-25)
+
+Findings in `docs/superpowers/specs/CODEX-FINDINGS-PLANS-4C-CODE.md`: three Important and two Minor. The two Minors were re-graded Important, because each breaks a requirement this plan states. All five are fixed, each test-first:
+
+1. **Cache hits skipped the throttle.** The plan check now runs before the response cache. The #358 limit still runs after it.
+2. **An upgrade could escape the close.** It is now registered before the throttle check (mutation-checked).
+3. **A plan change republished the old throttle.** `SetAccountPlan` now clears it, and the grace pass sets it again within the hour if the new plan is still exceeded.
+4. **Upgrades were tracked with plans off.** Tracking now happens only for an account plans govern (`SetPlanGovernedFor`, `planGoverned`).
+5. **Plan refusals weren't counted.** They are now counted in `EdgeRow.PlanThrottled`, apart from #358's counters.
+
+Census: Astra escalated `sweepOnce`'s changed basis and the ten new units to the census owner.
diff --git a/docs/superpowers/specs/CODEX-FINDINGS-PLANS-4C-CODE.md b/docs/superpowers/specs/CODEX-FINDINGS-PLANS-4C-CODE.md
new file mode 100644
index 000000000..7f3219cad
--- /dev/null
+++ b/docs/superpowers/specs/CODEX-FINDINGS-PLANS-4C-CODE.md
@@ -0,0 +1,55 @@
+Reviewed `13af0b2c459467404e79418be167c59661ca2649` against `7f8767715280765a9b47bd715a96203d3d36fda4`, which also matches local `origin/main`. No Critical findings.
+
+1. **Important — Cached responses bypass the account throttle.**
+ [internal/edge/edge.go:1880](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/edge.go:1880): cache hits return at lines 1866–1868 before `planThrottleAdmit`. An account past twice its bandwidth allowance can keep serving a cached response at unrestricted request rates, continuing to incur metered egress. Move the plan admission check before cache replay while preserving #358’s existing cache exemption.
+
+2. **Important — An upgrade can escape the throttle transition’s close operation.**
+ [internal/edge/edge.go:1796](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/edge.go:1796): admission and registration are separate. A request can pass `planUpgradeAdmit`, then the host publishes an awake throttle and calls `CloseAccountUpgrades`, then the request registers through `trackUpgrade` and completes its handshake. Registration never rechecks the throttle. Subsequent passes suppress the close callback because the account was already throttled. Make registration and the throttle recheck coordinate with closing, and add a deterministic test of this interleaving.
+
+3. **Important — A plan upgrade republishes the old throttle.**
+ [internal/console/planlimits.go:95](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/console/planlimits.go:95): publication copies `row.Throttle` unchanged. `SetAccountPlan` preserves that column, and the plan-change handler immediately publishes without recalculating it. For example, upgrading a bandwidth-throttled Free account to Personal publishes the larger allowance while retaining the 5 req/s throttle. Relief waits for the hourly grace pass despite the new limits already reaching boxes. Reconcile the throttle against the changed allowance before publishing the plan change.
+
+4. **Minor — Plans-off boxes still track upgrades.**
+ [internal/edge/planthrottle.go:76](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/planthrottle.go:76): tracking checks whether the hook exists, but `runAgent` installs it unconditionally at line 951. With no catalog, no limits record, or `CARLOS_PLAN_LIMITS=off`, every instance upgrade still allocates a cancellable context and retains an account-map entry until completion. This violates the explicit requirement for no upgrade-tracking side effects when plans are off. Gate tracking on actual plan enablement, including the production wiring in its test.
+
+5. **Minor — Plan refusals omit the required rate-limit accounting.**
+ [internal/edge/planthrottle.go:55](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/planthrottle.go:55): both refusal paths log directly and write a 429; neither calls `noteRateLimited` or records an equivalent distinct counter. An account receiving plan-throttle 429s therefore contributes no corresponding rate-limit refusal counts. Add the specified `plan-throttle` accounting without misclassifying it as #358 backstop or fair-share shedding.
+
+The five Review Focus checks were examined individually: expiry is enforced at lookup without another pass; buckets are account-scoped; upgrade closure fails the race described above; busy instances reach the ceiling and use the existing serialized stop/wake lifecycle; unmeasured caps preserve an active throttle. The command exemption matches the executor’s ruling. Worker ceilings, held probes and in-progress seeds retain their guards. Publication revisions, missing-plan-row deferral, last-good snapshots, 429 formatting, limiter slot release and reuse of existing polling paths have no additional findings from source inspection.
+
+**Census verdicts**
+
+These verdicts concern the recorded authority basis; they do not waive the functional findings above.
+
+| Existing unit | Verdict and evidence |
+|---|---|
+| `activator.Service` | **Approve.** [activator.go:1146](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/activator/activator.go:1146) adds only the atomic hook field. |
+| `console.Store.migrate` | **Approve.** [store.go:426](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/console/store.go:426) adds a column to the existing console database; no new database or path selection. |
+| `edge.Edge.ServeHTTP` | **Approve.** [edge.go:1796](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/edge.go:1796) and line 1880 add serving restrictions after existing scope and import gates; no root authority is granted. |
+| `host.runAgent` | **Approve.** [agent.go:503](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/host/agent.go:503) and lines 951–957 wire in-memory callbacks; existing root callbacks and input boundaries remain intact. |
+| `host.plansPass` | **Approve.** [plans_pass.go:105](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/host/plans_pass.go:105) reads the same account limits objects; lines 114–129 retain throttle values and notify the edge. No additional root input is followed. |
+| `activator.Service.sweepOnce` | **Escalate.** [activator.go:4734](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/activator/activator.go:4734) introduces a `StopIdle` path that bypasses `inflight == 0` and `heldForTick`, protections expressly named in the recorded basis. This is intentional ceiling behavior, but the owner must approve the changed basis rather than treating it as an unchanged-disposition approval. |
+
+All seven hand-written `plans-4c-units` entries are **new-unit decisions requiring the census owner**, as the card itself records:
+
+| New unit | Verdict and source assessment |
+|---|---|
+| `Store.SetAccountThrottle` | **Escalate — new disposition.** [accountplans.go:199](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/console/accountplans.go:199): parameterized update of the existing console table; no new root target. |
+| `Edge.planThrottleOf` | **Escalate — new disposition.** [planthrottle.go:32](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/planthrottle.go:32): route classification and an in-memory hook; existing caller exemptions retained. |
+| `Edge.planThrottleAdmit` | **Escalate — new disposition.** [planthrottle.go:46](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/planthrottle.go:46): in-memory bucket and HTTP refusal; no root operation. |
+| `Edge.planUpgradeAdmit` | **Escalate — new disposition.** [planthrottle.go:62](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/planthrottle.go:62): restricts upgrade admission; no root operation. |
+| `Edge.trackUpgrade` | **Escalate — new disposition.** [planthrottle.go:75](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/edge/planthrottle.go:75): tracks cancellation by account; no tenant-named path is opened or executed. |
+| `planThrottleFor` | **Escalate — new disposition.** [plans_pass.go:194](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/host/plans_pass.go:194): reads the existing snapshot and checks expiry. |
+| `planMaxRunFor` | **Escalate — new disposition.** [plans_pass.go:211](/home/paulca/.cache/tmp/claude-1001/plans-4c-box-throttle/internal/host/plans_pass.go:211): returns a fixed duration from that snapshot; introduces no additional input source. |
+
+| Re-pinned envelope | Verdict |
+|---|---|
+| `internal/activator` | **Escalate**, for the `sweepOnce` basis change above. The field and setter add no separate authority concern. |
+| `internal/console` | **Approve** existing authority boundaries; new-unit disposition remains owner-gated. Changed functions use existing SQL, measurement, audit and limits-publication paths. |
+| `internal/edge` | **Approve** existing authority boundaries; four new-unit dispositions remain owner-gated. Changes reach in-memory limiting, cancellation and response writing. |
+| `internal/host` | **Approve** existing authority boundaries; two new-unit dispositions remain owner-gated. No new polling, bucket keys or root targets. |
+| `internal/plans` | **Approve.** Additive wire field, expiry predicate and fixed rate rule; no new I/O. |
+
+Independent read-only checks verified both overlay seals (`35f31d04…` and `eb7ea215…`), legacy fingerprints, all 13 unit source digests and all five envelope hashes. The Go tests—including the typed census checks—could not start because creating Go’s build directory failed with `read-only file system`. Nothing was modified or posted to #280.
+
+**Verdict: changes required.**
\ No newline at end of file
diff --git a/internal/console/accountplans.go b/internal/console/accountplans.go
index 09abdd9fc..5a3980c24 100644
--- a/internal/console/accountplans.go
+++ b/internal/console/accountplans.go
@@ -84,6 +84,10 @@ func (s *Store) AccountPlan(accountID int64) (*AccountPlanRow, error) {
}
// SetAccountPlan writes the account's plan and returns its new revision.
+// It drops the account's throttle (plans 4c, Astra finding 3): a bigger
+// plan's relief must reach the boxes with its limits, and the grace pass
+// sets the throttle again within the hour if the new plan is still
+// exceeded.
// It validates nothing: callers check the plan against the catalog first.
func (s *Store) SetAccountPlan(accountID int64, plan string, packs map[string]int, source string,
sponsored *plans.Limits, reason, by string, now time.Time) (int64, error) {
@@ -108,7 +112,8 @@ func (s *Store) SetAccountPlan(accountID int64, plan string, packs map[string]in
SELECT ?, ?, ?, ?, ?, ?, 1, ?, ? WHERE EXISTS (SELECT 1 FROM accounts WHERE id = ? AND deleted_at = 0)
ON CONFLICT(account_id) DO UPDATE SET plan = excluded.plan, packs = excluded.packs,
source = excluded.source, sponsored = excluded.sponsored, reason = excluded.reason,
- updated_by = excluded.updated_by, updated_at = excluded.updated_at, revision = revision + 1
+ updated_by = excluded.updated_by, updated_at = excluded.updated_at, revision = revision + 1,
+ throttle = ''
RETURNING revision`,
accountID, plan, string(pj), source, sj, reason, by, now.Unix(), accountID).Scan(&rev)
if errors.Is(err, sql.ErrNoRows) {
diff --git a/internal/console/planlimits_test.go b/internal/console/planlimits_test.go
index 5aa66783f..9b00f0f63 100644
--- a/internal/console/planlimits_test.go
+++ b/internal/console/planlimits_test.go
@@ -283,3 +283,23 @@ func TestPublishCarriesThrottle(t *testing.T) {
t.Fatalf("published record = %+v", r)
}
}
+
+// Astra plans-4c finding 3: a plan change drops the throttle, so a bigger
+// plan's relief reaches the boxes with its limits; the grace pass sets it
+// again within the hour if the new plan is still exceeded.
+func TestPlanChangeClearsTheThrottle(t *testing.T) {
+ fx := newConsoleFixture(t)
+ acct := planAccount(t, fx, 501)
+ if _, err := fx.st.SetAccountPlan(acct.ID, "free", nil, PlanSourceOperator, nil, "r", "ops@example.com", planNow); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fx.st.SetAccountThrottle(acct.ID, &plans.Throttle{Bandwidth: true, Until: planNow.Add(time.Hour)}, planNow); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fx.st.SetAccountPlan(acct.ID, "personal", nil, PlanSourceOperator, nil, "upgrade", "ops@example.com", planNow); err != nil {
+ t.Fatal(err)
+ }
+ if row, _ := fx.st.AccountPlan(acct.ID); row.Throttle != nil {
+ t.Fatalf("throttle survived a plan change: %+v", row.Throttle)
+ }
+}
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 5ae2fa590..d138d7e2a 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -328,6 +328,7 @@ type Edge struct {
// 4c, planthrottle.go): the hook, the per-account buckets, and each
// account's open upgraded connections, closable when it is throttled.
planThrottle atomic.Pointer[func(registry.Route) (plans.Throttle, bool)]
+ planGoverned atomic.Pointer[func(registry.Route) bool]
planLimiter *ratelimit.Limiter
upgradesMu sync.Mutex
upgrades map[string]map[*int]context.CancelFunc
@@ -1793,12 +1794,12 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// proxy's hijack on a 101, so an open WebSocket is not counted, and
// it is itself an http.Hijacker (with Unwrap) for the proxy. A
// refusal is written to the raw writer.
- if !e.planUpgradeAdmit(w, r, up) {
- return
- }
var untrack func()
r, untrack = e.trackUpgrade(r, up)
defer untrack()
+ if !e.planUpgradeAdmit(w, r, up) {
+ return
+ }
release, ok := e.rateAdmit(w, r, up)
if !ok {
return
@@ -1853,6 +1854,13 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// A gated row's verify request is exempt in both directions too: it must
// reach the import rather than a response cached for the legacy route,
// and the import's answer must not outlive a rollback.
+ // The plan throttle (planthrottle.go) comes BEFORE the cache: a slowed
+ // account is slowed whoever answers, and a cache hit still spends
+ // bandwidth (Astra plans-4c finding 1). The per-instance rate limit
+ // below stays after it, so it still never limits a hit.
+ if !e.planThrottleAdmit(w, r, up) {
+ return
+ }
cacheable := e.cache != nil && (r.Method == http.MethodGet || r.Method == http.MethodHead) &&
up.route.Kind != "status" && up.route.ImportGate == ""
var key CacheKey
@@ -1877,9 +1885,6 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// the defer covers an answer that never wrote anything. A request that
// holds no slot (off, exempt, not an instance) keeps its writer as it
// was.
- if !e.planThrottleAdmit(w, r, up) {
- return
- }
release, admitted := e.rateAdmit(w, r, up)
if !admitted {
return
diff --git a/internal/edge/planthrottle.go b/internal/edge/planthrottle.go
index 5b3b031d9..65358f5f3 100644
--- a/internal/edge/planthrottle.go
+++ b/internal/edge/planthrottle.go
@@ -27,6 +27,27 @@ func (e *Edge) SetPlanThrottleFor(f func(registry.Route) (plans.Throttle, bool))
e.planThrottle.Store(&f)
}
+// SetPlanGovernedFor installs the hook that says whether a route's account
+// is governed by plans on this box at all (internal/host's planGoverned):
+// only then are its upgrades tracked for closing (Astra plans-4c finding
+// 4). nil tracks nothing.
+func (e *Edge) SetPlanGovernedFor(f func(registry.Route) bool) {
+ if f == nil {
+ e.planGoverned.Store(nil)
+ return
+ }
+ e.planGoverned.Store(&f)
+}
+
+// notePlanThrottled counts and logs one plan-throttle refusal, apart from
+// the per-instance rate limit's reasons (Astra plans-4c finding 5).
+func (e *Edge) notePlanThrottled(rt registry.Route, what string) {
+ if m := e.usageMeter.Load(); m != nil {
+ m.RecordPlanThrottled(rt)
+ }
+ e.logThrottled("plan-throttle "+rt.Host, "plan throttle: refused "+what+" for "+rt.Host+" (the account is slowed down until the month ends)")
+}
+
// planThrottleOf is the route's throttle when one applies to this request.
// Door, hop-door and tunnel callers are exempt, as from the rate limit.
func (e *Edge) planThrottleOf(r *http.Request, up upstream) (plans.Throttle, bool) {
@@ -52,7 +73,7 @@ func (e *Edge) planThrottleAdmit(w http.ResponseWriter, r *http.Request, up upst
if d == ratelimit.Allow {
return true
}
- e.logThrottled("plan-throttle "+up.route.Host, "plan throttle: refused a request for "+up.route.Host+" (the account is slowed down until the month ends)")
+ e.notePlanThrottled(up.route, "a request")
writeRateLimited(w, retryAfter)
return false
}
@@ -61,7 +82,7 @@ func (e *Edge) planThrottleAdmit(w http.ResponseWriter, r *http.Request, up upst
// account opens no new connection that would hold its apps awake.
func (e *Edge) planUpgradeAdmit(w http.ResponseWriter, r *http.Request, up upstream) bool {
if th, on := e.planThrottleOf(r, up); on && th.Awake {
- e.logThrottled("plan-throttle-upgrade "+up.route.Host, "plan throttle: refused an upgrade for "+up.route.Host)
+ e.notePlanThrottled(up.route, "an upgrade")
writeRateLimited(w, 60e9)
return false
}
@@ -70,10 +91,14 @@ func (e *Edge) planUpgradeAdmit(w http.ResponseWriter, r *http.Request, up upstr
// trackUpgrade makes an upgrade's connection closable by its account
// (CloseAccountUpgrades): the proxy ends an upgraded connection when its
-// request context is done. Only with a throttle hook armed, so a box
-// without plans keeps its request exactly as it was.
+// request context is done. Only for an account plans govern, so a box or
+// account without plans keeps its request exactly as it was. The caller
+// registers BEFORE asking the throttle (Astra plans-4c finding 2): the host
+// publishes a throttle and then closes, so either this request sees the
+// throttle, or it is registered when the close comes.
func (e *Edge) trackUpgrade(r *http.Request, up upstream) (*http.Request, func()) {
- if e.planThrottle.Load() == nil || up.route.Kind != "instance" {
+ g := e.planGoverned.Load()
+ if g == nil || up.route.Kind != "instance" || !(*g)(up.route) {
return r, func() {}
}
acct := release.RouteAccount(up.route)
diff --git a/internal/edge/planthrottle_test.go b/internal/edge/planthrottle_test.go
index 73af892d0..1a7b7b457 100644
--- a/internal/edge/planthrottle_test.go
+++ b/internal/edge/planthrottle_test.go
@@ -32,6 +32,7 @@ func throttleScene(t *testing.T, on, awake *atomic.Bool, backend string) *rateSc
)
frozen := time.Date(2026, 10, 25, 12, 0, 0, 0, time.UTC)
s.e.planLimiter = ratelimit.NewLimiter(func() time.Time { return frozen }, 1000)
+ s.e.SetPlanGovernedFor(func(rt registry.Route) bool { return rt.Account == "bdk" })
s.e.SetPlanThrottleFor(func(rt registry.Route) (plans.Throttle, bool) {
if rt.Account != "bdk" || !on.Load() {
return plans.Throttle{}, false
@@ -147,3 +148,104 @@ func TestAwakeThrottleClosesAndRefusesUpgrades(t *testing.T) {
}
wantOK(t, s.get(t, "203.0.113.1", ptHost, "/plain"), "a plain request while awake-throttled")
}
+
+// Astra plans-4c finding 1: a cache hit spends the throttled account's
+// bucket too; the #358 limit still never limits a hit.
+func TestThrottleAppliesToCacheHits(t *testing.T) {
+ ts, _ := countingUpstream(t, "cached page", map[string]string{"Cache-Control": "public, max-age=60"})
+ var on, awake atomic.Bool
+ on.Store(true)
+ s := throttleScene(t, &on, &awake, ts.Listener.Addr().String())
+ s.e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes))
+ for i := 0; i < plans.ThrottleRule.Burst; i++ {
+ wantOK(t, s.get(t, "203.0.113.1", ptHost, "/page"), fmt.Sprintf("request %d within the burst", i))
+ }
+ if res := s.get(t, "203.0.113.1", ptHost, "/page"); res.status != http.StatusTooManyRequests {
+ t.Fatalf("a cache hit past the throttle: %d, want 429", res.status)
+ }
+}
+
+// Finding 2: an upgrade is registered before the throttle is asked, so a
+// close that lands between the two still reaches it.
+func TestUpgradeRegisteredBeforeTheThrottleCheck(t *testing.T) {
+ ws := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ conn, buf, err := w.(http.Hijacker).Hijack()
+ if err != nil {
+ return
+ }
+ defer conn.Close()
+ buf.WriteString("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n")
+ buf.Flush()
+ for {
+ line, err := buf.ReadString('\n')
+ if err != nil {
+ return
+ }
+ buf.WriteString("echo:" + line)
+ buf.Flush()
+ }
+ }))
+ t.Cleanup(ws.Close)
+ s := newRateScene(t, "", nil, registry.Route{Host: ptHost, Kind: "instance", Addr: ws.Listener.Addr().String(), Status: "ready", App: "web", Account: "bdk"})
+ s.e.SetPlanGovernedFor(func(registry.Route) bool { return true })
+ var once atomic.Bool
+ s.e.SetPlanThrottleFor(func(rt registry.Route) (plans.Throttle, bool) {
+ if once.CompareAndSwap(false, true) {
+ // The host publishes an awake throttle and closes the account's
+ // upgrades while this request is between registration and the
+ // throttle check; this check still saw the old snapshot.
+ s.e.CloseAccountUpgrades("bdk")
+ }
+ return plans.Throttle{}, false
+ })
+ c, br, status := openSocket(t, s, ptHost)
+ if status == http.StatusSwitchingProtocols {
+ fmt.Fprint(c, "one\n")
+ if line, err := br.ReadString('\n'); err == nil {
+ t.Fatalf("the upgrade escaped the close: echoed %q", line)
+ }
+ }
+}
+
+// Finding 4: with plans off for the account nothing is tracked.
+func TestUpgradesUntrackedWhenNotGoverned(t *testing.T) {
+ ws := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ conn, buf, err := w.(http.Hijacker).Hijack()
+ if err != nil {
+ return
+ }
+ defer conn.Close()
+ buf.WriteString("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n")
+ buf.Flush()
+ io.Copy(io.Discard, buf)
+ }))
+ t.Cleanup(ws.Close)
+ s := newRateScene(t, "", nil, registry.Route{Host: ptHost, Kind: "instance", Addr: ws.Listener.Addr().String(), Status: "ready", App: "web", Account: "bdk"})
+ s.e.SetPlanThrottleFor(func(registry.Route) (plans.Throttle, bool) { return plans.Throttle{}, false })
+ s.e.SetPlanGovernedFor(func(registry.Route) bool { return false })
+ if _, _, status := openSocket(t, s, ptHost); status != http.StatusSwitchingProtocols {
+ t.Fatalf("handshake = %d", status)
+ }
+ s.e.upgradesMu.Lock()
+ n := len(s.e.upgrades)
+ s.e.upgradesMu.Unlock()
+ if n != 0 {
+ t.Fatalf("%d account(s) tracked with plans off", n)
+ }
+}
+
+// Finding 5: a plan-throttle refusal is counted as its own reason.
+func TestPlanThrottleRefusalCounted(t *testing.T) {
+ var on, awake atomic.Bool
+ on.Store(true)
+ s := throttleScene(t, &on, &awake, okBackend(t))
+ m := NewUsageMeter()
+ s.e.EnableUsage(m)
+ for i := 0; i <= plans.ThrottleRule.Burst; i++ {
+ s.get(t, "203.0.113.1", ptHost, "/")
+ }
+ row := m.Drain()[ptHost]
+ if row.PlanThrottled != 1 || row.RateShed != 0 || row.RateCeiling != 0 {
+ t.Fatalf("row = %+v, want one plan-throttle refusal and no #358 counts", row)
+ }
+}
diff --git a/internal/edge/usagemeter.go b/internal/edge/usagemeter.go
index 41cf2b038..869fa25e7 100644
--- a/internal/edge/usagemeter.go
+++ b/internal/edge/usagemeter.go
@@ -68,6 +68,17 @@ func (u *UsageMeter) RecordRateLimited(rt registry.Route, d ratelimit.Decision)
u.mu.Unlock()
}
+// RecordPlanThrottled counts one request refused because rt's account is
+// slowed down by its plan (plans 4c).
+func (u *UsageMeter) RecordPlanThrottled(rt registry.Route) {
+ u.mu.Lock()
+ row := u.m[rt.Host]
+ row.SetOwner(release.RouteAccount(rt), rt.App)
+ row.PlanThrottled++
+ u.m[rt.Host] = row
+ u.mu.Unlock()
+}
+
// Drain returns the accumulated rows and resets the meter.
func (u *UsageMeter) Drain() map[string]usage.EdgeRow {
u.mu.Lock()
diff --git a/internal/host/agent.go b/internal/host/agent.go
index d6bf2979e..906319137 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -949,6 +949,7 @@ func runAgent(args []string, buildClaims ClaimFactory) {
// account's shared bucket, and its open upgrades closed when it
// becomes awake-throttled.
e.SetPlanThrottleFor(planThrottleFor)
+ e.SetPlanGovernedFor(planGoverned)
closeUpgrades := func(sqid string) {
if n := e.CloseAccountUpgrades(sqid); n > 0 {
log.Printf("agent: plan throttle: closed %d open connection(s) of account %s", n, sqid)
diff --git a/internal/host/plans_pass.go b/internal/host/plans_pass.go
index b05b93acd..efd496870 100644
--- a/internal/host/plans_pass.go
+++ b/internal/host/plans_pass.go
@@ -206,6 +206,14 @@ func planThrottleFor(rt registry.Route) (plans.Throttle, bool) {
return th, true
}
+// planGoverned is whether plans govern the route's account on this box:
+// plans on and a limits record read. The edge tracks upgrades for closing
+// only then (Astra plans-4c finding 4).
+func planGoverned(rt registry.Route) bool {
+ _, ok := planLimitsFor(release.RouteAccount(rt))
+ return ok
+}
+
// planMaxRunFor is the activator's continuous-awake hook: 15 minutes for an
// instance of an awake-throttled account, else 0 (no ceiling).
func planMaxRunFor(rt registry.Route) time.Duration {
diff --git a/internal/host/plans_throttle_test.go b/internal/host/plans_throttle_test.go
index 559063916..cc1cd3b07 100644
--- a/internal/host/plans_throttle_test.go
+++ b/internal/host/plans_throttle_test.go
@@ -112,3 +112,20 @@ func TestPlansPassClosesUpgradesWhenAwakeThrottled(t *testing.T) {
t.Fatalf("closed = %v, want bab once", closed)
}
}
+
+// Finding 4: the edge tracks upgrades only for accounts plans govern.
+func TestPlanGoverned(t *testing.T) {
+ s, reg := plansWorld(t)
+ if planGoverned(throttledRoute) {
+ t.Fatal("governed with plans off")
+ }
+ putMarker(t, s, true)
+ putAccountLimits(t, s, "bab", 90)
+ plansPass(context.Background(), s, reg, plansNoEnv)
+ if !planGoverned(throttledRoute) {
+ t.Fatal("an account with a limits record is not governed")
+ }
+ if planGoverned(otherRoute) {
+ t.Fatal("an account without a record is governed")
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index b66720d56..3fa7093a1 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -27,5 +27,5 @@ plan14-root-reads-plans-4b-after-grace.tsv 0c4eabfe38e12b098285bdeb5ceb0b16e5333
plan14-root-reads-certwarm-wake.tsv 91204fcbc484343c03bd5ae69e3084055bc519a5b317e2ae3dc49880080764e2
plan14-root-reads-static-sweep-new.tsv 5f9f8435788e8bdaa965e1dc68cfccd5264b2b2121366ec73004b9ca3cb48ecb
plan14-root-reads-static-sweep.tsv 5f9f8435788e8bdaa965e1dc68cfccd5264b2b2121366ec73004b9ca3cb48ecb
-plan14-root-reads-plans-4c-units.tsv 35f31d046603874ae62b32a60a4f4bf265a9e7fc0edd2fa48a2f9bcec3e3a615
-plan14-root-reads-plans-4c-box-throttle.tsv eb7ea2158bceb592e91ef9a8ddd549cf1db56f7e508861aea12d5455e99494c8
+plan14-root-reads-plans-4c-units.tsv 3a7c2af84f411c06d01bfb1aca3fdc120c0418ee91847309ec67535f367f02a7
+plan14-root-reads-plans-4c-box-throttle.tsv d12219c8f819556569d10bf590a6171f281ab882a112f716d784e31fb14adac1
diff --git a/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv b/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv
index f76ad6f4a..17d78ace0 100644
--- a/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv
+++ b/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv
@@ -1,17 +1,20 @@
# Census overlay plans-4c-box-throttle, written by census-propose (#369). census-ruling-plans-4c-box-throttle, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md.
-# 5 body, 1 sites, 5 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 6 body, 1 sites, 6 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy 1293418f63bd169e58e39135d25e13bf6a0d565408ab296a0a7dba4d56bea545 internal/console/accountplans.go Store.SetAccountPlan legacy accepted-legacy accepted-legacy;rev3=PROPOSED-design-plans-and-caps;basis=root-input; console SQL on its own account_plans table, as its store siblings (J4).;rev3=census-ruling-plans-4c-box-throttle;basis=the upsert also clears the account's throttle (plans 4c, Astra finding 3), so a plan change publishes without it. The same statement on the same table; no read added. file:QueryRow@442 d04a8612067805ec734be89e2395bcb4c98e9f0a7467551159d193dc903dad92
@legacy 46b871d05b4fb6fb8407e654f710bfb7b8cc4eff4d2437ba590868af7153825b internal/console/store.go Store.migrate legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-email-signin;identity=the console (cmd/console serve under console.service, user carlos-console);basis=adds the sessions.method column (default keymail, the backfill) and calls migrateEmailSignin; SQLite DDL on CONSOLE_DB; the existing site moves;rev3=census-ruling-plans-4-notices-grace;basis=calls migratePlanGrace last, which creates the console's own plan_cap_state table (plans 4a). No read added here; the new store units are the plans-4a-store decision.;rev3=census-ruling-plans-4c-box-throttle;basis=adds the additive account_plans.throttle column (plans 4c). No read added. file:Exec@12017,file:Exec@18238 a976387d28e2b337252ca60039236a457fb99efedb6dda8c377ae30810618969
-@legacy a05f00ade662b8e2faf3000592c1843452161a3f7f160a52278b19f195654fc3 internal/edge/edge.go Edge.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the rate limit on the serving path, and on an upgrade planUpgradeAdmit plus trackUpgrade (plans 4c); the new reads live in those units (plans-4c-units decision). The same read sites here. registry:Gate@13604,registry:Gate@13664,registry:Gate@13722,registry:Host@13707,registry:ImportGate@17599,registry:Kind@11787,registry:Kind@17570,whole:Route@10017,whole:Route@11790,whole:Route@12348,whole:Route@12443,whole:Route@12519,whole:Route@12563,whole:Route@13607,whole:Route@13667,whole:Route@13710,whole:Route@13725,whole:Route@15358,whole:Route@17573,whole:Route@17602,whole:Route@19483,whole:Route@9805 6c87faf01fddd84a6c42d74cf87a6d67bd03f47775a36d588c37bc26d85952f8
+@legacy 861cc1bdc7d7e5e75e572075e6e3a023fdffbc6c0cdd50599c19bba252434fa7 internal/edge/edge.go Edge.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the response cache, and on an upgrade trackUpgrade then planUpgradeAdmit (plans 4c, Astra findings 1 and 2); the new reads live in those units (plans-4c-units decision). The same read sites here. registry:Gate@13604,registry:Gate@13664,registry:Gate@13722,registry:Host@13707,registry:ImportGate@17917,registry:Kind@11787,registry:Kind@17888,whole:Route@10017,whole:Route@11790,whole:Route@12348,whole:Route@12443,whole:Route@12519,whole:Route@12563,whole:Route@13607,whole:Route@13667,whole:Route@13710,whole:Route@13725,whole:Route@15358,whole:Route@17891,whole:Route@17920,whole:Route@19752,whole:Route@9805 cfa604eaff1bcd14b46eb47275582f439c4ef6fbf361feca47d6ab50a699de8f
@legacy 1c79743a0774549ee9a2cd99a5352366846efb032c6bdd3ee78eafdaca75eb94 internal/host/plans_pass.go plansPass legacy accepted-legacy accepted-legacy;rev3=PROPOSED-plans-2-box-limits;basis=root-route; the agent's plans pass, serialised by its own mutex, reads its own routes' accounts and two bucket objects (the plans marker, each account's limits record) into a cache; planIdleFor only narrows the activator's idle window. No root decision.;rev3=census-ruling-plans-4c-box-throttle;basis=keeps each account's published throttle from its limits record in the cache beside its limits, and tells planAwakeThrottled when an account first becomes awake-throttled (plans 4c). The same bucket objects; no read added. registry:Kind@817,whole:Route@803,whole:Route@886 dddd6f55b1b502736e025bafffeffdbfabaa65b81b23e5534ff780f70490e3f6
-@legacy f5f1bad6c12be3fc763f539b57a17f9076ff3770b5c09f4bc360bbfd17b51990 internal/activator/activator.go Service.sweepOnce legacy accepted-legacy accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).;rev3=census-ruling-plans-4c-box-throttle;basis=after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. registry:Hibernate@12971,registry:Hibernate@22142,registry:Hibernate@5124,registry:Hibernate@6794,registry:Hibernate@9319,registry:Host@22211,registry:Host@22269,registry:Host@22641,registry:Host@22734,registry:Host@23469,registry:Host@23551,registry:Host@24616,registry:Host@24795,registry:Host@24844,registry:NextDue@23424,registry:Status@22158,whole:Route@10074,whole:Route@12973,whole:Route@14906,whole:Route@16616,whole:Route@16806,whole:Route@17099,whole:Route@17271,whole:Route@17418,whole:Route@21629,whole:Route@23138,whole:Route@23478,whole:Route@23485,whole:Route@24431,whole:Route@24828,whole:Route@5126,whole:Route@6796,whole:Route@7230,whole:Route@9321 3180204acfaf05f0798b0e22bc2eda7e64b0375a4b1c1b62a09cd5c64fa7dab8
+@legacy a5b20c5f01a9b0fee35ea1ae606e5ec12c9620bc92878dafd3be6cc26ecad970 internal/activator/activator.go Service.sweepOnce legacy accepted-legacy accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).;rev3=census-ruling-plans-4c-box-throttle;basis=after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. This bypasses the inflight and held-for-tick protections the idle stop keeps, on purpose: escalated to the census owner by Astra. registry:Hibernate@12971,registry:Hibernate@22142,registry:Hibernate@5124,registry:Hibernate@6794,registry:Hibernate@9319,registry:Host@22211,registry:Host@22269,registry:Host@22641,registry:Host@22734,registry:Host@23469,registry:Host@23551,registry:Host@24616,registry:Host@24795,registry:Host@24844,registry:NextDue@23424,registry:Status@22158,whole:Route@10074,whole:Route@12973,whole:Route@14906,whole:Route@16616,whole:Route@16806,whole:Route@17099,whole:Route@17271,whole:Route@17418,whole:Route@21629,whole:Route@23138,whole:Route@23478,whole:Route@23485,whole:Route@24431,whole:Route@24828,whole:Route@5126,whole:Route@6796,whole:Route@7230,whole:Route@9321 3180204acfaf05f0798b0e22bc2eda7e64b0375a4b1c1b62a09cd5c64fa7dab8
internal/activator/activator.go type Service authority B,C,D,F,J4 rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added. 88d6649cac4f1bc814ca926fb5e50fa0e6188b5b0c0ff5d13c0322d905aaa5ae
+internal/console/accountplans.go Store.SetAccountPlan legacy accepted-legacy accepted-legacy;rev3=PROPOSED-design-plans-and-caps;basis=root-input; console SQL on its own account_plans table, as its store siblings (J4).;rev3=census-ruling-plans-4c-box-throttle;basis=the upsert also clears the account's throttle (plans 4c, Astra finding 3), so a plan change publishes without it. The same statement on the same table; no read added. file:QueryRow@442 d04a8612067805ec734be89e2395bcb4c98e9f0a7467551159d193dc903dad92
internal/console/store.go Store.migrate legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-email-signin;identity=the console (cmd/console serve under console.service, user carlos-console);basis=adds the sessions.method column (default keymail, the backfill) and calls migrateEmailSignin; SQLite DDL on CONSOLE_DB; the existing site moves;rev3=census-ruling-plans-4-notices-grace;basis=calls migratePlanGrace last, which creates the console's own plan_cap_state table (plans 4a). No read added here; the new store units are the plans-4a-store decision.;rev3=census-ruling-plans-4c-box-throttle;basis=adds the additive account_plans.throttle column (plans 4c). No read added. file:Exec@12017,file:Exec@18238 a976387d28e2b337252ca60039236a457fb99efedb6dda8c377ae30810618969
-internal/edge/edge.go Edge.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the rate limit on the serving path, and on an upgrade planUpgradeAdmit plus trackUpgrade (plans 4c); the new reads live in those units (plans-4c-units decision). The same read sites here. registry:Gate@13604,registry:Gate@13664,registry:Gate@13722,registry:Host@13707,registry:ImportGate@17599,registry:Kind@11787,registry:Kind@17570,whole:Route@10017,whole:Route@11790,whole:Route@12348,whole:Route@12443,whole:Route@12519,whole:Route@12563,whole:Route@13607,whole:Route@13667,whole:Route@13710,whole:Route@13725,whole:Route@15358,whole:Route@17573,whole:Route@17602,whole:Route@19483,whole:Route@9805 6c87faf01fddd84a6c42d74cf87a6d67bd03f47775a36d588c37bc26d85952f8
-internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-seeded-instances;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with wireSeedPlacement called in the activator start's Configure step, before armMovesPass, and the startup sweep's result stored for the import rollback in Recover; read sites unchanged, offsets moved; main's B,C,D,F authority retained PROPOSED E46: captured claim selection and root journal mutation; root RPC outside service host exclusion; SQL/route data never grants root authority. Executing identity: service controller; root for inventory/retirement callbacks.;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=passes the agent's log sink to armRunsPass; reads unchanged;rev3=census-ruling-db-region-forward-1;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=arms the db-reads loop (armDBReads) beside armRunsPass in the activator start's Configure step; reads unchanged, offsets moved; main's authority retained;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=arms the change index (armChangeIndex) and starts the record view's backstop loop before the loops that read through it, and hands the edge the watch loader (edge.WithChangeWatch); read sites unchanged at the same offsets;rev3=census-ruling-edge-request-records;basis=builds the edge request recorder against the existing log sink and data dir (newRequestRecorder, passed os.Getenv and time.Now) and starts reqrecLoop on a minute ticker; no read added;rev3=census-ruling-design-edge-rate-limit-358;basis=arms the edge's plan rate-ceiling hook, e.SetRateCeilingFor(planRateCeilingFor), right after EnableUsage; read sites unchanged (5), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=arms svc.SetMaxRunFor(planMaxRunFor) beside SetIdleFor, and e.SetPlanThrottleFor(planThrottleFor) plus the planAwakeThrottled close hook beside SetRateCeilingFor (plans 4c). No read added. file:Exec@13802,file:Open@731,registry:App@10065,whole:Route@10057,whole:Route@23594 31c63c6150eb0d0099692257dcd7c46dd637cfbb6967ec76d552e461d229d038
+internal/edge/edge.go Edge.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-seeded-instances;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with the import gate checked after the door's scope and a gated row left out of the response cache; serving only;rev3=census-ruling-edge-request-records;basis=one more call in the observer defer, observeRecords(up.route, ...), passing on the route the defer already holds; no new kind of read;rev3=census-ruling-design-edge-rate-limit-358;basis=calls rateAdmit twice, and an admitted request holds a slot on both paths: on the upgrade path before the activator or proxy (the handshake holds its slot through slotWriter, given back at the first final answer or at the reverse proxy's hijack on a 101, so an open WebSocket is not counted; released by a defer), and on the ordinary path after the response-cache check and before the activator and proxy (an admitted request holds a slot through slotWriter, released by a defer); a refusal is a 429 written there and returns; the upgrade path's comment now names slotWriter as its one wrapper; one comment on the door mark reworded; read sites unchanged (22: main's 21 plus edge-request-records' observeRecords pass of the route), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=calls planThrottleAdmit before the response cache, and on an upgrade trackUpgrade then planUpgradeAdmit (plans 4c, Astra findings 1 and 2); the new reads live in those units (plans-4c-units decision). The same read sites here. registry:Gate@13604,registry:Gate@13664,registry:Gate@13722,registry:Host@13707,registry:ImportGate@17917,registry:Kind@11787,registry:Kind@17888,whole:Route@10017,whole:Route@11790,whole:Route@12348,whole:Route@12443,whole:Route@12519,whole:Route@12563,whole:Route@13607,whole:Route@13667,whole:Route@13710,whole:Route@13725,whole:Route@15358,whole:Route@17891,whole:Route@17920,whole:Route@19752,whole:Route@9805 cfa604eaff1bcd14b46eb47275582f439c4ef6fbf361feca47d6ab50a699de8f
+internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-seeded-instances;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with wireSeedPlacement called in the activator start's Configure step, before armMovesPass, and the startup sweep's result stored for the import rollback in Recover; read sites unchanged, offsets moved; main's B,C,D,F authority retained PROPOSED E46: captured claim selection and root journal mutation; root RPC outside service host exclusion; SQL/route data never grants root authority. Executing identity: service controller; root for inventory/retirement callbacks.;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=passes the agent's log sink to armRunsPass; reads unchanged;rev3=census-ruling-db-region-forward-1;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=arms the db-reads loop (armDBReads) beside armRunsPass in the activator start's Configure step; reads unchanged, offsets moved; main's authority retained;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=arms the change index (armChangeIndex) and starts the record view's backstop loop before the loops that read through it, and hands the edge the watch loader (edge.WithChangeWatch); read sites unchanged at the same offsets;rev3=census-ruling-edge-request-records;basis=builds the edge request recorder against the existing log sink and data dir (newRequestRecorder, passed os.Getenv and time.Now) and starts reqrecLoop on a minute ticker; no read added;rev3=census-ruling-design-edge-rate-limit-358;basis=arms the edge's plan rate-ceiling hook, e.SetRateCeilingFor(planRateCeilingFor), right after EnableUsage; read sites unchanged (5), offsets moved; no read added;rev3=census-ruling-plans-4c-box-throttle;basis=arms svc.SetMaxRunFor(planMaxRunFor) beside SetIdleFor, and e.SetPlanThrottleFor(planThrottleFor), e.SetPlanGovernedFor(planGoverned) and the planAwakeThrottled close hook beside SetRateCeilingFor (plans 4c). No read added. file:Exec@13802,file:Open@731,registry:App@10065,whole:Route@10057,whole:Route@23594 2f48a4807916d7cfb85d44f906948c0023f0324ddf1a266b972af8d0a9fed6fe
internal/host/plans_pass.go plansPass legacy accepted-legacy accepted-legacy;rev3=PROPOSED-plans-2-box-limits;basis=root-route; the agent's plans pass, serialised by its own mutex, reads its own routes' accounts and two bucket objects (the plans marker, each account's limits record) into a cache; planIdleFor only narrows the activator's idle window. No root decision.;rev3=census-ruling-plans-4c-box-throttle;basis=keeps each account's published throttle from its limits record in the cache beside its limits, and tells planAwakeThrottled when an account first becomes awake-throttled (plans 4c). The same bucket objects; no read added. registry:Kind@817,whole:Route@803,whole:Route@886 dddd6f55b1b502736e025bafffeffdbfabaa65b81b23e5534ff780f70490e3f6
-internal/activator/activator.go Service.sweepOnce legacy accepted-legacy accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).;rev3=census-ruling-plans-4c-box-throttle;basis=after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. registry:Hibernate@12971,registry:Hibernate@22142,registry:Hibernate@5124,registry:Hibernate@6794,registry:Hibernate@9319,registry:Host@22211,registry:Host@22269,registry:Host@22641,registry:Host@22734,registry:Host@23469,registry:Host@23551,registry:Host@24616,registry:Host@24795,registry:Host@24844,registry:NextDue@23424,registry:Status@22158,whole:Route@10074,whole:Route@12973,whole:Route@14906,whole:Route@16616,whole:Route@16806,whole:Route@17099,whole:Route@17271,whole:Route@17418,whole:Route@21629,whole:Route@23138,whole:Route@23478,whole:Route@23485,whole:Route@24431,whole:Route@24828,whole:Route@5126,whole:Route@6796,whole:Route@7230,whole:Route@9321 3180204acfaf05f0798b0e22bc2eda7e64b0375a4b1c1b62a09cd5c64fa7dab8
+internal/activator/activator.go Service.sweepOnce legacy accepted-legacy accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).;rev3=census-ruling-plans-4c-box-throttle;basis=after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. This bypasses the inflight and held-for-tick protections the idle stop keeps, on purpose: escalated to the census owner by Astra. registry:Hibernate@12971,registry:Hibernate@22142,registry:Hibernate@5124,registry:Hibernate@6794,registry:Hibernate@9319,registry:Host@22211,registry:Host@22269,registry:Host@22641,registry:Host@22734,registry:Host@23469,registry:Host@23551,registry:Host@24616,registry:Host@24795,registry:Host@24844,registry:NextDue@23424,registry:Status@22158,whole:Route@10074,whole:Route@12973,whole:Route@14906,whole:Route@16616,whole:Route@16806,whole:Route@17099,whole:Route@17271,whole:Route@17418,whole:Route@21629,whole:Route@23138,whole:Route@23478,whole:Route@23485,whole:Route@24431,whole:Route@24828,whole:Route@5126,whole:Route@6796,whole:Route@7230,whole:Route@9321 3180204acfaf05f0798b0e22bc2eda7e64b0375a4b1c1b62a09cd5c64fa7dab8
@coverage internal/activator 16c5cfa55eaf72198f6185406e0ab6fa95d7a9d9006cd89c87e28650b1992a6b
-@coverage internal/console 939232f35c7eb28793b6fbcc1a4c1c117f402f677960221e9af22df6e520465f
-@coverage internal/edge 1c2f46148f9ade37a00bbe2f18cae89ce9d72a4ce6d0152a6806037171dae6b4
-@coverage internal/host 9abbe344d6e32a02113775d7b9d9b69f354e76c26f689b52fdf7e599711cafbb
+@coverage internal/console 245af1d7235885485a631ad9e50f26dba4106c064fa3bf304e0b78d90079b1de
+@coverage internal/edge f4139bcb3bdc1f6a13c2b8e8c6a788724aa867522d7a639dcf1043449b4c72d0
+@coverage internal/host 1a79b013206c0d98196686348122e8281285f0b0fefe83cd2c1b230d2f73bb07
@coverage internal/plans 69df5bdee2fff4d10a8ff01ba7d102f54ae1f9693fec3ac40506b80fb9805768
+@coverage internal/usage 24f3a53a77464a2d2a3c439f4481c1784a1ef7782a1d5b5f578d7e44a4fe1107
diff --git a/internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv b/internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv
index c3798a6d7..bd40f19cb 100644
--- a/internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv
+++ b/internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv
@@ -1,15 +1,21 @@
-# Census overlay plans-4c-units, written by hand: seven new units of the plan throttle (plans 4c), a decision. census-ruling-plans-4c-units; the card is docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md.
+# Census overlay plans-4c-units, written by hand: ten new units of the plan throttle (plans 4c), a decision. census-ruling-plans-4c-units; the card is docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md.
@legacy 9cff55a799d0e60ca9f87136ddacce145d9e906a708308e5241515caa81da999 internal/console/accountplans.go Store.SetAccountThrottle legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=root-input; console SQL on its own account_plans table, as its store siblings (J4); stores the account's plan throttle and bumps the revision the publish pass reads (plans 4c). file:Exec@259 ef845d77170669b221e19a6494f5a8f587ee966ae25425e2e7ff2912b0f29a5c
-@legacy 02fcb5127315bd985e99f0bee840a9e12a2a0782991461f467e3d9e92ec3bef5 internal/edge/planthrottle.go Edge.planThrottleAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: spends one token of a throttled account's shared in-memory bucket keyed 'plan:'+release.RouteAccount(row) and writes the rate limit's 429; logs the row's host, throttled. Grants nothing (plans 4c). registry:Host@409,registry:Host@464,whole:Route@281,whole:Route@412,whole:Route@467 5e637b4c2c1bce9bef3df42a31ae13dac49f7d33a97f8b53aca334ab359c8bc9
+@legacy 3f029515e7217870013d543067cda5f58779eb23a8af5f97bd062c7239546a34 internal/edge/planthrottle.go Edge.notePlanThrottled legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: counts one plan-throttle refusal on the usage meter (UsageMeter.RecordPlanThrottled, passed the row) and logs the row's host, throttled, as noteRateLimited does (plans 4c). registry:Host@172,registry:Host@220,whole:Route@132 0d7a8faf05ee9518e96cfd2350b1d4982b6b9d7764267276d409e0935008c997
+@legacy 3cf6775da772ee264d7420254a80e8fa4ed062a4f44811b2e0924daef820767f internal/edge/planthrottle.go Edge.planThrottleAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: spends one token of a throttled account's shared in-memory bucket keyed 'plan:'+release.RouteAccount(row) and writes the rate limit's 429, counted through notePlanThrottled. Grants nothing (plans 4c). whole:Route@281,whole:Route@400 476886e9f06ff8b1e39cfe113f4b310636518fc58e683beb3827189edd6af8a5
@legacy 3d4c8b3684fb3838dadeaffe82b3f2bef7df3da18c572bfbf247f2b6016b494d internal/edge/planthrottle.go Edge.planThrottleOf legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: asks the plan throttle hook (planThrottleFor, passed the row) whether an instance row's account is slowed down; door, hop-door and tunnel callers exempt as from the rate limit; reads only the row's kind (plans 4c). registry:Kind@129,whole:Route@132,whole:Route@353 0158379953353dcd65e108eb8168e55cb8fe4171ebc7ba1d63cb41b7999a2bd9
-@legacy a854df0790e8b62dfb52b78adb349c9d929d0909612b49dbdca77fc8239c4403 internal/edge/planthrottle.go Edge.planUpgradeAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: refuses a new upgrade for an awake-throttled account's instance row (the rate limit's 429), else planThrottleAdmit; logs the row's host (plans 4c). registry:Host@190,registry:Host@246,whole:Route@193,whole:Route@249 de8ab2d42da5e5f20f531d147cb1ac2322b132b29c97de45a80f75ede0695f97
-@legacy e17a31415335ebc7adf91536b3fb3e721aa897edadf007d978659de9f8161cfe internal/edge/planthrottle.go Edge.trackUpgrade legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: while a throttle hook is armed, wraps an instance row's upgrade request in a cancellable context registered under release.RouteAccount(row), so CloseAccountUpgrades can end it; reads only the row's kind (plans 4c). registry:Kind@120,whole:Route@123,whole:Route@208 6fa02cc9d7d09daa94d0d6d725d9852916d2ae52fdcbf41ffe44b492d6e40723
+@legacy 084b116f99077f9de68ac3d9de3dc91e4138ac7ea8abac04106794bc89c63b24 internal/edge/planthrottle.go Edge.planUpgradeAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: refuses a new upgrade for an awake-throttled account's instance row (the rate limit's 429, counted through notePlanThrottled), else planThrottleAdmit (plans 4c). whole:Route@173 b4921b4b5b07f8efe33b19fa770e5967d9d2d1fa52c5e9345c040c030c7bc9c2
+@legacy 3403dcb7a90dc428c31f75b43faeaa38e06d639d8a74325f34f0f479a3307eb3 internal/edge/planthrottle.go Edge.trackUpgrade legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: for an instance row whose account plans govern (planGoverned, passed the row), wraps the upgrade request in a cancellable context registered under release.RouteAccount(row), so CloseAccountUpgrades can end it (plans 4c). registry:Kind@128,whole:Route@131,whole:Route@168,whole:Route@235 4ec05529f11871f7ec117adce005cecaa10486922dfc42395cf1ea849378c713
+@legacy cacf061f941e1aff97f11a591b7bf0f93e2fcb18728b4d5fa22c5c6a597fb2b2 internal/edge/usagemeter.go UsageMeter.RecordPlanThrottled legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: RecordRateLimited's twin: adds one to the row's in-memory PlanThrottled counter, labelled with the row's account and app (plans 4c). registry:App@136,registry:Host@170,registry:Host@87,whole:Route@131 e2aa8eda9429824b36aa8313fa495ce718aedbda4d0a728e0b52e7fe3e8534bd
+@legacy d4f6b2f2bfed78a4306c87b30000cd1d17296a76acd934e547a36e7637c97847 internal/host/plans_pass.go planGoverned legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), as a hook armed in runAgent: planIdleFor's and planRateCeilingFor's twin, it reads the row's account (release.RouteAccount) and kind and the plans pass's in-memory cache; says whether the row's account has a limits record in the cache (plans on), so the edge tracks its upgrades only then. No root decision (plans 4c). whole:Route@89 7905844800553d44b33afe4f61c61199d075af6bc251da228cd5f9cdf16a5ae8
@legacy 5d88c05d4629f5bff8e2112acef89aa4aede8b28276bd324ce8307f43333c691 internal/host/plans_pass.go planMaxRunFor legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), as a hook armed in runAgent: planIdleFor's and planRateCeilingFor's twin, it reads the row's account (release.RouteAccount) and kind and the plans pass's in-memory cache; returns 15 minutes for an awake-throttled account's instance row, else 0, for the activator's continuous-awake ceiling. Only shortens; no root decision (plans 4c). whole:Route@84 66bab854b4d55d69b14dc3220bf42842e925054872848aff7644c1d0fd611256
@legacy 9e520471c29c0912e5b15071f0ea959411cc6f5d25970eb0c60ac948a9e2e387 internal/host/plans_pass.go planThrottleFor legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), as a hook armed in runAgent: planIdleFor's and planRateCeilingFor's twin, it reads the row's account (release.RouteAccount) and kind and the plans pass's in-memory cache; returns the account's published throttle while it is in force, for instance rows only. Only slows; no root decision (plans 4c). registry:Kind@69,whole:Route@256 e9d8aae73b5736f9d097d672e58442da5fbe993abf89d0747f12d4708fa22516
internal/console/accountplans.go Store.SetAccountThrottle legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=root-input; console SQL on its own account_plans table, as its store siblings (J4); stores the account's plan throttle and bumps the revision the publish pass reads (plans 4c). file:Exec@259 ef845d77170669b221e19a6494f5a8f587ee966ae25425e2e7ff2912b0f29a5c
-internal/edge/planthrottle.go Edge.planThrottleAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: spends one token of a throttled account's shared in-memory bucket keyed 'plan:'+release.RouteAccount(row) and writes the rate limit's 429; logs the row's host, throttled. Grants nothing (plans 4c). registry:Host@409,registry:Host@464,whole:Route@281,whole:Route@412,whole:Route@467 5e637b4c2c1bce9bef3df42a31ae13dac49f7d33a97f8b53aca334ab359c8bc9
+internal/edge/planthrottle.go Edge.notePlanThrottled legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: counts one plan-throttle refusal on the usage meter (UsageMeter.RecordPlanThrottled, passed the row) and logs the row's host, throttled, as noteRateLimited does (plans 4c). registry:Host@172,registry:Host@220,whole:Route@132 0d7a8faf05ee9518e96cfd2350b1d4982b6b9d7764267276d409e0935008c997
+internal/edge/planthrottle.go Edge.planThrottleAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: spends one token of a throttled account's shared in-memory bucket keyed 'plan:'+release.RouteAccount(row) and writes the rate limit's 429, counted through notePlanThrottled. Grants nothing (plans 4c). whole:Route@281,whole:Route@400 476886e9f06ff8b1e39cfe113f4b310636518fc58e683beb3827189edd6af8a5
internal/edge/planthrottle.go Edge.planThrottleOf legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: asks the plan throttle hook (planThrottleFor, passed the row) whether an instance row's account is slowed down; door, hop-door and tunnel callers exempt as from the rate limit; reads only the row's kind (plans 4c). registry:Kind@129,whole:Route@132,whole:Route@353 0158379953353dcd65e108eb8168e55cb8fe4171ebc7ba1d63cb41b7999a2bd9
-internal/edge/planthrottle.go Edge.planUpgradeAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: refuses a new upgrade for an awake-throttled account's instance row (the rate limit's 429), else planThrottleAdmit; logs the row's host (plans 4c). registry:Host@190,registry:Host@246,whole:Route@193,whole:Route@249 de8ab2d42da5e5f20f531d147cb1ac2322b132b29c97de45a80f75ede0695f97
-internal/edge/planthrottle.go Edge.trackUpgrade legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: while a throttle hook is armed, wraps an instance row's upgrade request in a cancellable context registered under release.RouteAccount(row), so CloseAccountUpgrades can end it; reads only the row's kind (plans 4c). registry:Kind@120,whole:Route@123,whole:Route@208 6fa02cc9d7d09daa94d0d6d725d9852916d2ae52fdcbf41ffe44b492d6e40723
+internal/edge/planthrottle.go Edge.planUpgradeAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: refuses a new upgrade for an awake-throttled account's instance row (the rate limit's 429, counted through notePlanThrottled), else planThrottleAdmit (plans 4c). whole:Route@173 b4921b4b5b07f8efe33b19fa770e5967d9d2d1fa52c5e9345c040c030c7bc9c2
+internal/edge/planthrottle.go Edge.trackUpgrade legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: for an instance row whose account plans govern (planGoverned, passed the row), wraps the upgrade request in a cancellable context registered under release.RouteAccount(row), so CloseAccountUpgrades can end it (plans 4c). registry:Kind@128,whole:Route@131,whole:Route@168,whole:Route@235 4ec05529f11871f7ec117adce005cecaa10486922dfc42395cf1ea849378c713
+internal/edge/usagemeter.go UsageMeter.RecordPlanThrottled legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: RecordRateLimited's twin: adds one to the row's in-memory PlanThrottled counter, labelled with the row's account and app (plans 4c). registry:App@136,registry:Host@170,registry:Host@87,whole:Route@131 e2aa8eda9429824b36aa8313fa495ce718aedbda4d0a728e0b52e7fe3e8534bd
+internal/host/plans_pass.go planGoverned legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), as a hook armed in runAgent: planIdleFor's and planRateCeilingFor's twin, it reads the row's account (release.RouteAccount) and kind and the plans pass's in-memory cache; says whether the row's account has a limits record in the cache (plans on), so the edge tracks its upgrades only then. No root decision (plans 4c). whole:Route@89 7905844800553d44b33afe4f61c61199d075af6bc251da228cd5f9cdf16a5ae8
internal/host/plans_pass.go planMaxRunFor legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), as a hook armed in runAgent: planIdleFor's and planRateCeilingFor's twin, it reads the row's account (release.RouteAccount) and kind and the plans pass's in-memory cache; returns 15 minutes for an awake-throttled account's instance row, else 0, for the activator's continuous-awake ceiling. Only shortens; no root decision (plans 4c). whole:Route@84 66bab854b4d55d69b14dc3220bf42842e925054872848aff7644c1d0fd611256
internal/host/plans_pass.go planThrottleFor legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4c-units;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), as a hook armed in runAgent: planIdleFor's and planRateCeilingFor's twin, it reads the row's account (release.RouteAccount) and kind and the plans pass's in-memory cache; returns the account's published throttle while it is in force, for instance rows only. Only slows; no root decision (plans 4c). registry:Kind@69,whole:Route@256 e9d8aae73b5736f9d097d672e58442da5fbe993abf89d0747f12d4708fa22516
diff --git a/internal/usage/edge.go b/internal/usage/edge.go
index 68ab20eb8..f37bc0987 100644
--- a/internal/usage/edge.go
+++ b/internal/usage/edge.go
@@ -40,6 +40,10 @@ type EdgeRow struct {
// added to it. Additive and omitempty, for the hop counters' reason.
RateShed int64 `json:"rate_shed,omitempty"`
RateCeiling int64 `json:"rate_ceiling,omitempty"`
+ // PlanThrottled counts requests refused because the account is slowed
+ // down by its plan (plans 4c), apart from the per-instance rate limit's
+ // two reasons. Inside Requests; additive and omitempty.
+ PlanThrottled int64 `json:"plan_throttled,omitempty"`
}
// SetOwner labels the row with the route's current account and app. When
@@ -51,7 +55,7 @@ type EdgeRow struct {
// AddDeltas).
func (r *EdgeRow) SetOwner(account, app string) {
if r.Account != account || r.App != app {
- r.RateShed, r.RateCeiling = 0, 0
+ r.RateShed, r.RateCeiling, r.PlanThrottled = 0, 0, 0
}
r.Account, r.App = account, app
}
@@ -102,6 +106,7 @@ func (d *EdgeDay) AddDeltas(hour string, deltas map[string]EdgeRow) {
row.HopBytesOut += delta.HopBytesOut
row.RateShed += delta.RateShed
row.RateCeiling += delta.RateCeiling
+ row.PlanThrottled += delta.PlanThrottled
rows[host] = row
}
}
diff --git a/internal/usage/edge_test.go b/internal/usage/edge_test.go
index 97f1a382f..c3393a437 100644
--- a/internal/usage/edge_test.go
+++ b/internal/usage/edge_test.go
@@ -154,3 +154,17 @@ func TestUpsertEdgeDayEmptyDeltasIsNoop(t *testing.T) {
t.Fatalf("noop wrote %v", keys)
}
}
+
+func TestPlanThrottledSumsAndResetsWithOwner(t *testing.T) {
+ var d EdgeDay
+ d.AddDeltas("10", map[string]EdgeRow{"h": {Account: "bdk", App: "web", PlanThrottled: 2}})
+ d.AddDeltas("10", map[string]EdgeRow{"h": {Account: "bdk", App: "web", PlanThrottled: 3}})
+ if got := d.Hours["10"]["h"].PlanThrottled; got != 5 {
+ t.Fatalf("summed = %d, want 5", got)
+ }
+ r := d.Hours["10"]["h"]
+ r.SetOwner("bdm", "web")
+ if r.PlanThrottled != 0 {
+ t.Fatal("a new owner sees the old owner's plan-throttle count")
+ }
+}