plan 3: Astra round 1 fixes; defer tag-basis costs
Coordinator rulings on Astra plan round 1. Slice B (tag filter, untagged inventory, tagging runbook) moves to a "Later" note that carries Astra #9 (infraview Kind vs NativeType) and #10 (tag activation is not coverage). CONSOLE_COST_DEPLOYMENT_TAG and the tagged basis are gone from this plan. #8: NewServer is no longer edited, and Task 1 runs the record-write census with the overlay procedure if any fingerprinted unit moves. Tax exclusion kept. Four tasks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+90
−161
docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md+90 −161
diff --git a/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md b/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md| index 84e638ced..fd14254f0 100644 |
| --- a/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md |
| +++ b/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md |
| @@ -2,109 +2,96 @@ |
| > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| -**Goal:** Every stored AWS bill says what it covers, and the console exposes one figure, the month's CARLOS-only platform cost, that is never the whole of a mixed AWS account. |
| +**Goal:** Every stored AWS bill says what it covers, and the console exposes one figure, the month's CARLOS-only platform cost. A console that cannot vouch for that figure hides it instead of showing a mixed AWS account's total. |
| -**Architecture:** `economics.Bill` gains an additive `basis` (and, for the tagged basis, the `deployment` tag value). The hourly `billPass` stamps it from a new console setting: either the AWS account is declared CARLOS-only (Carloku), or Cost Explorer is filtered to `carlos:deployment=<value>`, used only for months the cost allocation tag was active from day one. One method, `carlosPlatformCostUSD`, reads the stored bill and answers only for a CARLOS-only basis; Plan 2 converts it to euros. The Economics page and the manual-entry doors show and set the basis. |
| +**Architecture:** `economics.Bill` gains an additive `basis`. The hourly `billPass` stamps `account` when the console declares its AWS account CARLOS-only (Carloku), otherwise it leaves the basis empty, meaning the whole account. One method, `carlosPlatformCostUSD`, reads the stored bill and answers only for a CARLOS-only basis; Plan 2 converts it to euros. The Economics page and the manual-entry doors show and set the basis. Filtering by the `carlos:deployment` tag is deferred (see "Later"). |
| -**Tech Stack:** Go, the existing Cost Explorer seam (`internal/console/cepull.go`, aws-sdk-go-v2 `service/costexplorer` v1.67.5, already a dependency), `html/template`, OpenTofu (`infra/modules/region-host`). No new dependency. |
| +**Tech Stack:** Go, the existing Cost Explorer seam (`internal/console/cepull.go`), `html/template`. No new dependency, no infrastructure change. |
| **Spec:** `docs/superpowers/specs/2026-11-09-billing-dashboard-design.md` §4.5, plus the parts of §2 (anti-goal "A total AWS cost that includes things that aren't CARLOS") and §7 ("The platform cost matches the CARLOS-only AWS figure, and the page says which basis it used") that name it. Paul, 2026-11-09: "Make sure the AWS bill stuff only takes CARLOS related resources into account and not the full AWS bill on the account. I think in the Carloku case, everything on the bill is CARLOS related, so that should be fine." Plans 1 and 2 of this spec are written beside this one; Plan 2 calls this plan's seam. |
| +**Review history:** Astra plan round 1 (2026-11-09) found three items against this plan. #8 (record-write census) is fixed in Task 1. #9 and #10 were against the tag-mode slice, which the coordinator deferred; both are carried into "Later". The coordinator ruled to keep excluding the AWS `Tax` line. |
| + |
| ## Global Constraints |
| - Baseline: branch `design-billing-dashboard`, `dd344d1fa37b43a4ce5a260cd402a68bb954a5ba`. Unqualified `file:line` citations refer to it. New names below are this plan's decisions. |
| -- Wire shapes are additive (`AGENTS.md:431`). Bills written before this plan carry no `basis` and must still parse; a whole-account bill written after it must marshal byte-identically to one written before it (`omitempty` on both new keys). |
| -- Provider-neutral core (memory `provider-neutral-core`): `internal/economics` gains plain strings, no AWS import. Cost Explorer stays behind the existing `ceCosts` seam in `internal/console/cepull.go`. A deployment without AWS records bills by hand and declares their basis; nothing in this plan requires AWS. |
| +- Wire shapes are additive (`AGENTS.md:431`). Bills written before this plan carry no `basis` and must still parse, and a whole-account bill written after it must marshal byte-identically to one written before it (`omitempty`). |
| +- Provider-neutral core (memory `provider-neutral-core`): `internal/economics` gains a plain string, no AWS import. Cost Explorer stays behind the existing `ceCosts` seam. A deployment without AWS records bills by hand and declares their basis. |
| - Pages never call Cost Explorer (spec §2 anti-goal "A slow page"). Only `billPass` does. |
| -- No new bucket object and no new poll (memory `s3-requests-cost-money`). Steady-state request budget, nothing changing: S3 unchanged (`billPass` already reads two bill objects per hourly tick); Economics view in tag mode adds one GET of `infra/inventory.json` per view build (60 s cache, page-driven, not polled); Cost Explorer adds one `ListCostAllocationTags` per UTC day in tag mode only, plus one re-pull per month when the basis changes. |
| -- Copy: every human-facing string is in the copy table below and goes through the `copy-review` skill before it is written into a file. No em dashes in copy. Error fragments and CLI diagnostics are listed but are outside copy review (memory `copy-review-scope-human-text`). |
| -- No tenant names in code, tests or docs; the example deployment value is `production` (already used by `internal/awsmanaged/testdata/managed-console-policy.json`). |
| -- Census (`AGENTS.md:299`): `internal/economics/bill.go` is in the root binary's scope (`internal/provision/testdata/census-base-scope.txt:262`, reached through `internal/hostops/storage_classifier.go`), and so are the root package's `economics.go` and every non-Markdown file under `infra/`. Tasks 1, 4 and 5 change census scope; see "Census and cross-compile" below. |
| +- No new bucket object and no new poll (memory `s3-requests-cost-money`). Steady-state request budget with nothing changing: S3 unchanged (`billPass` already reads two bill objects per hourly tick), Cost Explorer unchanged except one re-pull per stored month when the basis changes. `carlosPlatformCostUSD` makes one GET per call; Plan 2 owns its caching. |
| +- With no basis setting, a console hides CARLOS-only costs (spec §4.5). Today only Carloku sets it. |
| +- Copy: every human-facing string is in the copy table and goes through the `copy-review` skill before it is written into a file. No em dashes in copy. Diagnostics are listed but outside copy review (memory `copy-review-scope-human-text`). |
| +- Root-read census (`AGENTS.md:299`): `internal/economics/bill.go` (`internal/provision/testdata/census-base-scope.txt:262`, reached through `internal/hostops/storage_classifier.go`) and the root package's `economics.go` are in scope. Tasks 1 and 4 change them. |
| +- Record-write census (`internal/provision/plan9_b8_census_test.go:360`, tip `gvisorDemosWriteCensusInventory` at `:369`): fingerprints every unit with a write site, including `internal/console/server.go:NewServer` and `internal/console/economicspass.go:Server.upsertBill` (`plan9_b8_census_test.go:726`). See Task 1 Step 6. |
| - Stopping rules (`AGENTS.md:34`) and gate (`AGENTS.md:245`): targeted `go test -run` while iterating, default `GOCACHE`; `make test` and `go build ./...` once before handoff; CI runs `20-cross@5`. |
| ## Review Focus |
| -1. **The tag is not active, or became active mid-month.** A tag-filtered query then returns $0 or a part-month figure that reads as the CARLOS cost. Expected: that month is stored whole-account and hidden. Task 5 `TestBillPassTaggedNeedsActiveTag`. |
| -2. **The setting changes after bills exist.** A month already pulled, or already settled after day 3, keeps its old basis forever. Expected: one re-pull under the new basis, then the ordinary once-a-day and settle rules. Task 1 `TestBillPassRepullsOnBasisChange`. |
| -3. **A hand-entered bill on a mixed account.** An old CLI sends no basis. Expected: it is not counted as CARLOS-only unless the account is declared CARLOS-only or the operator says "tagged". Task 4 `TestEconomicsBillBasisDoors`. |
| -4. **AWS tax on the bill.** Revenue on the Billing pages is before tax (spec §4.3), so a whole-account cost with the `Tax` line in it would understate profit. Expected: the platform cost leaves out the `Tax` service line on every basis. Task 2 `TestCarlosPlatformCostBasis`. |
| -5. **An unknown or hand-edited `basis` value in the bucket.** Expected: read as whole-account (fail closed), never as CARLOS-only. Task 2 `TestCarlosPlatformCostBasis`, and the host-side classifier still admits the new keys (Task 1 `TestReviewedStorageBodiesBindIdentityAndScope` rows). |
| +1. **The setting changes after bills exist.** A month already pulled, or already settled after day 3, would keep its old basis forever. Expected: one re-pull under the new basis, then the ordinary once-a-day and settle rules. Task 1 `TestBillPassRepullsOnBasisChange`. |
| +2. **A hand-entered bill on an undeclared account.** An old CLI sends no basis. Expected: it is not counted as CARLOS-only unless the account is declared CARLOS-only. Task 4 `TestEconomicsBillBasisDoors`. |
| +3. **AWS tax on the bill.** Revenue on the Billing pages is before tax (spec §4.3). Expected: the platform cost leaves out the `Tax` service line. Task 2 `TestCarlosPlatformCostBasis`. |
| +4. **An unknown or hand-edited `basis` value in the bucket**, including a value a later version writes (`tagged`) read by this one. Expected: read as whole-account (fail closed), never as CARLOS-only. Task 2 `TestCarlosPlatformCostBasis`. |
| +5. **The host-side bill classifier meets the new key.** Expected: the current binary admits bills with and without `basis`. Task 1 `TestReviewedStorageBodiesBindIdentityAndScope` rows. |
| --- |
| -## What CARLOS tags today (read-only survey, 2026-11-09) |
| - |
| -| Resource | Created by | `carlos:deployment` today | |
| -|---|---|---| |
| -| Region HA group boxes (ASG instances via launch template) | `infra/modules/region-host/group.tf:19-23` | Yes, with `carlos:region` | |
| -| Managed fleet boxes and fleet buckets | `internal/awsmanaged/compute.go:197`, `storage.go:182` | Yes, but not wired into `cmd/console` yet (2b-2 building) | |
| -| Single region hosts (`aws_instance`), their volumes and EIPs, scanner and PDF hosts | `infra/modules/{region-host,scanner-host,pdf-host}/main.tf` | No (`Name` only) | |
| -| Deployment and data buckets | `infra/modules/deployment-buckets` | No | |
| -| Alarms, SNS, SQS, NLB, launch template | `infra/modules/region-host` | No | |
| -| Tenant object-store buckets | console, `internal/objstore/aws.go:294` | No | |
| -| Steering health checks | `internal/steering/route53.go` | No | |
| -| Hosted zones, NAT, anything else | private roots (`carloku-infrastructure`, `platform-infrastructure`) | No: neither local clone has `default_tags` or any `carlos:` tag | |
| - |
| -So a tag-filtered bill today would count almost nothing. Carloku's account is CARLOS-only (Paul), so it uses the account setting and needs no tagging. Dev's account (kass) is mixed and has no Cost Explorer grant (`enable_cost_explorer` is set only in `carloku-infrastructure/region-ie.tf:68`), so dev's costs stay hidden until someone tags and activates (Task 6 runbook, a production-infrastructure change that needs Paul's scoped approval per `AGENTS.md:119`). |
| - |
| ## Decisions |
| -- **Settings** (my call; spec §6 leaves the names to the builder). `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` declares the whole AWS account CARLOS-only. `CONSOLE_COST_DEPLOYMENT_TAG=<value>` selects tag mode with that `carlos:deployment` value. Both set stops the console at boot, as do a non-boolean value and a tag value outside `^[A-Za-z0-9._:/=+@-]{1,256}$` (the same grammar as `internal/awsmanaged/compute.go:61`). Neither set: bills are still pulled whole-account for the Economics page, and the CARLOS-only figure is hidden. These are independent of 2b-2's `CARLOS_MANAGED_FLEET_DEPLOYMENT` (unmerged, `AGENTS.md:68` rule 4); defaulting one to the other is a follow-up. |
| -- **Stored basis values** (`internal/economics`): `""` the whole account, may hold more than CARLOS (every existing bill); `"account"` the whole account, declared CARLOS-only; `"tagged"` only resources tagged `carlos:deployment=<Deployment>`. |
| -- **Reading a bill** (`effectiveBillBasis`): a stored `account` or `tagged` stands, whatever the setting is now (it was true when pulled). A stored `""` reads as `account` while `CONSOLE_COST_ACCOUNT_CARLOS_ONLY` is on, since a whole-account figure from a CARLOS-only account is CARLOS-only. That is how Carloku's settled October bill counts without a re-pull. Anything else reads as `""`. |
| -- **Tag mode needs a live tag.** Each UTC day, at most once, the pull asks Cost Explorer `ListCostAllocationTags` for `carlos:deployment`. A month is pulled tagged only when the tag is `Active` and its `LastUpdatedDate` is on or before the month's first day; otherwise it is pulled whole-account with basis `""`. A failed status call (including AccessDenied, which a member account of an AWS Organization can get) also means whole-account. It is logged once and never latches `ceDisabled`. |
| -- **Tax.** `carlosPlatformCostUSD` subtracts the `Tax` service line (Cost Explorer's `SERVICE` value for tax) on every basis. A tag filter already excludes it; a whole-account bill does not. |
| -- **Per-service "Counts as CARLOS" checkboxes** (`Scenario.BillServices`, `templates/economics.html:209-221`) stay a modelling knob on the Economics page. They do not feed `carlosPlatformCostUSD`. A service-level pick cannot separate CARLOS from other EC2 in the same account. |
| -- **Manual entry.** The form, the API and the CLI take an optional basis: `tagged` or `account`. When it is absent the console uses `account` if the account is declared CARLOS-only, otherwise `""`. A manual `tagged` bill records the configured tag value, if any. |
| -- **Untagged CARLOS resources.** Tagging what the console creates at runtime (tenant buckets, steering health checks) needs new IAM (`s3:TagResource`, `route53:ChangeTagsForResource`) and census review, and no live deployment uses tag mode. It is a follow-up, not in this plan. This plan lists untagged resources on the Economics page (Task 6) and documents the operator steps. |
| -- **Slices.** Tasks 1-4 are slice A: account mode, the seam and the basis everywhere. Carloku sees it as soon as the setting is on. Tasks 5-6 are slice B: tag mode. Slice B has no live user today (rule 5, `AGENTS.md:74`), so it merges only once Paul names a switch-on (dev or Tito). |
| +- **Setting** (my call; spec §6 leaves the name to the builder). `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` declares the whole AWS account CARLOS-only. A non-boolean value stops the console at boot (the `domainProof` shape, `cmd/console/main.go:1489`). Unset: bills are still pulled whole-account for the Economics page, and the CARLOS-only figure is hidden. No tag setting in this plan. |
| +- **Stored basis values** (`internal/economics`): `""` means the whole account, which may hold more than CARLOS (every existing bill). `"account"` means the whole account, declared CARLOS-only. |
| +- **Reading a bill** (`effectiveBillBasis`): a stored `account` stands, whatever the setting is now, because it was true when pulled. A stored `""` reads as `account` while the setting is on, since a whole-account figure from a CARLOS-only account is CARLOS-only. That is how Carloku's settled October bill counts without a re-pull. Any other value reads as `""`. |
| +- **Tax.** `carlosPlatformCostUSD` subtracts the `Tax` service line (Cost Explorer's `SERVICE` value for tax). Ruled: keep. |
| +- **Per-service "Counts as CARLOS" checkboxes** (`Scenario.BillServices`, `templates/economics.html:209-221`) stay a modelling knob on the Economics page and do not feed `carlosPlatformCostUSD`. A service-level pick cannot separate CARLOS from other EC2 in the same account. |
| +- **Manual entry.** The form, the API and the CLI take an optional basis, `account` or `whole`. When it is absent the console uses `account` if the account is declared CARLOS-only, otherwise `""`. |
| -## Copy table (through `copy-review` before Task 2; slice B rows before Task 5) |
| +## Copy table (through `copy-review` before Task 2) |
| | # | Where | Draft | |
| |---|---|---| |
| -| C1 | basis label, tagged | `AWS, CARLOS-tagged only (carlos:deployment=%s)`; without a value: `AWS, CARLOS-tagged only` | |
| -| C2 | basis label, account | `AWS, whole account: CARLOS only` | |
| -| C3 | basis label, whole | `AWS, whole account: not only CARLOS` | |
| -| C4 | hint, whole, no setting | `This bill covers the whole AWS account, which may hold more than CARLOS. Set CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true if the account runs only CARLOS, or CONSOLE_COST_DEPLOYMENT_TAG to count tagged resources only.` | |
| -| C5 | hint, whole, tag mode (slice B) | `The carlos:deployment cost allocation tag was not active for all of %s, so this bill covers the whole AWS account. Months that start after you activate the tag count tagged resources only.` | |
| -| C6 | hint, no bill | `No AWS bill on file for %s yet.` | |
| -| C7 | manual form | label `What this bill covers`; options `CARLOS-tagged resources only` / `The whole account, which runs only CARLOS` / `The whole account, CARLOS and other things` | |
| -| C8 | CLI `--basis` help | `what the total covers: tagged (CARLOS-tagged resources only) or account (the whole account, which runs only CARLOS)`; output line `basis: %s` | |
| -| C9 | untagged section (slice B) | heading `Not tagged for CARLOS`; note `%d resources in this AWS account have no carlos:deployment=%s tag, so their costs are left out. Tag the ones that belong to CARLOS.`; footer `Tags not checked: %d buckets, %d DNS zones, %d alarms.` | |
| -| C10 | `infra/modules/README.md` section "Counting only CARLOS in the AWS bill" | prose per Task 6, reviewed as a whole | |
| -| x | not reviewed (diagnostics) | boot: `console: CONSOLE_COST_ACCOUNT_CARLOS_ONLY and CONSOLE_COST_DEPLOYMENT_TAG are both set; choose one`; API 400: `basis must be tagged or account` | |
| +| C1 | basis label, account | `AWS, whole account: CARLOS only` | |
| +| C2 | basis label, whole | `AWS, whole account: not only CARLOS` | |
| +| C3 | hint, whole | `This bill covers the whole AWS account, which may hold more than CARLOS. If the account runs only CARLOS, set CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true on the console.` | |
| +| C4 | hint, no bill | `No AWS bill on file for %s yet.` | |
| +| C5 | manual form | label `What this bill covers`; options `The whole account, which runs only CARLOS` / `The whole account, CARLOS and other things` | |
| +| C6 | CLI `--basis` help | `what the total covers: account (the whole account, which runs only CARLOS) or whole (the whole account, CARLOS and other things)`; output line `basis: %s` | |
| +| x | not reviewed (diagnostics) | boot: `console: CONSOLE_COST_ACCOUNT_CARLOS_ONLY %q is not a boolean (use true or false)`; API 400: `basis must be account or whole` | |
| --- |
| ### Task 1: Basis on the bill, the CARLOS-only account setting, and the pull |
| -**Risk/review:** production storage wire shape (bill objects in the deployment bucket) and census scope. Independent task review required (`AGENTS.md:65` rule 3), plus the census reviewer. |
| +**Risk/review:** production storage wire shape (bill objects in the deployment bucket) and both censuses. Independent task review required (`AGENTS.md:65` rule 3), plus the census reviewer. |
| **Files:** |
| -- Modify: `internal/economics/bill.go:5-24` (consts, two fields, doc comment that no longer claims attribution is only a dashboard knob), `internal/economics/bill_test.go` |
| -- Create: `internal/console/costscope.go`, `internal/console/costscope_test.go`, `cmd/console/costscope.go`, `cmd/console/costscope_test.go` |
| -- Modify: `internal/console/server.go:761` (Config field), `:1336` (seam type), `:1786` (NewServer validates); `cmd/console/main.go:507` (wire the setting); `internal/console/cepull.go:42,53` (seam takes `ceQuery`); `internal/console/economicspass.go:1072-1127` (`pullBillMonth`, `shouldSkipCEPull`); `internal/console/economicsbill_test.go` and `claim_invariant_probes_worker_test.go:157` (mechanical: closures take `ceQuery`); `internal/hostops/storage_classifier_test.go:36` (table rows only, no `hostops` source change) |
| +- Modify: `internal/economics/bill.go:5-24` (consts, one field, and a type comment that no longer says attribution is only a dashboard knob), `internal/economics/bill_test.go` |
| +- Create: `internal/console/costscope.go`, `cmd/console/costscope.go`, `cmd/console/costscope_test.go` |
| +- Modify: `internal/console/server.go:761` (Config field only, no `NewServer` change), `:1336` (seam type); `cmd/console/main.go:507` (wire the setting); `internal/console/cepull.go:42,53` (seam takes `ceQuery`); `internal/console/economicspass.go:1072-1127` (`pullBillMonth`, `shouldSkipCEPull`); `internal/console/economicsbill_test.go` and `claim_invariant_probes_worker_test.go:157` (mechanical: closures take `ceQuery`); `internal/hostops/storage_classifier_test.go:36` (table rows only, no `hostops` source change) |
| **Interfaces:** |
| -- Produces, `internal/economics`: `const BasisWholeAccount = ""`, `BasisAccount = "account"`, `BasisTagged = "tagged"`; `Bill.Basis string \`json:"basis,omitempty"\``; `Bill.Deployment string \`json:"deployment,omitempty"\`` (set only with `BasisTagged`). `Schema` stays 1. |
| -- Produces, `internal/console`: `type CostScope struct { AccountCarlosOnly bool }` (Task 5 adds `DeploymentTag string`); `func (c CostScope) Validate() error`; `Config.CostScope CostScope`; `type ceQuery struct { Start, End time.Time }` (Task 5 adds `TagValue string`); seam `ceCosts func(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) resolveCECosts(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) billBasisFor(ctx context.Context, start, end, now time.Time) (q ceQuery, basis, deployment string)`; `func shouldSkipCEPull(existing *economics.Bill, closedMonth bool, now time.Time, basis, deployment string) bool`. |
| -- Produces, `cmd/console`: `func costScopeFromEnv(getenv func(string) string) (console.CostScope, error)`; `main` calls it and `log.Fatalf`s on error. |
| +- Produces, `internal/economics`: `const BasisWholeAccount = ""`, `const BasisAccount = "account"`, and `Bill.Basis string` with JSON tag `basis,omitempty`. `Schema` stays 1. |
| +- Produces, `internal/console`: `type CostScope struct { AccountCarlosOnly bool }`; `Config.CostScope CostScope`; `type ceQuery struct { Start, End time.Time }`; seam `ceCosts func(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) resolveCECosts(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) realCECosts(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) billBasisFor(start, end time.Time) (q ceQuery, basis string)`; `func shouldSkipCEPull(existing *economics.Bill, closedMonth bool, now time.Time, basis string) bool`. |
| +- Produces, `cmd/console`: `func costScopeFromEnv(getenv func(string) string) (console.CostScope, error)`; `main` calls it and `log.Fatal`s on error. |
| - [ ] **Step 1: Write the failing tests** |
| - - `TestBillBasisWireShape` (`internal/economics`): `{"schema":1,"month":"2026-10","total_usd":5,"services":{},"source":"costexplorer"}` unmarshals with `Basis == ""`; marshalling a bill with `Basis: BasisWholeAccount` produces no `"basis"` and no `"deployment"` key; a `BasisTagged`/`"production"` bill round-trips both. |
| - - `TestCostScopeFromEnv` (`cmd/console`): unset gives the zero scope; `"true"` gives `AccountCarlosOnly`; `"maybe"` errors with the variable's name in the message. |
| - - `TestBillPassStampsBasis` (`internal/console`, fixture `newConsoleFixture`, `now := 2026-08-11T03:00Z`): with `fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}`, both `2026-08` and `2026-07` bills have `Basis == "account"`; with the zero scope both have `Basis == ""` and their raw JSON contains no `"basis"`. |
| - - `TestBillPassRepullsOnBasisChange`: a zero-scope `billPass` (2 `ceCosts` calls); then set the account scope and run again the same UTC day: 2 more calls and both bills now `account`; a third run: 0 more calls. Separately, a `2026-07` bill stored with `PulledAt 2026-08-05` (settled) and `Basis ""` is re-pulled exactly once after the switch. |
| - - In `TestReviewedStorageBodiesBindIdentityAndScope`, add rows `{"economics/bills/2026-10.json", \`{"schema":1,"month":"2026-10","source":"costexplorer","basis":"tagged","deployment":"production"}\`, true}` and the same without `basis`/`deployment`, `true`. |
| + - `TestBillBasisWireShape` (`internal/economics`): `{"schema":1,"month":"2026-10","total_usd":5,"services":{},"source":"costexplorer"}` unmarshals with `Basis == ""`. Marshalling a bill with `Basis: BasisWholeAccount` produces no `"basis"` key. An `account` bill round-trips. |
| + - `TestCostScopeFromEnv` (`cmd/console`): unset gives the zero scope, `"true"` gives `AccountCarlosOnly`, and `"maybe"` errors with the variable's name in the message. |
| + - `TestBillPassStampsBasis` (`internal/console`, fixture `newConsoleFixture`, `now := 2026-08-11T03:00Z`): with `fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}`, both the `2026-08` and `2026-07` bills have `Basis == "account"`. With the zero scope both have `Basis == ""` and their raw JSON contains no `"basis"`. |
| + - `TestBillPassRepullsOnBasisChange`: a zero-scope `billPass` makes 2 `ceCosts` calls. Set the account scope and run again the same UTC day: 2 more calls, and both bills are now `account`. A third run makes 0 more calls. Separately, a `2026-07` bill stored with `PulledAt 2026-08-05` (settled) and `Basis ""` is re-pulled exactly once after the switch. |
| + - In `TestReviewedStorageBodiesBindIdentityAndScope`, add the row `{"economics/bills/2026-10.json", "{\"schema\":1,\"month\":\"2026-10\",\"source\":\"costexplorer\",\"basis\":\"account\"}", true}` and the same body without `basis`, also `true`. |
| - [ ] **Step 2: Run to verify they fail** |
| Run: `go test ./internal/economics ./cmd/console ./internal/console ./internal/hostops -run 'TestBillBasisWireShape|TestCostScopeFromEnv|TestBillPass(StampsBasis|RepullsOnBasisChange)|TestReviewedStorageBodiesBindIdentityAndScope' -count=1` |
| - Expected: FAIL on undefined `Basis`, `CostScope`, `costScopeFromEnv`. The hostops rows fail with an unknown-field error until `bill.go` changes. |
| + Expected: FAIL on undefined `Basis`, `CostScope` and `costScopeFromEnv`. The `basis` hostops row fails on an unknown field until `bill.go` changes. |
| - [ ] **Step 3: Implement** |
| - `billBasisFor` returns `(ceQuery{start, end}, BasisAccount, "")` when `AccountCarlosOnly`, otherwise `(ceQuery{start, end}, BasisWholeAccount, "")`. `pullBillMonth` computes the basis before the skip check and stamps `Basis`/`Deployment` on the bill it writes. `shouldSkipCEPull` returns false when `existing.Basis != basis || existing.Deployment != deployment`, before its settle and same-day rules. Manual-wins in `upsertBill` is unchanged. `costScopeFromEnv` reads `CONSOLE_COST_ACCOUNT_CARLOS_ONLY` with `strconv.ParseBool` after `TrimSpace` (the `domainProof` shape, `cmd/console/main.go:1489`). Rewrite `bill.go`'s type comment: the pull is CARLOS-scoped by `Basis`, and `""` means whole account. |
| + `billBasisFor` returns `(ceQuery{start, end}, BasisAccount)` when `AccountCarlosOnly`, otherwise `(ceQuery{start, end}, BasisWholeAccount)`. `pullBillMonth` computes the basis before the skip check and stamps it on the bill it writes. `shouldSkipCEPull` returns false when `existing.Basis != basis`, ahead of its settle and same-day rules. Manual-wins in `upsertBill` is unchanged, and `upsertBill` itself is not edited. `costScopeFromEnv` reads `CONSOLE_COST_ACCOUNT_CARLOS_ONLY` with `strconv.ParseBool` after `TrimSpace`. `NewServer` is not edited: `s.cfg` already carries the whole `Config`, and a single bool has nothing to validate. |
| - [ ] **Step 4: Run to verify they pass**, plus the existing bill tests: `go test ./internal/console -run 'TestBillPass|TestEconomics' -count=1`; expect PASS. |
| -- [ ] **Step 5: Census card.** `make census-card`; CLAIMS line `internal/economics/bill.go:Bill<TAB>two additive string fields and three consts; no read added`; `make census-propose NAME=<branch> CLAIMS=<file>`. If Plans 1-2 share this branch, add this line to that branch's single CLAIMS file instead. |
| -- [ ] **Step 6: Commit** `economics: record what each AWS bill covers` |
| +- [ ] **Step 5: Root-read census.** Run `make census-card`. CLAIMS line: `internal/economics/bill.go:Bill<TAB>one additive string field and two consts; no read added`. Then run `make census-propose NAME=<branch> CLAIMS=<file>`. If Plans 1-2 share this branch, add the line to that branch's single CLAIMS file instead. |
| +- [ ] **Step 6: Record-write census (Astra #8).** Run `go test ./internal/provision -run TestPlan9B8RecordWriteCensus -count=1`. This plan is designed to leave every fingerprinted unit unchanged, so expect PASS. If it reports a `changed site`, for example because the implementation did touch `NewServer` or `Server.upsertBill`, or because Plans 1-2 on this branch did, update the inventory the way the existing overlays do (pattern: `internal/provision/analytics_live_census_test.go`): |
| + 1. Create `internal/provision/billing_dashboard_3_census_test.go` with `billingDashboard3WriteCensusInventory() []censusEntry`. Layer it on the newest tip: `gvisorDemosWriteCensusInventory` at this baseline, or a branch-mate's overlay if Plans 1-2 added one. Re-pin each reported unit with its class and kinds unchanged and its new sha256 digest, which is the hash `censusParse` takes over the declaration (`plan9_b8_census_test.go:189`). |
| + 2. Write a header comment that names each unit and says whether a record write was added, moved or reclassified. |
| + 3. Point `plan9_b8_census_test.go:369` at the new function. |
| + 4. Have the same independent reviewer as Step 5 approve it, and record the verdict on #280. |
| + If Plans 1-2 add the branch's overlay, re-pin inside theirs rather than chaining a second one. |
| +- [ ] **Step 7: Commit** `economics: record what each AWS bill covers` |
| ### Task 2: The platform-cost seam Plan 2 calls |
| @@ -114,28 +101,27 @@ So a tag-filtered bill today would count almost nothing. Carloku's account is CA |
| - Create: `internal/console/platformcost.go`, `internal/console/platformcost_test.go` |
| **Interfaces:** |
| -- Consumes: Task 1's `economics.Basis*`, `Config.CostScope`; existing `func (s *Server) getBill(ctx context.Context, month string) (*economics.Bill, error)` (`economicspass.go:1129`). |
| -- Produces (Plan 2 calls these; names are final): |
| - - `func (s *Server) carlosPlatformCostUSD(ctx context.Context, month string) (usd float64, basis string, ok bool)`. `month` is `"2006-01"`. `ok` is true only when the effective basis is `economics.BasisAccount` or `economics.BasisTagged`. `usd` is `TotalUSD - Services["Tax"]`. When `!ok`, `basis` is `economics.BasisWholeAccount` for a whole-account bill, or `costBasisMissing` when there is no readable bill (a read error is logged). One bucket GET per call, no cache. Plan 2 owns caching and the conversion: `platformCostEUR(month)` multiplies `usd` by its daily USD→EUR rate, passes `basis` through, and hides the figure when `!ok`. |
| +- Consumes: Task 1's `economics.Basis*` and `Config.CostScope`; the existing `func (s *Server) getBill(ctx context.Context, month string) (*economics.Bill, error)` (`economicspass.go:1129`). |
| +- Produces (Plan 2 calls these; the names are final): |
| + - `func (s *Server) carlosPlatformCostUSD(ctx context.Context, month string) (usd float64, basis string, ok bool)`. `month` is `"2006-01"`. `ok` is true only when the effective basis is `economics.BasisAccount`, and then `usd` is `TotalUSD - Services["Tax"]`. When `!ok`, `basis` is `economics.BasisWholeAccount` for a whole-account bill, or `costBasisMissing` when there is no readable bill (a read error is logged). Plan 2 owns caching and conversion: `platformCostEUR(month)` multiplies `usd` by its daily USD→EUR rate, passes `basis` through, and hides the figure when `!ok`. |
| - `const costBasisMissing = "missing"` (never stored). |
| - `func effectiveBillBasis(b economics.Bill, scope CostScope) string`. |
| - - `func costBasisLabel(basis, deployment string) string`: copy C1 to C3. |
| - - `func costBasisHint(scope CostScope, basis, month string) string`: C4 for `""`, C6 for `costBasisMissing`, `""` for a CARLOS-only basis. Task 5 adds C5. The Billing pages render this line in place of hidden costs (spec §4.5 "hidden behind a one-line explanation"). |
| + - `func costBasisLabel(basis, deployment string) string` returns C1 or C2. `deployment` is ignored here; it is kept because Plan 2 already calls this signature, and the tag follow-up will use it. |
| + - `func costBasisHint(scope CostScope, basis, month string) string` (the signature Plan 2 calls) returns C3 for `""`, C4 for `costBasisMissing`, and `""` for `account`. The Billing pages render it in place of hidden costs (spec §4.5, "hidden behind a one-line explanation"). |
| - `const billTaxService = "Tax"`. |
| -- [ ] **Step 0 (once, before this task): copy review.** Run the `copy-review` skill over rows C1-C4 and C6-C8 and wait for Paul's edits. Apply them verbatim; Tasks 2-4 use the approved strings. |
| -- [ ] **Step 1: Write the failing tests.** `TestCarlosPlatformCostBasis`, a table over stored bill × scope → `(usd, basis, ok)`: |
| - - no object → `(0, "missing", false)`; unparseable object → `(0, "missing", false)` |
| +- [ ] **Step 0 (once, before this task): copy review.** Run the `copy-review` skill over rows C1-C6 and wait for Paul's edits. Apply them verbatim. Tasks 2-4 use the approved strings. |
| +- [ ] **Step 1: Write the failing tests.** `TestCarlosPlatformCostBasis` is a table of stored bill × scope → `(usd, basis, ok)`: |
| + - no object → `(0, "missing", false)`; an unparseable object → `(0, "missing", false)` |
| - `""` bill, zero scope → `(0, "", false)` |
| - `""` bill, account scope, `Total 100`, `Services {"AmazonEC2":90,"Tax":10}` → `(90, "account", true)` |
| - - `"account"` bill, zero scope → `ok` true, basis `account` (stored basis stands) |
| - - `"tagged"`/`production` bill, zero scope → `ok` true, basis `tagged` |
| - - `"bogus"` bill, account scope → `(0, "", false)` (fail closed: an unknown value is whole-account, and the account setting does not promote it) |
| + - `"account"` bill, zero scope → `ok` true, basis `account` (the stored basis stands) |
| + - `"tagged"` bill and `"bogus"` bill, account scope → `(0, "", false)` (an unknown value is whole-account, and the setting does not promote it) |
| - manual `""` bill, account scope → `ok` true, basis `account` |
| - `TestCostBasisLabelAndHint` asserts C1 (with and without a value), C2, C3, C4 and C6 exactly as approved. |
| + `TestCostBasisLabelAndHint` asserts C1 to C4 exactly as approved. |
| - [ ] **Step 2: Run** `go test ./internal/console -run 'TestCarlosPlatformCostBasis|TestCostBasisLabelAndHint' -count=1`; expect FAIL (undefined). |
| -- [ ] **Step 3: Implement** the Interfaces above. In `effectiveBillBasis`, only `""` is promoted to `account` by the setting; `account` and `tagged` pass through; any other value returns `""`. |
| +- [ ] **Step 3: Implement** the Interfaces above. In `effectiveBillBasis`, only `""` is promoted to `account` by the setting, `account` passes through, and any other value returns `""`. |
| - [ ] **Step 4: Run Step 2 again**; expect PASS. |
| - [ ] **Step 5: Commit** `console: one CARLOS-only platform cost figure for Billing` |
| @@ -147,10 +133,10 @@ So a tag-filtered bill today would count almost nothing. Carloku's account is CA |
| - Modify: `internal/console/economicsview.go:45-100` (two fields), `:654` and `:677` (fill them), `internal/console/templates/economics.html:185-243`, `internal/console/economicspage_test.go` |
| **Interfaces:** |
| -- Consumes: Task 2's `effectiveBillBasis`, `costBasisLabel`, `costBasisHint`. |
| +- Consumes: Task 2's `effectiveBillBasis`, `costBasisLabel` and `costBasisHint`. |
| - Produces: `EconomicsView.BillBasisLabels map[string]string` (month → label) and `EconomicsView.BillBasisHints map[string]string` (month → hint, absent when there is none). Both are shared and read-only, like `Bills` (see `copyEconomicsView`, `:352`). |
| -- [ ] **Step 1: Write the failing test** `TestEconomicsPageShowsBillBasis`: seed a `2026-08` bill. With the account scope, `/fleet/economics?period=mtd` (an operator session, as in `economicspage_test.go:111`) contains C2 next to the bill table heading. With the zero scope it contains C3 and C4. A `tagged`/`production` bill shows C1 with `carlos:deployment=production`. |
| +- [ ] **Step 1: Write the failing test** `TestEconomicsPageShowsBillBasis`: seed a `2026-08` bill. With the account scope, `/fleet/economics?period=mtd` (an operator session, as in `economicspage_test.go:111`) contains C1 next to the bill table heading. With the zero scope it contains C2 and C3. |
| - [ ] **Step 2: Run** `go test ./internal/console -run TestEconomicsPageShowsBillBasis -count=1`; expect FAIL. |
| - [ ] **Step 3: Implement.** Fill both maps where `Bills` is assigned. In the template, add the label to the bill table's heading row (`:213`, after the source) and the hint as a `co-note` paragraph under the table. No new CSS classes (`docs/console-styleguide.md`). |
| - [ ] **Step 4: Run Step 2 again and** `go test ./internal/console -run 'TestEconomics|TestConsoleStyleguideClassesExist' -count=1`; expect PASS. |
| @@ -158,105 +144,48 @@ So a tag-filtered bill today would count almost nothing. Carloku's account is CA |
| ### Task 4: Manual bills carry a basis (form, API, CLI) |
| -**Risk/review:** billing input doors and census (root package). The census reviewer covers `economics.go`; otherwise the whole-branch review. |
| +**Risk/review:** billing input doors and the root-read census (root package). The census reviewer covers `economics.go`; otherwise the whole-branch review. |
| **Files:** |
| -- Modify: `internal/console/economicspass.go:1394` (`handleEconomicsBillSave`), `:1548` (`handleAPIEconomicsBill`), `templates/economics.html:227-242` (C7 select); `economics.go:31` (usage), `:232` (`economicsBillResult.Basis`), `:250` (`economicsBill` gains `basis string`), `:275` (`--basis` flag, output line); `economics_test.go:80`; `docs/site/cli.md:2689-2701` |
| +- Modify: `internal/console/economicspass.go:1394` (`handleEconomicsBillSave`), `:1548` (`handleAPIEconomicsBill`), `templates/economics.html:227-242` (C5 select); `economics.go:31` (usage), `:232` (`economicsBillResult.Basis`), `:250` (`economicsBill` gains `basis string`), `:275` (`--basis` flag and the output line); `economics_test.go:80`; `docs/site/cli.md:2689-2701` |
| - Test: `internal/console/economicsbill_test.go` |
| **Interfaces:** |
| - Consumes: Task 1's basis consts and `Config.CostScope`. |
| -- Produces: `func (s *Server) manualBillBasis(raw string) (basis, deployment string, err error)` in `economicspass.go`. `""` gives the default (account if declared, else whole). `tagged` gives `BasisTagged` plus the configured tag value, or `""` before Task 5. `account` gives `BasisAccount`. Anything else is an error. API request gains `Basis string \`json:"basis,omitempty"\``. CLI: `func validBillBasis(s string) error` (accepts `""`, `tagged`, `account`); `func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64, basis string) (economicsBillResult, error)`. |
| +- Produces: `func (s *Server) manualBillBasis(raw string) (string, error)` in `economicspass.go`. `""` gives the default (`account` if declared, else `""`), `account` gives `BasisAccount`, `whole` gives `BasisWholeAccount`, and anything else is an error. The API request gains `Basis string` with JSON tag `basis,omitempty`. CLI: `func validBillBasis(s string) error` accepts `""`, `account` and `whole`; `func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64, basis string) (economicsBillResult, error)`. |
| - [ ] **Step 1: Write the failing tests.** |
| - - `TestEconomicsBillBasisDoors` (form and API, table): basis `tagged` stores `tagged`. No basis with the account scope stores `account`. No basis with the zero scope stores `""`. `bogus` gives the form 400 and the API 400 `basis must be tagged or account`, and nothing is written. |
| - - Extend `TestAPISessionEconomicsBillWireShape`: with `basis "account"` the body carries `"basis":"account"`; with `""` the key is absent, so an older console sees the same body as before. |
| + - `TestEconomicsBillBasisDoors` (form and API, table): basis `account` stores `account`. No basis with the account scope stores `account`. No basis with the zero scope stores `""`. `whole` with the account scope stores `""`. `tagged` and `bogus` give the form a 400 and the API a 400 `basis must be account or whole`, and nothing is written. |
| + - Extend `TestAPISessionEconomicsBillWireShape`: with basis `"account"` the body carries `"basis":"account"`; with `""` the key is absent, so an older console sees the same body as before. |
| - `TestValidBillBasis`. |
| - [ ] **Step 2: Run** `go test ./internal/console -run TestEconomicsBillBasisDoors -count=1` and `go test . -run 'TestAPISessionEconomicsBill|TestValidBillBasis' -count=1`; expect FAIL. |
| -- [ ] **Step 3: Implement.** The form's select defaults to the option that matches the scope (C7). The CLI prints `basis: <label>` using the stored basis (C8). Add `--basis` to the `cli.md` example paragraph; `internal/docsite` checks headings only, and none change. |
| -- [ ] **Step 4: Run Step 2 again**, plus `go test ./internal/docsite -count=1`; expect PASS. |
| -- [ ] **Step 5: Census.** Add `economics.go:economicsBill<TAB>request gains optional basis; no read added`, the same for `runEconomicsBill` and `economicsBillResult`; rerun `make census-propose` with the same NAME. |
| +- [ ] **Step 3: Implement.** The form's select defaults to the option that matches the scope (C5). The CLI prints `basis: <label>` using the stored basis (C6). Add `--basis` to the `cli.md` example paragraph. `internal/docsite` checks headings only, and none change. |
| +- [ ] **Step 4: Run Step 2 again**, plus `go test ./internal/docsite ./internal/provision -run 'TestDocsite|TestPlan9B8RecordWriteCensus' -count=1`; expect PASS. The handlers call `upsertBill` and hold no write site of their own; if the record-write census reports one, follow Task 1 Step 6. |
| +- [ ] **Step 5: Root-read census.** Add CLAIMS lines `economics.go:economicsBill<TAB>request gains optional basis; no read added`, and the same for `runEconomicsBill` and `economicsBillResult`. Rerun `make census-propose` with the same NAME. |
| - [ ] **Step 6: Commit** `economics bill: say what a hand-entered bill covers` |
| -**Slice A ends here.** Before merge: `make test`, `go build ./...`, whole-branch review, census verdict on #280. Switch-on for Carloku is below. |
| - |
| -### Task 5: Tag mode: filter Cost Explorer to `carlos:deployment`, only while the tag is live |
| - |
| -**Risk/review:** billing figures, the IAM grant on the console's role, census (`infra/`). Independent task review plus the census reviewer. Production IAM is changed only by a later apply that Paul approves. |
| - |
| -**Files:** |
| -- Modify: `internal/console/costscope.go`, `cmd/console/costscope.go` (+ tests); `internal/console/cepull.go` (filter, tag status); `internal/console/server.go:1336-1343` (seam and day cache fields); `internal/console/economicspass.go` (`billBasisFor` tag branch); `internal/console/platformcost.go` (`costBasisHint` C5); `infra/modules/region-host/main.tf:406-424` (comment and action), `infra/modules/region-host/variables.tf:203-207` (description) |
| -- Test: `internal/console/economicsbill_test.go`, `internal/console/cepull_test.go` (create) |
| - |
| -**Interfaces:** |
| -- Consumes: Tasks 1-2. |
| -- Produces: |
| - - `CostScope.DeploymentTag string`. `Validate` refuses both settings at once and a value outside `^[A-Za-z0-9._:/=+@-]{1,256}$`. `costScopeFromEnv` reads `CONSOLE_COST_DEPLOYMENT_TAG`. |
| - - `const costDeploymentTagKey = "carlos:deployment"`. |
| - - `ceQuery.TagValue string` (`""` means the whole account). |
| - - `func ceFilterFor(q ceQuery) *cetypes.Expression`: nil for `""`, otherwise `&cetypes.Expression{Tags: &cetypes.TagValues{Key: aws.String(costDeploymentTagKey), Values: []string{q.TagValue}, MatchOptions: []cetypes.MatchOption{cetypes.MatchOptionEquals}}}`. `realCECosts` sets `GetCostAndUsageInput.Filter` from it. |
| - - Seam `ceTagStatus func(ctx context.Context) (active bool, since time.Time, err error)`; `func (s *Server) resolveCETagStatus(ctx context.Context, now time.Time) (active bool, since time.Time, err error)` caches the answer, error included, per UTC day (`ceTagDay string`, `ceTagActive bool`, `ceTagSince time.Time`, `ceTagErr error`; single goroutine, as `cepull.go:36` explains); `func (s *Server) realCETagStatus(ctx context.Context) (bool, time.Time, error)` calls `ListCostAllocationTags{TagKeys: []string{costDeploymentTagKey}}` on the shared client, logs a failure once (`ceTagWarnOnce`) and never calls `disableCE`. |
| - - `func tagStatusFrom(out *costexplorer.ListCostAllocationTagsOutput) (active bool, since time.Time, err error)`: `Status == CostAllocationTagStatusActive`; `since` from `LastUpdatedDate`, parsed as RFC 3339, then `2006-01-02`; unparseable is an error; key absent is inactive. |
| - - `billBasisFor` tag branch: `(ceQuery{start, end, tag}, BasisTagged, tag)` only when `active && err == nil && !since.After(start)`; otherwise the whole-account result with `BasisWholeAccount`. |
| - |
| -- [ ] **Step 0: copy review** of C5, C9 and C10, as Task 2 Step 0. |
| -- [ ] **Step 1: Write the failing tests.** |
| - - `TestCostScopeFromEnv` adds: tag `production` sets it; `bad value!` errors; both settings error with the boot diagnostic. |
| - - `TestBillPassTaggedFilter`: scope tag `production`, `ceTagStatus` active since `2026-01-01`. `ceCosts` sees `TagValue "production"` for both months; bills are `tagged`/`production`. |
| - - `TestBillPassTaggedNeedsActiveTag` (table, `now 2026-08-11`): inactive → both `""` with `TagValue ""`. Active since `2026-08-05` → both `""`. Active since `2026-07-01` → both `tagged`. Active since `2026-07-15` → `2026-07` `""`, `2026-08` `tagged`. Status error (an AccessDenied-shaped `smithy.GenericAPIError`) → both `""`, and `fx.srv.ceDisabled` stays false. |
| - - `TestBillPassTagStatusOncePerDay`: two passes the same UTC day call `ceTagStatus` once; the next day, once more. |
| - - `TestCEFilterFor` and `TestTagStatusFrom` (`cepull_test.go`) with the exact values above. |
| - - `TestCostBasisLabelAndHint` adds C5 for a `""` bill under tag scope. |
| -- [ ] **Step 2: Run** `go test ./internal/console ./cmd/console -run 'TestCostScopeFromEnv|TestBillPassTag|TestCEFilterFor|TestTagStatusFrom|TestCostBasisLabelAndHint' -count=1`; expect FAIL. |
| -- [ ] **Step 3: Implement** the Interfaces. In `main.tf` the grant becomes `Action = ["ce:GetCostAndUsage", "ce:ListCostAllocationTags"]`. Update the comment above it and the variable description ("Grant Cost Explorer reads (GetCostAndUsage, ListCostAllocationTags) so a console on this box can pull the monthly bill …"). The managed-fleets isolation list (`tests/managed_fleets/managed_fleets.tftest.hcl:384-400`) names no `ce:` action, so it still holds. |
| -- [ ] **Step 4: Run Step 2 again**; expect PASS. If `tofu` is installed: `tofu -chdir=infra/modules/region-host init -backend=false && tofu -chdir=infra/modules/region-host test`; expect PASS. Tofu tests are not in CI. |
| -- [ ] **Step 5: Census.** CLAIMS lines for `infra/modules/region-host/main.tf` (`envelope`: the console role may also list cost allocation tag status; no root read) and `variables.tf` (description only); rerun `make census-propose`. |
| -- [ ] **Step 6: Commit** `economics: count only carlos:deployment-tagged costs in tag mode` |
| - |
| -### Task 6: List what is not tagged, and the operator runbook |
| - |
| -**Risk/review:** UI and docs; whole-branch review. |
| - |
| -**Files:** |
| -- Create: `internal/console/costtags.go`, `internal/console/costtags_test.go` |
| -- Modify: `internal/console/economicsview.go` (three fields, filled only in tag mode), `templates/economics.html` (section after the bill table), `internal/console/economicspage_test.go`, `infra/modules/README.md` (new section after "Self-hosting from your own repo", `:162`; Markdown, outside census) |
| - |
| -**Interfaces:** |
| -- Consumes: `func (s *Server) loadInventory(ctx context.Context) (*infraview.Inventory, string)` (`infrapass.go:162`); Task 5's `CostScope.DeploymentTag`, `costDeploymentTagKey`. |
| -- Produces: `func untaggedCostResources(inv infraview.Inventory, deployment string) (untagged []infraview.Resource, unchecked map[string]int)`. Kinds whose tags the inventory reads and that cost money are `ec2:instance`, `ec2:volume`, `ec2:eip` and `infraview.KindOther`. One of these is untagged when `Tags[costDeploymentTagKey] != deployment`. Kinds whose tags the inventory does not read are `infraview.KindBucket`, `KindDNSZone` and `KindAlarm`; they are counted in `unchecked` by kind. Everything else is ignored (security groups, VPCs, subnets, IAM, records and certificates cost nothing themselves). Sort by kind, then ID. `EconomicsView.Untagged []infraview.Resource` (first 50), `UntaggedMore int`, `UntaggedUnchecked map[string]int`. |
| - |
| -- [ ] **Step 1: Write the failing tests.** |
| - - `TestUntaggedCostResources`: an instance tagged `production` is excluded; one tagged `staging` is included; an untagged volume and an untagged `other` are included; a security group, a VPC and a role are ignored; 2 buckets, 1 zone and 3 alarms give `unchecked {"bucket":2,"dns_zone":1,"alarm":3}`; the order is stable. |
| - - `TestEconomicsPageListsUntagged`: tag scope plus a seeded `infra/inventory.json` shows C9 and the rows; the zero or account scope shows no section and makes no inventory read (count `Get` calls on `infraview.InventoryKey` through `WrapReleases`). |
| -- [ ] **Step 2: Run** `go test ./internal/console -run 'TestUntaggedCostResources|TestEconomicsPageListsUntagged' -count=1`; expect FAIL. |
| -- [ ] **Step 3: Implement**, reading the inventory concurrently with the other reads in `buildEconomicsView` (`:439`), only when `DeploymentTag != ""`. |
| -- [ ] **Step 4: Write the runbook section** "Counting only CARLOS in the AWS bill" (C10, through copy review). Contents, in order: |
| - 1. Choose: `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` when the account runs nothing else, otherwise tag mode. With neither, the Billing pages hide costs. |
| - 2. Tag mode: add `default_tags { tags = { "carlos:deployment" = "<name>" } }` to every `aws` provider block in the root, the default and each region alias. Read the plan: tag changes apply in place, but a root with `user_data` drift restarts boxes on a whole-root apply, so target. Group boxes are already tagged through their launch template. |
| - 3. Tag what tofu does not make: tenant object-store buckets and steering health checks, with `aws resourcegroupstaggingapi tag-resources --resource-arn-list <arn>... --tags carlos:deployment=<name>`. The Economics page lists what is still untagged. |
| - 4. Activate the tag from the paying (management) account: `aws ce update-cost-allocation-tags-status --cost-allocation-tags-status TagKey=carlos:deployment,Status=Active`. It can take up to a day to appear, and costs are tagged from activation onward. A month counts as tagged only if it starts on or after the activation date. |
| - 5. Set `enable_cost_explorer = true` on the region-host that runs the console, which now also grants `ce:ListCostAllocationTags`. Then set `CONSOLE_COST_DEPLOYMENT_TAG=<name>` on the console and restart it. |
| -- [ ] **Step 5: Run Step 2 again**; expect PASS. |
| -- [ ] **Step 6: Commit** `economics: list resources the CARLOS tag misses` |
| - |
| -**Slice B ends here.** `make test`, `go build ./...`, whole-branch review, census verdict on #280. |
| +Before merge: run `make test` and `go build ./...`, then the whole-branch review and both census verdicts on #280. |
| --- |
| ## Census and cross-compile |
| -- In census scope: `internal/economics/bill.go` (Task 1), root `economics.go` (Task 4), `infra/modules/region-host/main.tf` and `variables.tf` (Task 5). None adds a root read. The host-side bill classifier (`internal/hostops/storage_classifier.go:145`) decodes into `economics.Bill` strictly, so a new binary admits the new keys with no `hostops` source change. A box running an older binary would refuse a bill carrying `basis`, which matters only where console writes pass through that classifier (claim mode, shelved). Roll boxes before the console, as usual (memory `roll-order-dev-first`). Brief a reviewer from the other family (Astra for a Claude author) with the card and record the verdict on #280. |
| -- Cross-compile: no OS-specific code. `cepull.go` uses the already-imported Cost Explorer client, and the CLI change is plain `flag`/`encoding/json`. `20-cross@5` covers darwin, windows and linux-arm64. |
| -- Not in census scope: `internal/console`, `cmd/console`, templates, Markdown. |
| +- Root-read scope: `internal/economics/bill.go` (Task 1) and root `economics.go` (Task 4). Neither adds a root read. The host-side bill classifier (`internal/hostops/storage_classifier.go:145`) decodes strictly into `economics.Bill`, so the new binary admits the new key with no `hostops` source change. A box running an older binary would refuse a bill carrying `basis`. That matters only where console writes pass through that classifier (claim mode, shelved). Roll boxes before the console, as usual (memory `roll-order-dev-first`). Brief a reviewer from the other family (Astra for a Claude author) with the card and record the verdict on #280. |
| +- Record-write census: no fingerprinted unit changes by design (Task 1 Step 6 checks, and says what to do if one does). |
| +- Cross-compile: no OS-specific code. `20-cross@5` covers darwin, windows and linux-arm64. |
| ## Switch-on |
| -- **Slice A, Carloku (Paul named it, 2026-11-09).** After a release containing slice A rolls (dev first), set `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` in the flagship console's environment, where `CONSOLE_DOMAIN_PROOF` lives, and restart the console. This is a production configuration change: ask Paul for the go at the roll. Check: `/fleet/economics` shows C2 for October and November, and October's figure equals the AWS Billing console's October total less tax (read-only check; profile per memory `aws-from-the-sandbox`). That is spec §7's "matches the CARLOS-only AWS figure" check. |
| -- **Dev:** no setting, so costs stay hidden. Dev has no Cost Explorer grant and a mixed account. |
| -- **Slice B:** merge when Paul names its first user (dev or Tito) and approves the scoped tagging and tag activation in that account. |
| +- **Carloku (Paul named it, 2026-11-09).** After a release containing this plan rolls (dev first), set `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` in the flagship console's environment, where `CONSOLE_DOMAIN_PROOF` lives, and restart the console. This is a production configuration change, so ask Paul for the go at the roll. To check: `/fleet/economics` shows C1 for October and November, and October's figure equals the AWS Billing console's October total less tax (read-only; name a profile, per memory `aws-from-the-sandbox`). This is spec §7's "matches the CARLOS-only AWS figure". |
| +- **Every other console** (dev, Tito, self-hosters): no setting, so CARLOS-only costs stay hidden with hint C3. |
| + |
| +## Later: tag-basis costs for mixed accounts (deferred by the coordinator, 2026-11-09) |
| -## Follow-ups (not in this plan) |
| +The spec's default (§4.5) is a Cost Explorer pull filtered to `carlos:deployment=<value>`, for an AWS account that also holds non-CARLOS resources. It is deferred: no live console needs it today. The follow-up plan should start from these points: |
| -- Tag tenant object-store buckets (`internal/objstore/aws.go:294`) and steering health checks at creation when a tag is configured. This needs `s3:TagResource` and `route53:ChangeTagsForResource` on the console role, plus census review. |
| -- Default `CONSOLE_COST_DEPLOYMENT_TAG` from `CARLOS_MANAGED_FLEET_DEPLOYMENT` once 2b-2 merges. |
| -- AWS credits are inside `UnblendedCost` and lower the figure. If Paul wants gross cost, filter `RECORD_TYPE` later. |
| +- **Tagging today (survey, 2026-11-09).** Only region HA group boxes carry `carlos:deployment` (`infra/modules/region-host/group.tf:19-23`). Managed-fleet boxes and buckets will once 2b-2 wires `internal/awsmanaged` in (`compute.go:197`, `storage.go:182`). Single hosts, their volumes and EIPs, scanner and PDF hosts, deployment and data buckets, alarms, SNS, SQS and the NLB carry `Name` at most. Tenant object-store buckets (`internal/objstore/aws.go:294`) and steering health checks are created untagged. Neither private infrastructure root sets `default_tags`. A tag-filtered bill today would count almost nothing. |
| +- **Tag activation does not prove coverage (Astra #10).** An active cost allocation tag only says Cost Explorer can filter on it, not that every CARLOS resource carries it. Before tagged costs are shown as the platform cost, the follow-up must establish verified coverage. For example, it could require the untagged list below to be empty of CARLOS resources, or tag everything the console creates at creation time and check the inventory, and it must state what happens to a month without that proof. Keep the month-level rule as well: a month counts only if the tag was `Active` (`ListCostAllocationTags`, `LastUpdatedDate`) from its first day. Activation happens in the paying (management) account, applies from activation onward, and needs `ce:ListCostAllocationTags` on the console's role (`infra/modules/region-host/main.tf:410`, which puts `infra/` into the root-read census). |
| +- **Inventory vocabulary (Astra #9).** `infraview.Resource.Kind` values are `machine`, `disk`, `ip`, `bucket`, `dns_zone`, `alarm`, `other` and so on (`internal/infraview/infraview.go`). The AWS strings `ec2:instance`, `ec2:volume` and `ec2:eip` are `NativeType`. Select by `Kind`, and test against real inventory shapes produced by `internal/awsinv`. Note that the inventory reads tags for EC2 resources and the tagging catch-all, but not for buckets, hosted zones or alarms (`internal/awsinv/rest.go`, `ec2.go`). |
| +- **Tagging what the console creates** (tenant buckets, steering health checks) needs `s3:TagResource` and `route53:ChangeTagsForResource` on the console role and census review. The 2b-1 managed-fleet storage already creates buckets with tags (`CreateBucketConfiguration.Tags`). |
| +- **Shape that fits this plan.** The new stored basis value `tagged` (plus the tag value) is additive. This plan already reads unknown values as whole-account, so an older console never shows tagged figures as CARLOS-only. The setting should be added only when it is honoured end to end, and could default from `CARLOS_MANAGED_FLEET_DEPLOYMENT` once 2b-2 merges. |
| +- AWS credits sit inside `UnblendedCost` and lower the figure. If Paul wants gross cost, filter `RECORD_TYPE`. |