carlos / platform Public

Plan: apply Astra round 2 on the instance usage plan

The CLI reads the usage answer through a bounded reader up to 8 MiB
with an overflow error, and the route's read faults are filed as a
failed job run. Adds the round 3 brief.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 70e5076f372301938421580c4257cba915c3e326 parent 1e8d79d
3 files changed, +164 −2
  • docs/superpowers/plans/2026-11-29-instance-usage.md +29 −2
  • docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md +33 −0
  • docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R3.md +102 −0
diff --git a/docs/superpowers/plans/2026-11-29-instance-usage.md b/docs/superpowers/plans/2026-11-29-instance-usage.md
index 502244428..b06ff8be1 100644
--- a/docs/superpowers/plans/2026-11-29-instance-usage.md
+++ b/docs/superpowers/plans/2026-11-29-instance-usage.md
@@ -526,6 +526,11 @@ past step 2, but a month whose start is before `From` is 409 with body
(`hotreads.go` ~405). Real bodies are still decoded with the key check.
- Absent: nothing. Any other error, a decode or key failure, or over the
read cap: the whole answer is 503 with `Retry-After: 60`, logged.
+- The read (the LIST and every Get, not the gate or the memo hit) runs
+ inside `s.jobs.Run(ctx, "InstanceUsageRead", read)`, as
+ `apidoorkeys.go:364` runs a door's work, so a read fault is the job's
+ failed run on the operator's jobs page (spec §8 "filed as a failed
+ job"); the read returns the fault as its error.
- Sum per host over boxes and dates; `""` is `unattributed`; `total` is
both; instances sorted by host; more than 10,000 hosts is 409 (Task 0
copy). `read_at` is `now` RFC 3339 UTC.
@@ -553,7 +558,9 @@ it as it keeps the others.
answers); `TestUsagePendingAndBreakOnMemoHit` (after a 200, flip to
pending: 503; to invalidated: 409; no memo answer leaks);
`TestUsageReadFaults` (read error, bad JSON, key mismatch, body over
- `usageDayReadCap`: each 503 with `Retry-After: 60`);
+ `usageDayReadCap`: each 503 with `Retry-After: 60`, and the
+ `InstanceUsageRead` job's status is `JobFailed` with that error; a
+ following clean read sets it back to `JobOK`);
`TestUsageCap` (10,001 hosts: 409; 10,000: 200);
`TestUsageOtherAppCredential` (a usage credential for app A asking for
app B: 404); `TestUsageMonthBounds` (Review Focus 3: malformed and
@@ -592,7 +599,13 @@ must return an error: NOT `requireAPISession`, `resolvedAccount` or
`resolvedApp`, which `log.Fatal`. Follow `release_pull.go` (~60-80):
`resolveMode(consoleFlag)` (nil session is an error: API mode only),
`apiAccount(acctRaw, acctIDRaw)`, and `sess.defaultAccount(ctx)` when no
-account is given; the session's `getJSON`. `--json` prints the route's body as received. Human output: the
+account is given. NOT the session's `getJSON`: it reads at most 1 MiB
+and returns a truncated body without an error (`apimode.go` ~817), and a
+valid answer at the 10,000-instance cap with long hostnames is about
+3 MB. Add `func (s *apiSession) getJSONLimit(ctx context.Context, path string, limit int64) (int, []byte, error)`
+beside it, reading `limit+1` bytes and returning an overflow error past
+`limit`; have the existing 1 MiB path call it so there is one reader.
+`carlos usage` reads with `usageResponseLimit = 8 << 20`. `--json` prints the route's body as received. Human output: the
Task 0 approved layout, bytes through the root package's existing
human-bytes formatter. A 409 with `first_month` prints the approved
"counting starts" line and exits 0; other non-2xx return an error with the
@@ -605,6 +618,11 @@ route's message.
`TestUsageRefusesBadMonth` (`--month 2027-1` errors before any request);
`TestUsageErrorsReturn` (no `--app`, no session, an unknown flag, a
default-account failure: each a returned error, no exit);
+ `TestUsageLargeAnswer` (a fake console returns a valid answer of
+ 10,000 instances with 253-character hosts, over 1 MiB: `--json` prints
+ it byte for byte, the human output decodes it; an answer over 8 MiB is
+ a returned overflow error, never a truncated print);
+ `TestGetJSONLimitOverflow` (limit n: n bytes read whole, n+1 an error);
`approved_usage_copy_test.go` pins every approved string.
- [ ] **Step 2: Run** `go test . -run 'Usage|Parity|DocSite' -count=1`: FAIL.
- [ ] **Step 3: Implement;** add the parity row in the observe block,
@@ -671,3 +689,12 @@ NOT READY, one P1 and six P2. Resolved in this revision:
| 5 P2, CLI helpers that `log.Fatal` | CLI error propagation | `release_pull.go`'s error-returning helpers, `ContinueOnError`; witness added (Task 7) |
| 6 P2, missing witnesses T9, T11, T7 | Required regression coverage | `TestInstanceFlushAppsApart`, `TestDomainMovedMidHourSplitsAtCountTime`, `TestUsageFromSelfInvalidation` |
| 7 P2, browser UX and user copy review | User-facing review gates | The form never lists `usage`, so no screen changes; the copy gate is Luna, as the controller's brief from the coordinator directs (declined in part) |
+
+**Round 2** (Astra, on `1b6a8b90b`, `CODEX-FINDINGS-instance-usage-plan-R2.md`):
+NOT READY. All seven round 1 findings resolved. One P1 and one P2, both
+new families:
+
+| Finding | Fault family | Resolution |
+|---|---|---|
+| 1 P1, the CLI's GET reads 1 MiB and truncates silently | End-to-end response-size compatibility | `getJSONLimit` with an overflow error; `carlos usage` reads up to 8 MiB; witnesses over 1 MiB and over 8 MiB (Task 7) |
+| 2 P2, read faults not filed as a failed job | Operational visibility of read failures | The read runs inside `s.jobs.Run(..., "InstanceUsageRead", ...)`; the fault test asserts `JobFailed` (Task 6) |
diff --git a/docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md b/docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md
new file mode 100644
index 000000000..7b355f800
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md
@@ -0,0 +1,33 @@
+Round 1 dispositions:
+
+- R1-1 P1 — **Resolved:** CLI-only parity row with a registered work package.
+- R1-2 P2 — **Resolved:** both mint handlers enforce the switch; the store enforces app binding.
+- R1-3 P2 — **Resolved:** unread history returns 503 without changing `@from`.
+- R1-4 P2 — **Resolved:** prefetch uses valid per-key dry bodies.
+- R1-5 P2 — **Resolved:** CLI resolution returns errors and uses `ContinueOnError`.
+- R1-6 P2 — **Resolved:** the three missing regression witnesses are specified.
+- R1-7 P2 — **Resolved within the brief’s scope:** the form excludes Usage; the authorized Luna copy gate stands.
+
+1. **P1 — Task 7: the selected HTTP helper truncates supported responses.**
+
+ [Plan:595](/home/paulca/.paseo/worktrees/03ai90xp/instance-usage/docs/superpowers/plans/2026-11-29-instance-usage.md:595) directs the CLI to use `sess.getJSON` and print the received body unchanged for `--json`. That helper delegates to `getJSONHeader`, which reads through `io.LimitReader(res.Body, 1<<20)` and returns the truncated body without an error ([apimode.go:817](/home/paulca/.paseo/worktrees/03ai90xp/instance-usage/apimode.go:817)).
+
+ **Failure scenario:** a valid answer containing 10,000 instances with 253-character hostnames exceeds that limit. An in-memory fixture using those hosts and two ten-digit counters produced **3,100,244 bytes**. Human output cannot decode the truncated JSON; `--json` prints an incomplete answer.
+
+ **Fix:** specify a usage-specific bounded reader, or a helper accepting a response limit, large enough for the maximum supported answer. Read one extra byte and return an explicit overflow error. Test both human output and byte-for-byte JSON output with a response exceeding 1 MiB.
+
+ **Fault family:** end-to-end response-size compatibility.
+
+2. **P2 — Task 6: unreadable objects are not recorded as failed jobs.**
+
+ [Plan:527](/home/paulca/.paseo/worktrees/03ai90xp/instance-usage/docs/superpowers/plans/2026-11-29-instance-usage.md:527) specifies logging and a 503, but omits the failed-job record explicitly required by [spec:421](/home/paulca/.paseo/worktrees/03ai90xp/instance-usage/docs/superpowers/specs/2026-11-29-instance-usage-design.md:421). Its read-fault tests likewise check only the response. Calling `jobFailed` directly from the handler would not suffice: it does nothing without a job-run context ([jobs.go:242](/home/paulca/.paseo/worktrees/03ai90xp/instance-usage/internal/console/jobs.go:242)).
+
+ **Failure scenario:** corrupt or oversized usage objects repeatedly cause 503 responses without the required failure appearing in the operator’s job status.
+
+ **Fix:** specify the job-recording boundary around the real read operation, propagate its error into the registry, and extend the fault tests to assert a failed-job record.
+
+ **Fault family:** operational visibility of usage-read failures.
+
+Reviewed commit `1b6a8b90b4e1d216f148a259e49a0616875c3e8b`. No files changed or test suites run.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R3.md b/docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R3.md
new file mode 100644
index 000000000..03af22c53
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-REVIEW-BRIEF-instance-usage-plan-R3.md
@@ -0,0 +1,102 @@
+# Review brief: instance usage implementation plan, round 3 of 3
+
+Repo carlos/platform, branch `instance-usage`, commit <see the prompt>.
+Under review: `docs/superpowers/plans/2026-11-29-instance-usage.md`.
+Authorities: `docs/superpowers/specs/2026-11-29-instance-usage-design.md`
+(revision 5, merged on main as 96731431a; reviewed in three Astra rounds,
+review closed) and AGENTS.md. Do not review against unmerged branches; if
+this work needs one, say so as a P1 and stop.
+
+You are an independent reviewer. Read the plan, then the spec and the code
+it names, and check every claim against that code.
+
+## Fixed: do not re-argue
+
+- Paul's ruling (spec §2, posted on discussion #1519, 2026-11-29): cut
+ completeness. The route returns bytes counted so far as a lower bound,
+ no complete claim, no partial=1, counting valid from the first whole UTC
+ month after switch-on, one file per app. Report only mechanisms that fail
+ to honour it.
+- The spec's design (identity = instance hostname, the family's keys, the
+ role shape, the route's shape) is reviewed and closed. Review whether the
+ PLAN implements it faithfully and buildably, not the design itself.
+
+## What to check
+
+1. Spec coverage: every requirement R1-R7, decision D1-D8 and test T1-T13
+ has a task that implements and tests it.
+2. Exactly-once (spec §5): does Task 3's queue algorithm and `writePart`
+ guarantee at most once per batch and object, at least once while queued,
+ ordering per object, markers kept forever, and the drop horizon as a
+ limit on starting writes? Name any interleaving that double counts.
+3. `@from` (spec §4, Task 6): does `usageFromCheck` move `from` only on a
+ real break and only forward, leave it untouched on a pending or retried
+ start-up check, and read the console's hostname history correctly
+ (`internal/console/hostsused.go` `hostsCached`, `hostsActive`,
+ `invalidateHosts`, `provision.HostsState.At`)? Is `RunUsageFrom` enough
+ to write `@from` on switch-on day with no route call?
+4. Authority (Task 5): is the usage role truly confined to one door, and is
+ every mint path (CLI services door, browser services page, platform
+ credentials) covered? Check `internal/svcrole/svcrole.go`,
+ `internal/console/svcprincipal.go`, `apiservices.go`, `svcpage.go`,
+ `platform_credentials.go`, `svcroutes_test.go`.
+5. The meter (Task 2): the three callers (`internal/edge/edge.go` ~2771,
+ `demo_traffic.go` ~217, `assetcatch.go` ~1159-1177), the far catch's
+ primary rule, and that the old `usage/edge/` family is byte-identical.
+6. The cache (`internal/console/usagedays.go`): is the plan's change to
+ `usageDayDate` and the route's use of `usageDayReader` correct for keys
+ whose last segment is not a date?
+7. Buildability: names, signatures and file paths that do not exist or
+ conflict with the code; tests that cannot be written as described;
+ AGENTS.md rules (census, parity, docsite, code health, race, copy).
+
+## Round 2
+
+Earlier rounds: round 1, `docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R1.md`
+(one P1, six P2, all resolved in round 2); round 2,
+`docs/superpowers/plans/CODEX-FINDINGS-instance-usage-plan-R2.md` (one P1,
+one P2). The plan's "Review history" section says how each was
+handled. Finding 7's call for the user's own copy review is declined: the
+operator's brief for this branch names Luna (gpt-6-luna) as the copy
+gate; raise it again only with new evidence.
+
+First give one line per P1 and P2 from round 2: resolved, partly, or
+not. Carry every unresolved or partly resolved finding forward at its
+current severity, then add new findings. The verdict covers everything
+outstanding, earlier rounds included.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section or task, the problem,
+the evidence (file:line, verified), the failure scenario, a concrete
+fix and the invariant or trust boundary it breaks (that is its fault
+family). End with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+This is round 3, the last in the budget. A NOT READY also says whether
+the P1s share one cause, and whether refusing the case up front or
+cutting the feature would remove them.
+
+Note: Tasks 1 and 2 are already being built on this branch (commits
+after the plan's); review the plan, not that code.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites.