plan: Go code health, fix, hold and improve
The plan behind the 2026-11-16 Go audit (#1123), rev 3: - Fix: batch 2 (merged), then batch 3 led by console request cancellation and the remaining unbounded production calls, then structure with a short spec each (census moved class first). - Hold: a code-health ratchet in CI (site records for "no new ones" rules, totals for trends, records only go down, raises refused against the merge base), the existing guards, and Go rules in AGENTS.md. - Improve: a monthly health pass and a quarterly one-slice audit. Reviewed by Astra (round 1 NOT READY, round 2 READY AFTER FIXES, fixes in rev 3; the database metric's repeated finding answered with one signature classifier). Approved by Paul 2026-11-17. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from code-health-plan into main.
5 files changed,
+549
−0
docs/superpowers/plans/2026-11-16-go-code-health.md+287 −0docs/superpowers/reviews/FINDINGS-code-health-plan-R1.md+80 −0docs/superpowers/reviews/FINDINGS-code-health-plan-R2.md+63 −0docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan-R2.md+71 −0docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan.md+48 −0
CI passed — run details
diff --git a/docs/superpowers/plans/2026-11-16-go-code-health.md b/docs/superpowers/plans/2026-11-16-go-code-health.md| new file mode 100644 |
| index 000000000..c8b4e9b55 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-16-go-code-health.md |
| @@ -0,0 +1,287 @@ |
| +# Go code health: fix, hold, improve |
| + |
| +Status: draft rev 3 for Paul, 2026-11-16 (Astra rounds 1 and 2 answered; review closed at round 2). Backlog and audit reports: amadan |
| +discussion #1123. First batch merged the same day (958ff2e, b064b14, |
| +0374ac2). |
| + |
| +## What this plan is for |
| + |
| +The 2026-11-16 audit found the code careful but with three kinds of gap: |
| +network calls with no deadline, holes in the CI gate, and shapes that keep |
| +growing (a 162k-line console package, 1,200-line functions, 999 |
| +`log.Fatal` calls in the CLI, 1,019 sleeps in tests). The first batch |
| +closed the worst deadlines and two gate holes. |
| + |
| +Fixing the current list once is not enough. Between the audit (5b6d5374) |
| +and the recheck (c4b44c34), eight days apart, by rough text counts the CLI |
| +gained about 45 `log.Fatal` mentions and tests about 147 `time.Sleep` |
| +mentions, and two of the three longest functions grew by 130 to 160 lines |
| +(`handleAPIInstanceCreate` 1,081 to 1,242, `runAgent` 1,090 to 1,222; |
| +`Reconcile` 1,255 to 1,275). These are grep estimates; the scanner in |
| +Part 2 sets the real baseline. So the plan has three parts: |
| + |
| +1. **Fix** what is known, in small reviewed branches. |
| +2. **Hold** every gain with a check in CI, so nothing that was fixed comes |
| + back and nothing measured gets worse. |
| +3. **Improve** steadily: convert code as it is touched, and look again on |
| + a fixed rhythm. |
| + |
| +## Principles |
| + |
| +- **Ratchets, not sweeps.** A count that can only go down beats a |
| + one-time cleanup. Sweeps across hundreds of files cost review rounds and |
| + census cards; ratchets cost nothing until someone touches the code. |
| +- **Convert on touch.** A branch that changes a function brings that |
| + function up to the rules below. No branch exists only to restyle. |
| +- **Guards over rules.** A rule in AGENTS.md is read sometimes; a test |
| + that fails is read every time. Where a rule can be a guard test, it is. |
| +- **Small branches, the stopping rules unchanged.** One concern per |
| + branch, Opus builds, Astra reviews (Fable for whole-branch reviews |
| + where the tier matters), three rounds at most. |
| +- **Recheck before building.** Every backlog item is checked against |
| + current main first; the audit's own baseline was 159 commits stale. |
| + |
| +## Part 1: fix |
| + |
| +### Batch 2 (started 2026-11-16) |
| + |
| +| Branch | What | Census | |
| +|---|---|---| |
| +| `audit-bugs-2` | ledger verify timeout and `{}` HEAD panic (cli.go); system update decode errors (system.go); "ops" substring match (console/ownership.go); #1141 subdomain lost race; silent capacity page (host/haplacement.go); escrow alerts matched by string prefix (activator/escrow.go) | yes | |
| +| `audit-console-shutdown` | console drains HTTP and its workers on SIGTERM before releasing the policy lease, so rolls stop dropping requests | no (console) | |
| +| `audit-govulncheck` | `50-govulncheck` CI step with an explicit, dated exception file; GO-2026-6859 listed under the 1.26.10 pin (#897, #904) | no | |
| +| `audit-edge-test-sleeps` | about 13 s of fixed sleeps in edge tests replaced through the seams that exist (`Edge.watchTick`) and one new one (`holderHeaderSuspectAfter` becomes a variable a test can shrink, at the same value) | yes: the new seam changes internal/edge production code | |
| + |
| +Plus the one-line AGENTS.md fix: its sandbox note recommends a GOCACHE |
| +path the machine policy bans (rides `audit-bugs-2`). |
| + |
| +Batch 2 keeps the edge test-sleep branch because it was already under way |
| +and is small; from batch 3 on, production deadline gaps come before test |
| +speed. |
| + |
| +### Batch 3: production deadlines first, then the follow-ups |
| + |
| +In this order: |
| + |
| +- **Console request cancellation, in place.** Request handlers call store |
| + methods without their request context (for example |
| + internal/console/oppeople.go:102, :127), on a store with one connection |
| + (store.go:122), so an abandoned request keeps its place in the queue. |
| + Thread the request context through the store methods those handlers use, |
| + starting with the busiest request paths; no package move needed. |
| +- **The remaining unbounded production calls:** the edge prober's dial |
| + (internal/edge/upstreamdial.go:16); host `systemctl`/`journalctl` calls |
| + with no timeout (internal/host/systemunits.go:327, unitsettle.go:75, and |
| + the loops adoptLoop, fastConvergeLoop, statusLoop, configSync/configGen) |
| + through one bounded helper with a guard test. |
| +- #1143: credential clients get the body bound; an explicit buildable |
| + client stays the caller's; the AWS client guard catches field |
| + assignment and option callbacks. |
| +- staticcheck's excluded families, one branch each, then switched on: |
| + SA4006 (70, includes #1141's shape), SA1019 (70), SA1012 (177, mostly |
| + nil contexts in internal/registry). |
| +- Racy test helpers (host/caps_pass_test.go captureLog, |
| + activator/wakecheck_test.go), then a targeted `-race` CI step on edge, |
| + activator, lease and host. |
| +- gitleaks as its own CI step. |
| + |
| +### Batch 4 onward: structure, each with its own short spec |
| + |
| +In this order, because each makes the next cheaper: |
| + |
| +1. **Census `moved` class** in `census-propose`: a pure file move carries |
| + its disposition, its reviewer approval and its J4 witness obligations |
| + instead of reading as a removal plus a new unit. It is a dependency only |
| + of the relocations below that move files inside the root binary's graph |
| + (2, 3, and any host split). Console-only work (4 and 5) is outside |
| + the root census and does not wait for it. |
| +2. **Leaf package for the S3 `Store` interface** out of |
| + `internal/release` (67 importers, all linking the registry and SQLite |
| + today). |
| +3. **Leaf package for the names console takes from activator and edge**, |
| + so the console stops linking about 90k lines of production code it |
| + barely uses (89,626 at c4b44c34). This one is census-touching: the |
| + names live in root-linked files (`edge.FleetArmVerdict` decides routing |
| + eligibility, internal/edge/fleetforward.go:322), so extracting them |
| + changes census-covered source. Its spec decides whether the `moved` |
| + class covers it or it needs ordinary unit and envelope proposals. |
| +4. **Console request contexts, the rest**: after batch 3's request paths, |
| + the remaining store calls, held by the ratchet's database metric. |
| +5. **Console split, staged**: widen the 15 package-directory source guards |
| + first, then `consoledb` (the Store), then billing, alerts, operator |
| + pages, architecture view and PDF, one at a time. |
| +6. **CLI commands return errors**: convert on touch to |
| + `runXWithSession(ctx, sess, args, out) error`; the ratchet below holds |
| + the count. |
| + |
| +## Part 2: hold |
| + |
| +### A code-health ratchet in CI |
| + |
| +A test-only package, `internal/codehealth`, scans the tree once per gate |
| +run and compares it with a checked-in record, `.amadan/code-health.tsv`. |
| +It is outside the census: the census scope comes from the root binary's |
| +production dependencies, and nothing links a test-only package. The idea |
| +is Rastrillo's `.rastrillo/code.txt` (offences recorded when the gate |
| +began, records only go down), adapted for many parallel branches. |
| + |
| +**Two kinds of record.** |
| + |
| +- **Sites**, for rules that say "no new ones": each existing offence is |
| + recorded by identity (package, enclosing function, callee) with a count. |
| + A new site, or a higher count at an existing one, fails the gate even if |
| + an old one was removed elsewhere, so removing one offence never pays for |
| + another. Moving code within a package keeps the identity. A rename or a |
| + move to another package goes through `make code-health-record |
| + MOVE=<old>:<new>`, which carries the existing allowance across and can |
| + never increase it. It writes the new site with a `# moved-from: <old>` |
| + comment and removes the old one in the same edit; the CI step below |
| + accepts a new site carrying that comment only when the old site's |
| + allowance in the merge base is at least as large and the old site is |
| + gone. A transfer is not a raise. |
| +- **Totals**, for trends with no "no new ones" rule (packages importing |
| + internal/release, say): a number per metric and package. |
| + |
| +**What fails, and what does not.** |
| + |
| +- An offence above its record fails the gate and names the site. |
| +- A count below its record does not fail. The gate prints the lower |
| + number. So two branches that each remove a different sleep both pass, |
| + and main after both merges passes too (it is simply below its record). |
| +- `make code-health-record` only lowers records and drops sites that are |
| + gone. It cannot add a site or raise a number. Adding or raising needs a |
| + hand edit with a `# raised: <reason>` comment on the line. |
| +- A separate CI step compares `.amadan/code-health.tsv` with the merge |
| + base's copy (fetching main if the runner lacks it) and fails on any |
| + added site or raised number unless the line carries `# raised: |
| + <reason>` or is a valid `# moved-from:` transfer, so a raise is always |
| + a visible, reviewed decision and a transfer is checked mechanically. |
| +- Records drift below the code only when nobody runs the lowering |
| + command; the monthly pass catches that (Part 3). |
| + |
| +**How it measures.** With type information (`golang.org/x/tools/go/packages`, |
| +already a dependency), not text, for the root module and `launchctx`, |
| +under `GOOS=linux`, as the union of two configurations: no tags (what |
| +production builds) and the gate's tags (`rootrunner`, |
| +`carlos_cutover_witness`), with a site seen in both counted once. That |
| +way a `!rootrunner` production file (internal/host/departure_queue_default.go) |
| +is measured too; a fixture proves it. Files built only for darwin or |
| +windows are outside the first version and listed as such in the scanner's |
| +output. Generated files (`// Code generated`) and |
| +`testdata` are skipped. Import aliases are resolved by type, so |
| +`log.Fatal` under another name still counts. Each metric has fixture |
| +tests showing what it counts and what it ignores. Its run time is measured |
| +on CI before it joins the gate; if it is slow it runs as its own CI step. |
| + |
| +**Metrics at the start.** The scanner sets the real numbers; these are |
| +grep estimates from c4b44c34. |
| + |
| +| Metric | Kind | Estimate | |
| +|---|---|---| |
| +| `log.Fatal*` and `os.Exit` calls in root-package production files | sites | about 999 and 120 mentions | |
| +| `time.Sleep` calls in test files | sites | about 1,019 mentions | |
| +| database operations without a context (one classifier, below), in every package, so moving code into a new package (e.g. `consoledb`) does not hide them | sites | 459 in console via `s.db` alone; more with `tx`, `Stmt` and interfaces | |
| +| functions over 300 lines, counting only lines with code (blank and comment-only lines excluded) | sites (function, length) | 3 over 1,000 today | |
| +| files over 3,000 lines, same counting | sites (file, length) | to measure | |
| +| packages importing internal/release | total | 67 | |
| +| `context.Background()`/`TODO()` in internal/host production code | sites | to measure | |
| + |
| +**The database classifier** is one function with one rule, so receiver |
| +spelling, narrow interfaces and package moves cannot hide a call: a call |
| +is a database operation without a context when its static callee is |
| +`Query`, `QueryRow`, `Exec`, `Prepare` or `Begin` and either (a) it is a |
| +method of `database/sql`'s `DB`, `Tx`, `Conn` or `Stmt`, or (b) it is a |
| +method of any other type or interface whose signature is identical to |
| +the same-named `database/sql` method. (b) catches console's |
| +`sqlQueryer.QueryRow` (internal/console/billingpayments_store.go:73) and |
| +`sqlHandle.Begin` (store_gate.go:110) without listing them. Its context |
| +counterpart is the `...Context` method, and `BeginTx` for `Begin`. |
| +Fixtures cover each of those examples, `*sql.Stmt` (internal/registry/registry.go:2874) |
| +and the same calls after a move to another package. If a form turns up |
| +that the rule misses, the rule changes in that one function, with a |
| +fixture; no per-receiver lists. |
| + |
| +Line metrics count code, not comments, so adding a safety explanation |
| +never fails the gate and deleting comments never counts as a gain. Their |
| +physical length is printed as a report only. |
| + |
| +### Guards that already hold a line |
| + |
| +- Every edge `http.Server` sets its timeouts (958ff2e). |
| +- Every AWS client in the root binary goes through the bounded transport |
| + (0374ac2, `TestAWSClientsAreBounded`). |
| +- staticcheck SA checks clean (b064b14), rootrunner tests vetted. |
| + |
| +Each later batch adds its own guard where the rule is mechanical (the |
| +bounded `systemctl` helper, for one). |
| + |
| +### Go rules in AGENTS.md |
| + |
| +A short "Writing Go here" section, each rule pointing at the guard or |
| +ratchet that enforces it: |
| + |
| +- Network calls carry a deadline; AWS clients come from internal/rootaws. |
| +- Functions that have a `ctx` pass it on; a detached |
| + `context.Background()` carries a comment saying why. |
| +- New CLI commands return errors; they do not call `log.Fatal`. |
| +- New tests wait on a signal or a seam, not `time.Sleep`. |
| +- Errors are compared with `errors.Is`/`errors.As` and wrapped with `%w` |
| + when a caller might branch on them; never match `err.Error()` text. |
| +- A function past 300 lines of code, or a file past 3,000 (comments and |
| + blank lines not counted), is split by concern in the branch that would |
| + grow it; deleting comments to fit is not a split. |
| + |
| +## Part 3: improve |
| + |
| +### Monthly health pass (first Monday of the month) |
| + |
| +One session, bounded (one scanner run, one staticcheck run with every |
| +check on, one govulncheck run, at `nice`, on cached builds), reporting |
| +only: |
| + |
| +1. Post the numbers on a standing discussion with the change since last |
| + month: the ratchet, staticcheck with every check on (S, ST, QF, U1000 |
| + included), govulncheck. |
| +2. Where main is below its records, open one small branch that runs |
| + `make code-health-record` (lowering only), reviewed like any other. |
| + Anything above its record on main is a broken invariant: file it as an |
| + Issue at once. |
| +3. Pick the next two or three items from the backlog for the month and |
| + post them for Paul's go. |
| + |
| +Its cost is measured on the first run and stated in the post; if it |
| +exceeds an hour of agent time, the pass is cut down, not the rules. |
| + |
| +### Quarterly audit, one slice at a time |
| + |
| +Each quarter, one read-only Fable auditor takes one slice (console; host |
| +family; activator and edge; root CLI and the rest; in rotation) with the |
| +2026-11-16 brief, against current main. Astra verifies the findings |
| +before they reach the backlog. New findings become backlog items or new |
| +ratchet metrics. Every slice is seen once a year. |
| + |
| +### Tightening over time |
| + |
| +- staticcheck: SA families back on (batch 3), then U1000 (dead code), |
| + then the S and ST checks worth having, one at a time, each with its |
| + findings fixed or recorded first. |
| +- Ratchet thresholds come down once the lists are short: functions from |
| + 300 lines towards 150, files from 3,000 towards 1,500. |
| +- Test speed: the slowest-test list from `test-weights.tsv` is reviewed |
| + each health pass; sleeps over one second are the first targets. |
| + |
| +## What is not in this plan |
| + |
| +Settled by the audit as not worth doing: a `slog` migration, a repo-wide |
| +`%w` or context sweep, moving the CLI to `internal/cli`, subpackages |
| +inside activator, mass-unexporting in host. |
| + |
| +## Done means |
| + |
| +- Batches 2 and 3 merged; staticcheck runs every SA check; govulncheck, |
| + gitleaks and a targeted `-race` run in CI. |
| +- The ratchet in CI; no record raised except by a reviewed `# raised:` |
| + line, and allowances moved only by checked transfers. |
| +- Each structural item merged or explicitly dropped with a reason. |
| +- After that the monthly pass and quarterly audit continue; this plan is |
| + then a rhythm, not a project. |
diff --git a/docs/superpowers/reviews/FINDINGS-code-health-plan-R1.md b/docs/superpowers/reviews/FINDINGS-code-health-plan-R1.md| new file mode 100644 |
| index 000000000..a54b710c7 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-code-health-plan-R1.md |
| @@ -0,0 +1,80 @@ |
| +Reviewed round 1 at `7977edd904c8dcabfccc2fdda5a417d6b295db5e`, against local baseline `c4b44c34`. No files changed; no builds, tests, or subagents run. Discussion #1123 was inaccessible because network access is blocked, so its reports and external issue claims remain unverified. |
| + |
| +1. **P1 — Part 2: the ratchet does not protect gains across merges or record regeneration.** |
| + **Invariant: an accepted baseline cannot increase, and merged code must match it.** |
| + |
| + [Plan lines 99–108](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:99) specify comparison against the branch’s own record and a command that rewrites it. They specify neither comparison with an accepted baseline nor integration handling. |
| + |
| + Two branches can each remove a different sleep, changing the same record from 100 to 99. Both pass independently. Git can merge their identical record edits without conflict, leaving 98 sleeps against a record of 99: the required decrease check then fails on main. The repository explicitly gates the branch tip and checks main afterward ([AGENTS.md:185](/home/paulca/amadan.net/carlos/platform-code-health-plan/AGENTS.md:185)). Separately, rewriting the record upward would satisfy the described equality check. |
| + |
| + **Fix:** define a lower-only update command, reject unauthorized baseline increases against the accepted base, and specify how combined changes are regenerated and gated before landing. Include the two-independent-decreases scenario in the ratchet’s acceptance checks. |
| + |
| +2. **P2 — Part 2: aggregate counts cannot enforce the proposed rules for new code.** |
| + **Invariant: removing an old offence must not authorize a new one.** |
| + |
| + The record is per metric/package ([plan:101](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:101)), while the rules prohibit new CLI fatalities and new test sleeps ([plan:141](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:141)). Removing one old call and adding one elsewhere passes the count check. Counts alone also cannot identify the “new offences” promised at line 105. |
| + |
| + Package splits create another problem: existing sleeps transferred into a new package become new offences there, despite no increase overall. Allowing unrestricted initial records would instead permit evasion. |
| + |
| + **Fix:** distinguish aggregate trend metrics from site-level prohibitions. Record grandfathered sites where “no new ones” is intended, and define reviewed identity transfers for moves, renames and package splits without increasing the inherited allowance. |
| + |
| +3. **P2 — Part 2: the database metric lacks a reliable measurement boundary.** |
| + **Invariant: the metric follows database operations, regardless of receiver spelling or package placement.** |
| + |
| + [Plan:117](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:117) names `db.Query`/`QueryRow`/`Exec`. Existing calls also use `tx` and a `sqlQueryer` interface: [billingpayments_store.go:72](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/billingpayments_store.go:72), [line 88](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/billingpayments_store.go:88), and [line 176](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/billingpayments_store.go:176). `Begin()` at line 170 is another context-free database operation. |
| + |
| + A receiver-name scan misses these; an unrestricted selector-name scan counts unrelated APIs. Limiting coverage to `internal/console` also makes the proposed `consoledb` extraction appear to fix calls merely by moving them. |
| + |
| + **Fix:** define the database types/interfaces and operations covered, including transaction acquisition. Use type information or a documented conservative syntax rule with fixtures covering these existing forms. Carry coverage into extracted packages. Specify import-alias handling, build-tag coverage and generated/fixture exclusions for the scanner generally. |
| + |
| +4. **P2 — Batch ordering: request cancellation is unnecessarily behind structural work.** |
| + **Invariant: operational fixes should not wait for unrelated dependency cleanup.** |
| + |
| + [Plan:75–87](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:75) puts console request contexts after the census extension and two package extractions. The current connection limit is indeed one ([store.go:122](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/store.go:122)); request handlers call store methods without passing their request context ([oppeople.go:102](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/oppeople.go:102), [line 127](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/oppeople.go:127)). Those paths can be improved in place. |
| + |
| + Batch 3 also contains existing unbounded production calls—[upstreamdial.go:16](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/edge/upstreamdial.go:16), [systemunits.go:327](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/host/systemunits.go:327), and [unitsettle.go:75](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/host/unitsettle.go:75)—while batch 2 includes test-speed cleanup. |
| + |
| + **Fix:** bring a bounded request-cancellation slice forward, and prioritize the remaining production deadline gaps ahead of sleep cleanup. Make `moved` a dependency of relocations that require it, not of every structural or cancellation change. |
| + |
| +5. **P2 — Batch 2: the edge sleep branch is incorrectly labelled census-free.** |
| + **Invariant: production test seams retain the normal census review.** |
| + |
| + [Plan:50](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:50) proposes a seam for `holderHeaderSuspectAfter` but labels the branch “no (tests).” The constant and timer construction are production code at [forwardha.go:509–521](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/edge/forwardha.go:509). Changing them changes the production envelope; the scanner fingerprints whole in-scope files ([census_scope_test.go:182](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/provision/census_scope_test.go:182)). |
| + |
| + **Fix:** mark the branch census-required if it adds that seam, with the normal independent approval. Retain “no” only for a strictly test-file-only implementation. |
| + |
| +6. **P2 — Part 2: physical-line ratchets reward deleting useful explanation.** |
| + **Invariant: readability and safety documentation must not be sacrificed to satisfy a size metric.** |
| + |
| + [Plan:118–119](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:118) allows oversized functions/files only to shrink, and [line 145](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:145) requires splitting a growing one. Adding a safety explanation to an unchanged oversized function would fail, while deleting comments would count as improvement. This codebase puts meaningful authority explanations immediately beside implementation, for example [apiinstances.go:1573](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/apiinstances.go:1573). |
| + |
| + **Fix:** exclude blank and comment-only lines from the blocking metric. Keep physical length as a report, and require meaningful decomposition rather than accepting comment removal as structural improvement. |
| + |
| +7. **P2 — Introduction and metric table: some quantitative claims are inaccurate or lack a counting definition.** |
| + **Invariant: baseline comparisons use the same reproducible measurement.** |
| + |
| + [Plan:16–18](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:16) says all three longest functions grew by 100–200 lines. Comparing function-body spans at the two named commits gives: |
| + |
| + | Function | `5b6d5374` | `c4b44c34` | Growth | |
| + |---|---:|---:|---:| |
| + | `Reconcile` | 1,255 | 1,275 | 20 | |
| + | `handleAPIInstanceCreate` | 1,081 | 1,242 | 161 | |
| + | `runAgent` | 1,090 | 1,222 | 132 | |
| + |
| + Current declarations are at [reconcile.go:1460](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/provision/reconcile.go:1460), [apiinstances.go:1578](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/apiinstances.go:1578), and [agent.go:275](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/host/agent.go:275). |
| + |
| + The stated 999 fatalities and 1,019 sleeps reproduce literal text-occurrence counts, which include non-call text; [cli.go:49](/home/paulca/amadan.net/carlos/platform-code-health-plan/cli.go:49) is one such comment. |
| + |
| + **Fix:** correct the growth claim and label historical text counts as estimates. Generate the authoritative baseline with the final scanner and record its scope and counting definitions. |
| + |
| +8. **P3 — Monthly pass: “read-only” conflicts with lowering records.** |
| + |
| + [Plan:152–157](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:152) promises a read-only session, then directs it to lower records. Under a functioning exact-match ratchet, an unlocked decrease on main is also a gate failure to investigate. |
| + |
| + **Fix:** make the pass report discrepancies and propose a separate reviewed repair branch. Treat unexplained drift as a failed invariant. |
| + |
| +The test-only `internal/codehealth` package is outside the census as proposed: scope derives from production dependency files, not test imports ([census_scope_test.go:43–79](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/provision/census_scope_test.go:43)). A single parsing pass is a reasonable approach, but gate runtime remains unmeasured. |
| + |
| +The monthly and quarterly cadence does not itself contradict the stopping rules; the plan explicitly retains them. Keep each audit and verification bounded, reuse existing caches, and measure scanner cost before claiming the hour budget. A `moved` design must preserve dispositions, reviewer approval and J4 witness obligations; current removal handling is not a safe substitute for that contract. |
| + |
| +NOT READY |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/FINDINGS-code-health-plan-R2.md b/docs/superpowers/reviews/FINDINGS-code-health-plan-R2.md| new file mode 100644 |
| index 000000000..11dbcb264 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-code-health-plan-R2.md |
| @@ -0,0 +1,63 @@ |
| +- R1 P1, ratchet merges and regeneration: **resolved** for the reported cases; decreases no longer fail, updates only lower, and increases require an explicit reason. |
| +- R1 P2, aggregate counts versus new offences: **resolved** through site records and reviewed allowance transfers. |
| +- R1 P2, database measurement boundary: **partly resolved**; type-based coverage still excludes existing database forms. |
| +- R1 P2, batch ordering: **resolved**; request cancellation and remaining production deadlines precede structural work. |
| +- R1 P2, edge seam census classification: **resolved**. |
| +- R1 P2, comment deletion incentive: **resolved**. |
| +- R1 P2, growth figures and counting definitions: **resolved** for the reported discrepancies. |
| + |
| +Reviewed `732d32ba2214bab824fa6791f0a09b5238e5f465` against `c4b44c34`. The production source is unchanged between those commits. No files changed; no builds, tests, or subagents ran. Network restrictions prevented access to discussion #1123, so its reports and issue claims remain unverified. |
| + |
| +No P1 findings. |
| + |
| +1. **P2 — Part 2: the database metric still misses existing database operations.** Carried from R1. |
| + |
| + **Invariant:** database operations remain measurable regardless of receiver spelling, interface narrowing, or package placement. |
| + |
| + The definition at [plan:173](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:173) includes module interfaces only when they offer the corresponding `...Context` method. Its named example, `sqlQueryer`, declares **only** `QueryRow` at [billingpayments_store.go:73](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/billingpayments_store.go:73). Consequently, the proposed rule misses the existing `q.QueryRow` calls, including line 88. |
| + |
| + Transaction acquisition has a related gap. `Store.db` is a `sqlHandle`, whose contextual transaction method is `BeginTx`, not `BeginContext` ([store_gate.go:110](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/store_gate.go:110)). The literal counterpart rule therefore misses `s.db.Begin()`. Prepared statements are also omitted: the receiver at [registry.go:2874](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/registry/registry.go:2874) is `*sql.Stmt`, which is neither among the listed SQL types nor a type defined in this module. |
| + |
| + **Fix:** define one database-operation classifier covering SQL method signatures, narrow interfaces, `*sql.Stmt`, and the explicit `Begin`→`BeginTx` mapping. Require fixtures for these existing examples and equivalent calls after package extraction. |
| + |
| + This is the second round in the same measurement-boundary fault family. Under [AGENTS.md:54](/home/paulca/amadan.net/carlos/platform-code-health-plan/AGENTS.md:54), do not continue with successive receiver-list patches. Recommend the rule’s centralized-invariant option; the alternatives are to reject unsupported forms explicitly or defer this metric. |
| + |
| +2. **P2 — Batch 4: extracting shared console dependencies is incorrectly classified as outside the census.** |
| + |
| + **Invariant:** census scope follows changed production source, regardless of which consumer motivates the change. |
| + |
| + [Plan:101](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:101) exempts items 3–5 as console work. Item 3, however, extracts definitions from activator and edge into a shared leaf package. |
| + |
| + These are not exclusively console definitions. The console calls `edge.FleetArmVerdict` at [apiinstances.go:449](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/console/apiinstances.go:449); its implementation at [fleetforward.go:322](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/edge/fleetforward.go:322) contains routing eligibility decisions. The root command package imports edge at [commands.go:16](/home/paulca/amadan.net/carlos/platform-code-health-plan/commands.go:16). Likewise, the console’s activator helpers come from root-linked production files. |
| + |
| + Extracting those definitions changes census-covered source and potentially adds a root-linked package. Whole-file coverage is explicit at [census_scope_test.go:125](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/provision/census_scope_test.go:125). |
| + |
| + **Fix:** classify item 3 as census-touching. Its short spec should determine whether the proposed `moved` class applies or ordinary unit and envelope proposals are required. Keep the console-only context and store work independent of that dependency. |
| + |
| +3. **P2 — Part 2: the scanner’s build configuration omits ordinary production source.** |
| + |
| + **Invariant:** a production file must not escape the ratchet because a test configuration substitutes another file. |
| + |
| + [Plan:157](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:157) specifies loading with `rootrunner,carlos_cutover_witness`. But [departure_queue_default.go:1](/home/paulca/amadan.net/carlos/platform-code-health-plan/internal/host/departure_queue_default.go:1) uses `!rootrunner`; the tagged implementation replaces it. |
| + |
| + A scanner using only the specified configuration never sees that production file. New host `context.Background()` calls there, for example, would evade the advertised host metric. |
| + |
| + **Fix:** measure the union of ordinary production and tagged configurations, deduplicating shared source sites. Add a fixture proving that an offence in a `!rootrunner` file is counted. State explicitly whether other supported operating systems are covered or remain outside the initial ratchet. |
| + |
| +4. **P3 — Part 2: transfer and exception wording needs one consistent contract.** |
| + |
| + [Plan:135](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:135) permits `MOVE` to create a destination identity, while lines 147–153 say the command cannot add sites and CI requires a `# raised:` annotation for every addition. The completion criterion at [plan:258](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:258) also says records are “never raised,” despite the explicit exception mechanism. |
| + |
| + **Fix:** document how CI recognizes a valid transfer and distinguish transferred allowances from approved increases. Align the completion criterion with that policy. |
| + |
| +5. **P3 — Batch 3 and Batch 4: remove duplicated tasks and label the historical size estimate.** |
| + |
| + The prober and host deadline tasks appear twice at [plan:72](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:72) and line 80. The “78k lines” statement at [plan:107](/home/paulca/amadan.net/carlos/platform-code-health-plan/docs/superpowers/plans/2026-11-16-go-code-health.md:107) matches the older audit baseline: direct-package, non-test Go files total 77,538 lines at `5b6d5374`, versus 89,626 at `c4b44c34`. |
| + |
| + **Fix:** keep each deadline task once and label the size estimate with its baseline or update it. |
| + |
| +The test-only scanner remains outside the census as proposed. The corrected fatal-call, sleep, and function-growth figures reproduce against the named commits. The monthly reporting branch resolves R1’s P3. The monthly and quarterly cadence is bounded on paper; scanner runtime and shared-machine resource use remain unmeasured, so retain the first-run measurement requirement. |
| + |
| +This round has no P1, so the stopping rule ends review here. Address the P2s without reopening review, subject to the repeated-family decision above; retain P3s as follow-ups. |
| + |
| +READY AFTER FIXES |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan-R2.md b/docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan-R2.md| new file mode 100644 |
| index 000000000..2dbd5490d |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan-R2.md |
| @@ -0,0 +1,71 @@ |
| +# Review brief: plan docs/superpowers/plans/2026-11-16-go-code-health.md, round 2 of 3 |
| + |
| +Repo carlos/platform, branch `code-health-plan` (tip named in the reviewer's prompt). |
| +Under review: `docs/superpowers/plans/2026-11-16-go-code-health.md`. |
| +Authorities: AGENTS.md on main ("Stopping rules", "The census", "Build & |
| +test"). Context: amadan discussion #1123 (audit backlog, reports, and the |
| +recheck table against c4b44c34). |
| + |
| +You are an independent reviewer. This is a plan for keeping the Go code |
| +healthy over time, not a feature. Check it against the code and the repo's |
| +rules. |
| + |
| +## What to check |
| + |
| +1. The code-health ratchet (Part 2): is the design sound? A test-only |
| + package `internal/codehealth` parsing the tree with go/parser and |
| + comparing against `.amadan/code-health.tsv`; failing on increase and |
| + also on decrease (forcing the record down in the same branch). Will it |
| + be stable across parallel branches (merge conflicts in the record), fast |
| + enough for the gate, and outside the census as claimed? Are the chosen |
| + metrics measurable reliably, and do they track something that matters? |
| + Is any metric gameable in a way that makes code worse? |
| +2. Batch ordering: is anything in batch 3 or 4 more urgent than batch 2? |
| + Does the census `moved` class really need to come first for the |
| + structural work? |
| +3. The AGENTS.md rules: each enforceable as stated, and none contradicting |
| + existing AGENTS.md rules or the stopping rules? |
| +4. The monthly pass and quarterly audit: realistic in cost, and do they |
| + respect the stopping rules (no review spirals) and the shared-machine |
| + CPU budget? |
| +5. Anything missing that a strong Go team would hold the line on (for this |
| + codebase specifically), with evidence. |
| +6. Factual claims (counts, commits, file:line) against main at c4b44c34. |
| + |
| +## Round 2 |
| + |
| +Earlier rounds: round 1, Astra, `docs/superpowers/reviews/FINDINGS-code-health-plan-R1.md` |
| +(NOT READY: one P1, six P2s, one P3). The plan is now rev 2. |
| + |
| +First give one line per P1 and P2 from round 1: 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. |
| + |
| +Rev 2 answers: the ratchet no longer fails on a decrease (so parallel |
| +decreases merge cleanly), the record command only lowers, a separate CI |
| +step refuses raised numbers or added sites against the merge base unless |
| +the line carries a `# raised:` reason; "no new ones" rules are site |
| +records (package, enclosing function, callee) with explicit MOVE transfers |
| +that cannot increase an allowance; the database metric is type-based and |
| +covers DB/Tx/Conn and interfaces with Context forms, in every package; |
| +line metrics count code lines only; batch 3 now leads with console request |
| +cancellation in place and the remaining production deadline gaps; `moved` |
| +is a dependency only of root-graph relocations; the edge sleep branch is |
| +marked census-touching; the growth figures are corrected and labelled as |
| +grep estimates; the monthly pass reports and lowers records only through |
| +a reviewed branch. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not work, or contradicts a repo rule. Blocks. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Follow-up list only. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3, each with the section, the problem, evidence |
| +(file:line, verified), and a concrete fix. End with exactly one verdict: |
| +READY, READY AFTER FIXES, or NOT READY. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run builds or tests. |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan.md b/docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan.md| new file mode 100644 |
| index 000000000..3398eba48 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-code-health-plan.md |
| @@ -0,0 +1,48 @@ |
| +# Review brief: plan docs/superpowers/plans/2026-11-16-go-code-health.md, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `code-health-plan`, commit b2bf354b52353c4621208fe43a4cc4f4916197bf. |
| +Under review: `docs/superpowers/plans/2026-11-16-go-code-health.md`. |
| +Authorities: AGENTS.md on main ("Stopping rules", "The census", "Build & |
| +test"). Context: amadan discussion #1123 (audit backlog, reports, and the |
| +recheck table against c4b44c34). |
| + |
| +You are an independent reviewer. This is a plan for keeping the Go code |
| +healthy over time, not a feature. Check it against the code and the repo's |
| +rules. |
| + |
| +## What to check |
| + |
| +1. The code-health ratchet (Part 2): is the design sound? A test-only |
| + package `internal/codehealth` parsing the tree with go/parser and |
| + comparing against `.amadan/code-health.tsv`; failing on increase and |
| + also on decrease (forcing the record down in the same branch). Will it |
| + be stable across parallel branches (merge conflicts in the record), fast |
| + enough for the gate, and outside the census as claimed? Are the chosen |
| + metrics measurable reliably, and do they track something that matters? |
| + Is any metric gameable in a way that makes code worse? |
| +2. Batch ordering: is anything in batch 3 or 4 more urgent than batch 2? |
| + Does the census `moved` class really need to come first for the |
| + structural work? |
| +3. The AGENTS.md rules: each enforceable as stated, and none contradicting |
| + existing AGENTS.md rules or the stopping rules? |
| +4. The monthly pass and quarterly audit: realistic in cost, and do they |
| + respect the stopping rules (no review spirals) and the shared-machine |
| + CPU budget? |
| +5. Anything missing that a strong Go team would hold the line on (for this |
| + codebase specifically), with evidence. |
| +6. Factual claims (counts, commits, file:line) against main at c4b44c34. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not work, or contradicts a repo rule. Blocks. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Follow-up list only. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3, each with the section, the problem, evidence |
| +(file:line, verified), and a concrete fix. End with exactly one verdict: |
| +READY, READY AFTER FIXES, or NOT READY. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run builds or tests. |