carlos / platform Public

Usage attribution is box-local: census, fleetMeters, statements and status --instances charge remote tenants to the platform closed

Found by the console remote-instances investigation (2026-10-25, origin/main c3a34e32). The app-page half is fixed on branch console-remote-instances; this half is billing, so it is filed here rather than folded in.

What happens. The usage readings are fleet-wide: every box writes metrics/boxes/<box>/raw/<hour> and LoadMetrics sweeps all of it. But the routes those readings are attributed against come from the console box's own registry:

  • carlos status --instances (internal/console/apistatusinstances.go): account per unit from openPassRegistry (:106). A unit sampled on another box matches no route, falls through routeForUnit's unmatched case, and is charged to the ops account as platform overhead.
  • censusPass (internal/console/economicspass.go:99), fleetMeters and statementsPass count routes and charge usage against the same local registry, so remote tenants are undercounted in economics.

Why it is live now. The doc comment at apistatusinstances.go:34-49 and the --instances section of docs/site/cli.md call the trap inert because "both production deployments are single-box today". That stopped being true when AU went live (au.bdk.oncarlos.com on barbara-tinkering since 2026-08-15) and again on 2026-10-21 when all 12 bdn instances moved to iris-clockmaking (UK). Flagship registries on 2026-10-25: annie (console box) has 0 bdn rows; iris has 12 bdn instance region=uk; barbara has 2 (au.bdk, taskmonger.bdk).

A ready source. control/edges/<box>.json already carries account and app for every host the box serves (checked on iris: 12 bdn home hosts, each with account and app). Bucket instance records carry them too. Either is a region-neutral attribution source; the old plan was routes-as-bucket-records (PR #137, unmerged).

Request budget note for whoever designs it (memory s3-requests-cost-money): the edges files are already read on the change index's control/edges scope, so attribution from them need add no polling.

Spec-sized; wants a design and Paul's call on how statements already issued are treated.

Fix proposal (read-only investigation, 2026-10-26). Not built: billing is sensitive, so this waits for Paul's go.

Which numbers are wrong

Every compute meter is attributed by matching a sampled unit (carlos-exec@<host>, carlos-app@<host>.service) against the console box's own registry (unitOwner → routeForUnit, internal/console/economicspass.go). A unit with no local route is charged to the ops account (bab) as platform overhead. That affects:

  • Statements (statementsPass, hourly, create-or-replace for the month to date): instance_hours, cpu_core_hours, mem_gb_hours.
  • Plan caps: the awake-hours cap reads instance_hours from the statement (monthMeters, planmeasure.go), so a remote tenant's awake hours never count against its cap.
  • Census (censusPass, daily, create-only): apps and routes per account, which feed app_months.
  • The economics page (LoadEconomics → sweepUsage with loadRoutesForEconomics) and carlos status --instances, both live reads.

Correct as they are: egress, requests and backhaul (each edge row carries its own account), storage (bucket prefix), fleet box-hours, and the running-things cap (it counts records).

It is worse than "remote tenants". The statement re-sweeps the whole month against today's routes, so moving a tenant off the console box also wipes the compute it used on the console box earlier in the month. Flagship October, from the metrics day rollups:

| | instance-hours | core-hours | mem GB-hours | |---|---|---|---| | bdn on annie, 1-21 Oct (before the UK move) | 738.2 | 0.29 | 55.4 | | bdn on iris, 21-26 Oct | 7.0 | 0.00 | 0.4 | | bdk on annie | 1.5 | 0.00 | 0.0 |

bdn's October statement (usage/accounts/bdn/2026-10.json, updated 17:38Z today) has no instance_hours, cpu_core_hours or mem_gb_hours at all. All 745 hours sit in bab's. September's statement (1849.5 instance-hours) is right, because bdn was on annie all month. Census: bdn is missing from every census day since 2026-10-22 (it was apps 9, routes 12 up to the 21st), so bdn's October app_months reads 5.84 instead of about 7.5. barbara has no metered tenant time in October (au.bdk slept all month).

Where the right data is

  • Instance and sidecar records (apps/<sqid>/<app>/{instances,sidecars}/<host>.json): region-neutral, and they outlive a move. A unit's name is derived from its host (activator.UnitName, ExecName), so records map unit → account/app on any box. Read through the record view snapshot (change index, armed on flagship), they cost no new requests.
  • Box reports through the remoteFacts accessor (pageBoxReports, cached 60 s): the account and app of every host a box serves, for hosts with no record (apex mints, hand routes). Per box, so the box that sampled the unit decides.
  • The console box's registry stays as the last source, for named units (console.service) and local hand routes.

The change

  1. A unitAttribution built once per pass: local registry rows with a named Unit first, then records, then fresh box reports for the sampling box, then the ops fallback. sweepUsage, unitOwner and handleAPIStatusInstances take it instead of []registry.Route.
  2. censusPass counts per account from records, plus local rows that no record covers (deduplicated by host).
  3. Remove the "single-box today, so inert" comments (apistatusinstances.go, economicspass.go) and the matching limit note in docs/site/cli.md.

Size: about 200 lines of console code and 250 of tests, all in internal/console. No box change, no new polling. One Astra review (billing is a gate under the stopping rules).

Decision for Paul

Statements are month-to-date and create-or-replace, so the first hourly pass after the release rewrites October: bdn gains about 745 instance-hours, bab loses the same. Nothing is invoiced from statements today; they feed the economics page and the awake-hours cap. Options:

  • (a) Recommended: let the open month correct itself, and leave closed months as written (September and earlier are right anyway).
  • (b) Apply the new attribution only from a cutover date, so October keeps today's split. This needs extra code, and it keeps a known-wrong number.
  • Separately, whether to backfill the create-only census days 2026-10-22 to 2026-10-26 (it is a one-off rewrite of five objects, so it needs approval).

Check before the roll: if bdn's or bdk's plan has an awake-hours cap, the corrected statement could cross a warning threshold mid-month.

Built and merged: 70930b64 (branch usage-attribution-390). Not released yet: it takes effect with the next console release, and no box release is needed.

Rule as built (changed from the proposal after review). A box reading is an account's only on evidence that holds for the whole time the reading covers:

  • the box's tenant tag on a live reading (remote-instance-metrics); day rollups carry none.
  • a host under <...>.<sqid>.<apps domain>, or a sidecar's <name>.<app>.<sqid>.sidecar.internal, for a live account. Only that account can ever hold such a name: self-serve domains are pinned to it, and #215 refuses another account's namespace at attach.

Other tenant workloads are counted against no account and logged once per sweep: custom-domain instances with no tag, and units stamped on a tenant's console-box route. Platform units stay with ops.

The census now counts instance and sidecar records on every box, plus console-box routes no record covers. It skips Trash and fleet placements, and refuses the day on any unreadable record.

Why not records, as proposed. Astra round 1 found three P1s in one family. A record's created_at is not process ownership: a box with no lifetime judge keeps a predecessor's row and process after a successor's record exists. A box report or console route says who holds a host now, not last week. A stamped unit name is no identity on another box. Round 2: READY.

Effects at the release

  • October rewrites at the first statements pass: bdn's compute comes back, bab's 745 hours go. bdn's hosts are all in its namespace.
  • Census days 22-26 Oct stay as written (no backfill).
  • The 5 flagship instance records on custom domains now count against no account. Restoring them needs boxes to roll their tags into hourly rollups. That is a box change, filed as a follow-up below.

Cap check. The flagship console has no CARLOS_PLAN_CATALOG or CARLOS_BILLING, and there is no control/plans.json. Plans are off, so no cap can trip.

Tests. Production-wired:

  • a two-box tenant;
  • a hostname reused across accounts;
  • a same-account recreate;
  • a statement re-run across a move;
  • unknown units;
  • status across boxes;
  • the census.

12 mutants were killed, including on the attribution key. Census approved on #280.

Follow-ups

  1. Box: carry the tenant tag into HourAgg when every sample in the hour has the same tag (box release, census card).
  2. A stale comment in status_instances.go (Astra P3).

Closing.