Skip to content

maintainability audit: 103 duplicated blocks, 267 functions with 6+ params, and a 16.9k-line file #10170

Description

@JSONbored

Umbrella for the maintainability audit. Motivation: "our app is extremely heavy and has a lot of pitfalls, making it very hard to maintain." This is the measured version of that, with the specific instances split into their own issues.

Measurements

metric value
source LOC (src/** + packages/*/src/**) 227,477
test LOC 461,366 (2.0×)
src/queue/processors.ts 16,913 lines — 7.4% of all source in one file
src/db/repositories.ts 9,052
src/api/routes.ts 6,382
functions with ≥6 positional parameters 267
worst offender persistDecisionRecord13 positional parameters
cross-file duplicated blocks (≥8 non-comment lines) 103

Why this is not abstract — four incidents in one session traced to it

  1. P1: manual-review label flaps every pass — a plan can contain both an add and a remove of it #10164 (P1, label flap in production). The same 8-line manual-review-hold block existed in three transforms. The third (calibration: randomized ε-holdout on would-close PRs with propensity logging #8831, added later) diverged from the other two, and nobody could see it because there was no single definition to compare against. Cost: a label cycling every 90 seconds on live PRs.

  2. perf(webhook): four of five coalesce families are keyed but windowless, so they never coalesce #10127 (webhook coalescing inert). Key and window were computed by two separate functions. Four of five families had a key and no window, so they could never coalesce — 1,727 check_suite.completed deliveries in 1.5 days and 2.9 gate passes per head SHA. Fixed by making one function return both, so the state is unrepresentable.

  3. cost: estimateNeurons is duplicated 4x and the copies drop the calls multiplier, under-reporting AI spend #10169 (AI spend under-reported). estimateNeurons exists four times; the canonical one is exported and takes a calls multiplier, the three private copies do not. A retrying service reports half its real spend into the budget backstop.

  4. gate: let maintainers be exempt from the missing-linked-issue penalty without weakening it for contributors #10158 (config knob). Adding one gate knob required edits in seven places. Four separate exhaustiveness guards caught it half-registered — and two of those failures were silent in production (parses but warns "unknown key"; drops on serialization round-trip). The guards are excellent; needing seven edits is the problem.

The common shape: two or more places that must agree, with nothing enforcing it. Every one of the above was invisible until it caused a production symptom.

Concrete, bounded wins

processors.ts

16,913 lines is the single largest structural cost. Today it meant hunting four gateCheckPolicy call sites across the file and finding that author context was in scope at only one of them — the direct cause of #10158 needing a shared resolver. It also holds 3 of the 5 repo-set duplicates.

Not proposing a big-bang split. The tractable version is extracting cohesive, already-duplicated units (the repo-set resolver above is a clean first one) and letting the file shrink as a side effect of removing duplication, rather than as a refactor for its own sake.

Deliberately NOT flagged

The 2:1 test-to-source ratio is not bloat — the exhaustiveness guards and invariant tests in this repo caught real, silent bugs repeatedly today. Several of the 103 duplicate blocks are type declarations or coincidental structure; the ones listed above were each read and confirmed as genuine copy-paste.

Metadata

Metadata

Assignees

Labels

maintainer-onlyOwner-only work — yields no Gittensor points.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions