carlos / platform Public

Instance usage: bytes per instance behind a read-only usage route

Counts edge bytes and requests per instance by the UTC hour each
exchange completed (#1519). Boxes CAS-merge each batch exactly once into
usage/instances/<box>/<date>/<account>/<app>.json; nothing under
usage/edge/ changes. The console writes usage/instances/@from.json once
the hostname history is verified active and serves
GET /api/cli/apps/{account}/{app}/usage?month=YYYY-MM: a lower bound,
whole UTC months from @from, at most 10,000 instances. A new usage role
reaches only that door for one app; carlos usage reads it. Off by
default: CONSOLE_INSTANCE_USAGE=true turns on the route, the mint and
@from; CARLOS_INSTANCE_USAGE=off stops a box counting.

Reviews: plan Astra R1-R3; per-task Astra on the meter, flush, role and
route (round 1, P2s fixed); census approved by Astra on #280; whole
branch Astra READY round 1. Copy through Luna. Spec:
docs/superpowers/specs/2026-11-29-instance-usage-design.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from instance-usage into main.
claude agent, operated by paul@keymail.dev 43dce353f9c1e3ca6b28f0abb2091e4e61fd0fab parent 963d90c
91 files changed, +8,145 −212
  • apimode.go +1 −20
  • apimode_limit.go +52 −0
  • approved_usage_copy_test.go +149 −0
  • cmd/console/instanceusage_test.go +89 −0
  • cmd/console/main.go +29 −6
  • commands.go +1 −0
  • commands_test.go +2 −0
  • docs/parity.md +11 −2
  • docs/site/cli.md +26 −0
  • docs/superpowers/notes/census-proposal-instance-usage.md +47 −0
  • docs/superpowers/notes/instance-usage-copy.md +112 −0
  • docs/superpowers/plans/2026-11-29-instance-usage.md +721 −0
  • docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R1.md +24 −0
  • docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md +33 −0
  • docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R3.md +18 −0
  • docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R2.md +93 −0
  • docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R3.md +102 −0
  • docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan.md +80 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-branch-R1.md +7 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-census-R1.md +49 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task2-R1.md +11 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task3-R1.md +17 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task5-R1.md +17 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task6-R1.md +27 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-branch.md +77 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-census.md +41 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task2.md +59 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task3.md +67 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task5.md +66 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task6.md +75 −0
  • internal/console/apilinks_test.go +6 −0
  • internal/console/apiservices.go +21 −0
  • internal/console/apiusage.go +377 −0
  • internal/console/apiusage_e2e_test.go +100 −0
  • internal/console/apiusage_test.go +684 −0
  • internal/console/claim_workers.go +6 −0
  • internal/console/economics_instances_compat_test.go +64 −0
  • internal/console/hostnorm.go +43 −0
  • internal/console/jobs.go +19 −0
  • internal/console/jobs_test.go +23 −7
  • internal/console/linkedpolicy.go +3 −0
  • internal/console/links_auth_test.go +2 −1
  • internal/console/platform_credentials_test.go +20 −0
  • internal/console/routedecls.go +12 −1
  • internal/console/routedecls_test.go +2 −1
  • internal/console/server.go +6 −35
  • internal/console/svcpage.go +29 −2
  • internal/console/svcprincipal.go +64 −0
  • internal/console/svcroutes_test.go +133 −16
  • internal/console/usagedays.go +9 −2
  • internal/console/usagefrom.go +255 −0
  • internal/console/usagefrom_test.go +558 −0
  • internal/console/usagerole_test.go +288 −0
  • internal/edge/asset_far_test.go +67 −0
  • internal/edge/assetcatch.go +11 −1
  • internal/edge/demo_traffic.go +1 −1
  • internal/edge/edge.go +1 −1
  • internal/edge/usagemeter.go +64 −8
  • internal/edge/usagemeter_instances_test.go +373 −0
  • internal/edge/usagemeter_test.go +9 −9
  • internal/host/agent.go +5 −61
  • internal/host/applessroute_test.go +1 −1
  • internal/host/canary_count.go +70 −0
  • internal/host/group_names_test.go +2 −1
  • internal/host/instance_usage.go +262 −0
  • internal/host/instance_usage_e2e_test.go +215 −0
  • internal/host/instance_usage_test.go +893 −0
  • internal/host/testdata/usage-edge-golden.json +1 −0
  • internal/host/usage_compat_test.go +100 −0
  • internal/host/usage_loop.go +24 −4
  • internal/host/usage_loop_test.go +7 −7
  • internal/provision/instance_usage_census_test.go +56 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-instance-usage.tsv +39 −0
  • internal/status/instanceusage_test.go +30 −0
  • internal/status/snapshot.go +12 −0
  • internal/svcrole/svcrole.go +23 −8
  • internal/svcrole/svcrole_test.go +58 −3
  • internal/usage/edge.go +5 −0
  • internal/usage/instances.go +145 −0
  • internal/usage/instances_test.go +165 −0
  • internal/usage/testdata/instance-usage-e2e.golden.json +36 −0
  • parity/cli.tsv +1 −0
  • parity/packages.tsv +1 −0
  • parity/parity.tsv +1 −0
  • services.go +12 −5
  • services_roles_help_test.go +47 −0
  • testdata/clireg-golden.jsonl +10 −8
  • usage_cmd.go +261 −0
  • usage_cmd_test.go +308 −0

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-oFIpiH
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.43.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading golang.org/x/sys v0.49.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/klauspost/compress v1.20.2
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/memory v1.11.0
go: downloading github.com/google/uuid v1.6.0
go: downloading modernc.org/mathutil v1.7.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec

amadan: job cancelled — a newer push superseded it

landed from instance-usage

apimode.go

Loading diff…

apimode_limit.go

Loading diff…

approved_usage_copy_test.go

Loading diff…

cmd/console/instanceusage_test.go

Loading diff…

cmd/console/main.go

Loading diff…

commands.go

Loading diff…

commands_test.go

Loading diff…

docs/parity.md

Loading diff…

docs/site/cli.md

Loading diff…

docs/superpowers/notes/census-proposal-instance-usage.md

Loading diff…

docs/superpowers/notes/instance-usage-copy.md

Loading diff…

docs/superpowers/plans/2026-11-29-instance-usage.md

Loading diff…

docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R1.md

Loading diff…

docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md

Loading diff…

docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R3.md

Loading diff…

docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R2.md

Loading diff…

docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R3.md

Loading diff…

docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan.md

Loading diff…

docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-branch-R1.md

Loading diff…

docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-census-R1.md

Loading diff…

docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task2-R1.md

Loading diff…

docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task3-R1.md

Loading diff…

docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task5-R1.md

Loading diff…

docs/superpowers/reviews/CODEX-FINDINGS-instance-usage-task6-R1.md

Loading diff…

docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-branch.md

Loading diff…

docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-census.md

Loading diff…

docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task2.md

Loading diff…

docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task3.md

Loading diff…

docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task5.md

Loading diff…

docs/superpowers/reviews/CODEX-REVIEW-BRIEF-instance-usage-task6.md

Loading diff…

internal/console/apilinks_test.go

Loading diff…

internal/console/apiservices.go

Loading diff…

internal/console/apiusage.go

Loading diff…

internal/console/apiusage_e2e_test.go

Loading diff…

internal/console/apiusage_test.go

Loading diff…

internal/console/claim_workers.go

Loading diff…

internal/console/economics_instances_compat_test.go

Loading diff…

internal/console/hostnorm.go

Loading diff…

internal/console/jobs.go

Loading diff…

internal/console/jobs_test.go

Loading diff…

internal/console/linkedpolicy.go

Loading diff…

internal/console/links_auth_test.go

Loading diff…

internal/console/platform_credentials_test.go

Loading diff…

internal/console/routedecls.go

Loading diff…

internal/console/routedecls_test.go

Loading diff…

internal/console/server.go

Loading diff…

internal/console/svcpage.go

Loading diff…

internal/console/svcprincipal.go

Loading diff…

internal/console/svcroutes_test.go

Loading diff…

internal/console/usagedays.go

Loading diff…

internal/console/usagefrom.go

Loading diff…

internal/console/usagefrom_test.go

Loading diff…

internal/console/usagerole_test.go

Loading diff…

internal/edge/asset_far_test.go

Loading diff…

internal/edge/assetcatch.go

Loading diff…

internal/edge/demo_traffic.go

Loading diff…

internal/edge/edge.go

Loading diff…

internal/edge/usagemeter.go

Loading diff…

internal/edge/usagemeter_instances_test.go

Loading diff…

internal/edge/usagemeter_test.go

Loading diff…

internal/host/agent.go

Loading diff…

internal/host/applessroute_test.go

Loading diff…

internal/host/canary_count.go

Loading diff…

internal/host/group_names_test.go

Loading diff…

internal/host/instance_usage.go

Loading diff…

internal/host/instance_usage_e2e_test.go

Loading diff…

internal/host/instance_usage_test.go

Loading diff…

internal/host/testdata/usage-edge-golden.json

Loading diff…

internal/host/usage_compat_test.go

Loading diff…

internal/host/usage_loop.go

Loading diff…

internal/host/usage_loop_test.go

Loading diff…

internal/provision/instance_usage_census_test.go

Loading diff…

internal/provision/plan9_b8_census_test.go

Loading diff…

internal/provision/testdata/plan14-root-reads-chain.tsv

Loading diff…

internal/provision/testdata/plan14-root-reads-instance-usage.tsv

Loading diff…

internal/status/instanceusage_test.go

Loading diff…

internal/status/snapshot.go

Loading diff…

internal/svcrole/svcrole.go

Loading diff…

internal/svcrole/svcrole_test.go

Loading diff…

internal/usage/edge.go

Loading diff…

internal/usage/instances.go

Loading diff…

internal/usage/instances_test.go

Loading diff…

internal/usage/testdata/instance-usage-e2e.golden.json

Loading diff…

parity/cli.tsv

Loading diff…

parity/packages.tsv

Loading diff…

parity/parity.tsv

Loading diff…

services.go

Loading diff…

services_roles_help_test.go

Loading diff…

testdata/clireg-golden.jsonl

Loading diff…

usage_cmd.go

Loading diff…

usage_cmd_test.go

Loading diff…