carlos / platform Public

instance-usage

Bytes and requests served per instance, behind a read-only usage route (#1519). Consumer: Patrix's hosted dashboard (plaza's billing tick), enforcing monthly bandwidth from January 2027.

What changes

  • Edge meter (internal/edge/usagemeter.go): besides the per-host rows, counts each exchange under {UTC hour it completed, account, app, instance host} when the route is an instance. The far asset catch attributes only its own primary; an alias it delivers is unattributed ("").
  • Box flush (internal/host/instance_usage.go): CAS-merges each drained batch into usage/instances/<box>/<date>/<account>/<app>.json, exactly once per batch and object (writer id per process, batch id per drain, applied markers kept forever), oldest batch first per object, nothing started for buckets older than 24 h (dropped and counted as instance_usage_dropped_bytes on the box status). CARLOS_INSTANCE_USAGE=off in host.env stops counting and writing. Nothing under usage/edge/ changes (pinned by golden tests).
  • Console (internal/console/usagefrom.go, apiusage.go): usage/instances/@from.json holds the first whole month attribution is valid, written when the hostname history is verified active and moved forward only on a real break. GET /api/cli/apps/{account}/{app}/usage?month=YYYY-MM sums one app's objects for a month: a lower bound (Paul's ruling), 503 on any read fault (filed as the InstanceUsageRead job), 409 before from or with the history not active, at most 10,000 instances, memo keyed by account, app and month.
  • Role usage (internal/svcrole): outside Admin's union, one door (Exactly(Usage, Instance, Operate, Admin)), bound to one app, minted and rotated only while the switch is on; never offered on the browser form.
  • CLI carlos usage --app <a> [--month YYYY-MM] [--json], docs in docs/site/cli.md, parity row (gap; console view filed as #1536).
  • Switch: the route, the mint and @from sit behind CONSOLE_INSTANCE_USAGE=true (off by default). Boxes count from the release.

Also: getJSON in the CLI now errors past 1 MiB instead of returning a silently truncated body (apimode_limit.go); a few functions moved verbatim to satisfy the code-health ratchet (internal/host/canary_count.go, internal/console/hostnorm.go).

Review history

  • Design: Astra rounds 1-3 (spec rev 5, merged 9673143).
  • Plan: Astra rounds 1-3, all NOT READY with a P1 in a new family each round; all fixed. No fourth round (my call, posted on #1519; Paul may ask for one).
  • Per-task Astra (stopping rule 3): Task 2 meter, Task 3 flush, Task 5 role, Task 6 route: each READY AFTER FIXES in round 1, P2s fixed.
  • Census: Astra APPROVED every unit and envelope, round 1, recorded on #280.
  • Whole branch: Astra READY, round 1, no findings.
  • Copy: Luna (one change); UX pass in docs/superpowers/notes/instance-usage-copy.md.
  • Follow-up (P3): the oversized-object log line in usagedays.go names the economics sweep.

Testing: targeted tests per task (incl. a randomized exactly-once simulation and -race on the meter and flush), an end-to-end test across a month boundary, code-health and staticcheck clean, CI on amadan (see the CI tab).

Rollout (not done here): dev only after this merges and only if dev's hostname history is active (spec §12); flagship 2026-12-14 on Paul's go; first counted month January 2027.

Human

Bytes and requests per instance behind a read-only usage route (#1519). Plan written; plan review round 1 under way.

Commits 36
Discussions 0 0 open
Tasks 12/12 done

Activity