The Drift Log · Audit, then actually repair
Why Rewrites Win Over Audits and How to Change the Math
27 October 2026 · 4 min read · 832 words · inference

Standard audits catalogue structural decay without offering an extraction path. Auditing for capability makes incremental refactoring viable.
The pitch for a complete rewrite is always clean: a modern runtime, typed boundaries, fast CI, and zero baggage. The pitch for working on legacy code is a spreadsheet containing twelve hundred static analysis warnings and an unprioritised list of security advisories.
Leadership signs off on the rewrite not because they believe greenfield work will stay on schedule, but because the alternative looks unexecutable. A standard repository audit describes decay without providing an extraction path. When the only artifact of an audit is a scorecard of failure, starting over feels like the only rational engineering choice.
To change the balance between refactoring and rewriting, you have to change what an audit produces.
The Flaw in Diagnostic Audits
Most code health assessments scan for structural defects: cyclomatic complexity, dead code, dependency drift, and lint deviations. The output is a backlog of friction points.
Issues Found:
- [High] 142 circular imports detected in /services/billing
- [Medium] Database connection pool configured with deprecated options
- [Low] 1,840 style violations across 82 files
This list tells an engineering team where code is ugly, but it says nothing about what the code actually accomplishes. It treats high-value domain logic—like payment reconciliation edge cases discovered over four years of production failures—the same as an unformatted switch statement.
When presented with ten thousand lines of tightly coupled domain logic, an engineer cannot tell where the business invariant ends and the architectural mistake begins. Remediating circular dependencies in place risks breaking silent production invariants. Rewriting the entire service feels safer because the team assumes they can re-implement the feature set from first principles without inheriting the structural rot.
They usually discover those silent invariants months later, in production, on the new system.
Inverting the Balance: Auditing for Capability
A rewrite throws away discovered domain edge cases to escape bad code layout. A surgical repair preserves those edge cases while isolating the layout.
For targeted repair to beat a ground-up rewrite, a repository audit must catalogue functional capability rather than structural complaints. Instead of asking "what is broken in this module?", the evaluation asks:
- What discrete inputs and outputs cross this directory boundary?
- What part of this subsystem runs independently of framework scaffolding?
- Which routines represent pure domain transformations that can be extracted into tested, self-contained units?
When you isolate a subsystem by its contract rather than its defects, you stop treating legacy code as an indivisible monolith. You treat it as an unindexed library of working functions wrapped in legacy plumbing.
Once a capability is bounded, the repair is local. You do not refactor the entire billing service; you extract the tax calculation engine into an isolated artifact, pin its behaviour with an execution harness, and leave the calling surface intact. We covered how this pipeline moves from diagnostic data directly to pull requests in closing the loop from repository audit to merged repair.
The Accounting of Incremental Repair
Consider the mechanics behind both approaches:
| Dimension | Greenfield Rewrite | Capability Extraction | | :--- | :--- | :--- | | Discovery Scope | Broad requirements gathering across the full domain | Contract mapping at discrete directory boundaries | | Unit of Work | Full re-implementation of the complete subsystem | Single bounded routine isolated and pinned under test | | Defect Surface | High (re-discovering unwritten production edge cases) | Low (existing, production-exercised logic preserved) | | Rollout Risk | Binary (all-or-nothing cutover) | Incremental (merged per verified component) |
A rewrite concentrates all risk at the point of cutover. If the new system fails to handle a legacy payment gateway quirk on day 180, the rollout stalls entirely.
Incremental capability extraction distributes risk across isolated changes. If a repair to a single parser fails its runtime validation, only that extraction is reverted. The rest of the application keeps running.
By turning an audit into an actionable inventory of functional boundaries, you eliminate the cognitive load that makes teams reach for a rewrite in the first place. You do not have to understand all 50,000 lines at once; you only need to prove that a 200-line calculation preserves its contract under test.
What to Do on Monday
Stop generating sitewide lint and debt reports that nobody acts on.
- Pick one contentious module. Choose a directory that teams frequently propose rewriting because "it is too fragile to touch."
- Trace the contract, not the AST. Identify the primary entry points. Write down the shape of their inputs, their outputs, and their side effects.
- Isolate the pure computation. Carve out the logic that computes values without touching I/O. Move it to a separate, standalone file.
- Pin it with a harness. Write a focused test suite against that extracted unit using historical payloads before changing a single line of implementation.
If you want an objective view of how many isolated, reusable components are currently trapped in your codebase, run a free repository evaluation. The goal of an audit is never to prove your code is difficult—you already know it is. The goal is to extract what works so you never have to rewrite it from scratch.
Keep reading
Next in the log
- Dashboard for Measuring Audit‑to‑Repair Cycle Time
Track audit‑to‑repair time by pairing immutable detection timestamps with merge dates and visualizing the lag on a simple dashboard.
- Debt Scorecards: Prioritizing Refactors from Audit Data
Turn audit JSON into a numeric debt scorecard that prioritizes refactor work and ties directly into the certification harness.
- Turning Inconclusive Harness Results into Targeted Test Suites
Turn an INCONCLUSIVE harness verdict into a focused test that unlocks the repair pipeline.
The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.