ADR-030: Code-Quality Gating — Enforced Lint Posture and Debt Ratchet
Relates to
ADR-013 — this ADR applies the same enforce-don’t-assert, deny-by-default philosophy ADR-013 brought to plan lifecycle to code quality. It ports the gating model proven in the sibling CCWIS project (craig), whose exact lint posture this matches or exceeds.
Context
A ten-agent code-quality review (five readers per repo, 2026-06-09) graded canopy and craig both at A− with the same engineering DNA, but found craig consistently ahead on the enforced-gating dimensions: a 40-line function ceiling, the whole panic class denied workspace-wide, every lint suppression carrying a reason, all backstopped by a debt ratchet that fails the build on regression.
The difference is mechanism, not discipline. Canopy’s quality is conventional — achieved by careful authors, review, per-crate #![forbid(unsafe_code)] (51 crates), and a CI cargo clippy --workspace --all-targets — -D warnings. That -D warnings hardens default-level clippy + rustc warnings to errors, but it does not enable the allow-by-default restriction lints that catch panics and overflow (unwrap_used, expect_used, panic, indexing_slicing, arithmetic_side_effects, …), nor the pedantic/nursery groups, nor a function-size ceiling. Canopy has no root [workspace.lints] table and no clippy.toml. So a regression — a new .unwrap() in a request path, a 600-line handler — passes the gate today.
Two forces make now the moment to fix this. First, canopy is ATO-bound (SNAP UAT, September 2026); for eligibility software carrying legal weight, enforced panic-free and injection-free is an audit asset, not a nicety. Second, canopy is about to write its largest body of new code in a single arc — epics &56 (worker fact-authoring) and &58 (provable policy completeness), on the order of 100k LOC. It is far cheaper to write to a gate than to retrofit one onto finished code, and the worst time to lack the gate is during the highest-volume coding period. The gate must precede that work so every new line is born clean.
Decision
-
Centralized strict lint posture via root
[workspace.lints]— at least as strict as craig. Every member crate carries[lints] workspace = true; strictness lives in one place (this also retires the 51 scattered![forbid(unsafe_code)]headers and avoids the per-crate-header smell). The denied set covers: the panic class (unwrap_used,expect_used,panic,todo,unimplemented,unreachable,unwrap_in_result,dbg_macro), index/slice panics (indexing_slicing,string_slice), overflow (arithmetic_side_effects— forcechecked_*/saturating_*/wrapping_*), IO surface (print_stdout,print_stderr— route throughtracing), thepedantic,cargo, andnurserygroups (atdeny, priority −1 so individual sub-lints can be allow-listed), complexity (cognitive_complexity,too_many_lines), and the hygiene lintswildcard_enum_match_arm,partial_pub_fields,allow_attributes_without_reason,let_underscore_must_use,ignored_unit_patterns; plus rust-levelunused_must_use = denyandunsafe_code = deny(deny, notforbid, so a SAFETY-commented[expect]can cover the legitimateenv::set_varsites in xtask under Rust 2024). The exact lint table — including the priority-1 escape-list and its required rationale comments — is the implementation artifact of the plan; the policy is this posture is the floor, and it may only ratchet stricter. Per the 2026-06-09 calibration sign-off canopy adopts the exceed-craig stance: the pedantic-noise sub-lints (module_name_repetitions,must_use_candidate,missing_errors_doc,missing_panics_doc) and the nursery escape-hatches that craig allow-lists for transition-noise are instead denied here. Only structural exceptions escape —cargo_common_metadata(an unpublished workspace would otherwise demand fake crate metadata) andmultiple_crate_versions(transitive-dep skew, tracked in the ratchet instead) — plus any individual lint that measurement shows has >10 genuinely-low-value emissions, allow-listed with a rationale comment per §4. -
clippy.tomlthresholds.too-many-lines-threshold = 40(match craig’s ceiling);allow-unwrap-in-tests = true+allow-expect-in-tests = true(so tests need no per-crate carve-out for those two). -
A monotonic
quality-budgetsdebt ratchet (port craig’sxtask quality-budgets). A catalogue of debt counters (oversized modules/functions, untypedserde_json::Value,#[allow]count,.unwrap_or_default(), duplicate dep versions, …) each with athresholdand a.lockfloor captured by--write-lock. The enforced ceiling is lock-authoritative:if locked > 0 { locked } else { threshold }.--fail-on-regressionfails the build if any counter’s live count exceeds its ceiling. The ratchet only descends:--write-lockre-snapshots current counts (lowering the floor after a cleanup), and any change to the lock — up or down — must be justified in the MR. This is what makes the burndown continuous and non-regressing rather than a deferred cleanup phase. -
A lint-promotion / triage pattern (ports craig’s ADR-031). When a new lint or group is promoted toward
deny: < 10 emissions and clear value → keep denied, sweep the fixes in the same MR; > 10 emissions and clear value → allow-list at priority 1 with a documented rationale and a filed successor-plan sweep; known-noisy / case-by-case → allow-list at priority 1. Every{ level = "allow", priority = 1 }entry MUST carry a comment recording (1) the surface measurement, (2) the rationale, (3) the successor-plan pointer. Group defaults (pedantic/cargo/nursery) staydenyso newly-stabilized lints surface for triage rather than being silently muted. Deferred sweeps go to named successor plans, never a vague follow-up. -
Grandfather at status quo. Turning the posture on annotates each existing violation with
[expect(clippy::…, reason = "…")](or fixes it inline where cheap), and seeds the ratchet at canopy’s current debt counts. The gate goes live without a big-bang refactor: existing debt is frozen (cannot grow), all new code meets the full standard, and the grandfathered[expect]s + ratchet floors are burned down monotonically — partly as a side effect of touching files during feature work, partly via dedicated burndown MRs. -
Production strictness is absolute; test code carves out narrowly. Tests legitimately use
.unwrap()/.expect()/indexing/panic!as assertion scaffolding.unwrap/expectare covered by theclippy.tomlin-test toggles; the remaining panic/index/print/overflow lints need a#[cfg(test)]-scoped allow (clippy[workspace.lints]cannot expresscfg(test)). Canopy centralizes this carve-out as far as the tooling allows to avoid craig’s ~31×-repeated crate-root header. -
Wiring — the gate is the pre-push
cargo xtask validatebattery, with CI parity.validateruns (in order)fmt --check,cargo machete(unused deps),clippy --workspace --all-targets --locked — -D warnings(which now also enforces the[workspace.lints]denies), thequality-budgets --fail-on-regressionstep (blocking),build, andnextest. CI runs the same battery via--skip-devstack --skip-dockeras the single source of truth; the pre-push hook’s executable bit is guarded so a silently-neutered gate is caught.
Consequences
-
New code is born clean and regression-proof. The ~100k LOC of &56/&58 is written to the gate from the first line; the build refuses to accrete a new panic, oversized function, or un-reasoned allow.
-
One source of truth. The
[workspace.lints]table replaces 51 per-crateforbidheaders; no crate can silently relax the posture. -
An ATO asset. "Production code is enforced panic-free, overflow-checked, and injection-safe" becomes a property the build proves on every push, not a claim.
-
A genuinely-needed exception is reasoned and reviewable —
[expect(…, reason = "…")]/ priority-1 allow-with-comment — never a silent[allow]. -
Lowering the ratchet is an explicit, justified act (
--write-lock+ MR rationale); the floor cannot drift up. -
Strictness is one-directional. This ADR is the decision-of-record; the code-quality-gating plan sequences the rollout. The posture may only ratchet stricter; relaxing any
denyis an ADR-amending decision, not a config edit. -
Cost paid up front: standing up the regime requires a grandfather sweep (annotate/fix existing violations) and porting the ratchet tooling before the feature work begins — a bounded, mechanical cost that the plan front-loads as its first slice.
Amendment 1 (2026-09-17) — as built
Status unchanged (still Accepted). The posture is built as decided — the root [workspace.lints] table in Cargo.toml, clippy.toml (too-many-lines-threshold = 40, the in-test unwrap/expect toggles), cargo xtask quality-budgets with --write-lock and the committed xtask/quality-budgets.lock. Three details of §1 and §7 read differently in the tree. In-document amendment, not an edit to the Decision.
-
§7 wiring.
cargo xtask validatetakes--skip-dockerand--timingonly (Argsinxtask/src/cmd/validate.rs); there is no--skip-devstack. The pre-push hook runscargo xtask validate --skip-docker(.githooks/pre-push). CI does not invoke the battery:.gitlab-ci.ymlmirrors its static gates as individual jobs (quality-budgets,adr-013-plan-lint,typed-id-path-audit,ci-config-lint, …; the job comments name the validate sub-step mirrored) and runs the whole suite only as the manual DinD jobvalidate-in-network(cargo xtask validate-in-network --with-devstack). The stage order §7 enumerates is the 2026-06 inventory; the live inventory isrun_innerinvalidate.rs, and the invariant is that clippy under the workspace lints andquality-budgetsare blocking gates in it. -
§1’s "exceed-craig" deny is the target, not the M1 state. Three of the four pedantic-noise lints §1 says are denied —
missing_errors_doc,missing_panics_doc,must_use_candidate— sit on the priority-1 transition allow-list in[workspace.lints.clippy](comment "M1 grandfather — NOT steady-state policy", counts captured 2026-06-09) under §4’s >10-emissions clause, to burn down under the plan's Phase B;module_name_repetitionsis not allow-listed and is denied through thepedanticgroup. -
54 headers, not 51. The M1 sweep centralized 54 per-crate
#![forbid(unsafe_code)]headers into[workspace.lints.rust](unsafe_code = "deny", per the comment inCargo.toml); 51 was the survey count in the Context.
Amendment 2 (2026-09-24) — as built
Status unchanged (still Accepted). clippy.toml also carries allow-panic-in-tests = true (2284): §6’s test carve-out for panic, centralized through the tooling as §6 intends. Like the unwrap/expect toggles, the key reaches [test] fns and items with a [cfg(test)] ancestor; it retired 77 per-site [expect(clippy::panic)]. Production panic stays denied. The key relaxes a deny in test code, and the Consequences make relaxing a deny an ADR-amending decision, hence this amendment. clippy.toml is a template-synced file, so the key is held as the cfg-clippy entry in .claude/sync-overrides.toml until claude-quickstart carries it. In-document amendment, not an edit to the Decision.
-
No lib-root
cfg_attr. §6’s other route, a lib-root#![cfg_attr(test, allow(…))], is not used:cargo xtask validatelints with--profile test, which compiles every target withcfg(test), so such a block would silence production panics as well. -
What stays enforced in tests.
unwrap_in_result,unreachable,todoandunimplementedhave no in-tests key, and clippy’sallow-dbg-in-testsis not set. Integration-test crates keep their crate-root M2![allow]header, because their free helper fns have no[test]/#[cfg(test)]ancestor for the toggles to key on.
Erratum (2026-10-25, as-built): the template sync retired with #2990. clippy.toml is canopy-owned and carries allow-panic-in-tests = true itself; the cfg-clippy entry and .claude/sync-overrides.toml are gone.
Erratum (2026-11-28, as-built): §3’s ceiling is locked.unwrap_or(threshold), not if locked > 0 { locked } else { threshold } (#3577). The lock is the ceiling whenever xtask/quality-budgets.lock names the budget, a lock of 0 included; the threshold is the ceiling only of a budget the file does not name yet. Read with locked > 0, a lock of 0 fell back to the threshold, so a budget bought down to zero stopped ratcheting: B2, whose threshold is the 100-line limit, would have allowed 100 over-long functions at a lock of 0.