plan: code health rev 3, round 2 fixes (review closed)
Astra round 2: READY AFTER FIXES. One database classifier by signature (the repeated measurement family, enforced in one place); the console leaf extraction marked census-touching; the scanner measures untagged and tagged builds; transfers checked mechanically; duplicates removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+105
−16
docs/superpowers/plans/2026-11-16-go-code-health.md+42 −16docs/superpowers/reviews/FINDINGS-code-health-plan-R2.md+63 −0
CI failed — 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| index 6a1a6028b..c8b4e9b55 100644 |
| --- a/docs/superpowers/plans/2026-11-16-go-code-health.md |
| +++ b/docs/superpowers/plans/2026-11-16-go-code-health.md |
| @@ -1,6 +1,6 @@ |
| # Go code health: fix, hold, improve |
| -Status: draft rev 2 for Paul, 2026-11-16 (Astra round 1 answered). Backlog and audit reports: amadan |
| +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). |
| @@ -77,11 +77,6 @@ In this order: |
| - #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. |
| -- The edge prober's unbounded dial (`internal/edge/upstreamdial.go` |
| - comment). |
| -- Host loops that wait on `systemctl`/`journalctl` with no timeout |
| - (adoptLoop, fastConvergeLoop, statusLoop, configSync/configGen): one |
| - bounded `systemctl` helper, used everywhere. |
| - 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). |
| @@ -98,13 +93,18 @@ In this order, because each makes the next cheaper: |
| 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, and any host split); console work (3 to 5) is outside the root |
| - census and does not wait for it. |
| + (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 78k lines it barely uses. |
| + 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 |
| @@ -134,7 +134,11 @@ began, records only go down), adapted for many parallel branches. |
| 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; the reviewer sees the transfer in the diff. |
| + 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. |
| @@ -149,15 +153,21 @@ began, records only go down), adapted for many parallel branches. |
| 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 without that comment, so a raise is always |
| - a visible, reviewed decision. |
| + 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` with the gate's tags (`rootrunner`, |
| -`carlos_cutover_witness`). Generated files (`// Code generated`) and |
| +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 |
| @@ -170,12 +180,27 @@ grep estimates from c4b44c34. |
| |---|---|---| |
| | `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: methods `Query`, `QueryRow`, `Exec`, `Prepare`, `Begin` on `*sql.DB`, `*sql.Tx`, `*sql.Conn`, and any interface or type in the module that offers the `...Context` form of the same method (e.g. console's `sqlQueryer`), 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` and interfaces | |
| +| 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. |
| @@ -255,7 +280,8 @@ inside activator, mass-unexporting in host. |
| - Batches 2 and 3 merged; staticcheck runs every SA check; govulncheck, |
| gitleaks and a targeted `-race` run in CI. |
| -- The ratchet in CI, its records never raised. |
| +- 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-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 |