Refactoring closeout and maintenance rules
The R0-R31 structural-debt program is complete. Implementation history and the reasons for retained exceptions are in the refactoring inventory; user-visible changes belong in the changelog.
Current guardrails
scripts/checks/check_refactor_budget.pyscans handwritten production Rust code.validation/refactor_budget_v1.jsonis a ratchet: existing allowances may shrink but may not grow.- New production files are limited to 1,500 lines. New functions are limited to 120 lines and 25 lexical decision points.
- Generated and declarative tables require narrow, documented exclusions.
- Public Rust paths, struct-literal compatibility, typed errors, Python names, TypeScript names, and JSON shapes stay stable during structural work.
The scanner is not a correctness oracle. Chemistry regressions, cross-binding contracts, output digests, and paired performance gates remain authoritative.
Completed program
| Phases | Scope | Result |
|---|---|---|
| R0-R8 | Scanner, baseline, core chemistry, formats, bindings, 3D, dead code | Complete |
| R9-R16 | Test extraction, boundary cleanup, hot spots, CI, first closeout | Complete |
| R17 | Format-I/O pull-request convergence and baseline freeze | Complete |
| R18-R20 | Checked conversion, standardization, depiction, and layout | Complete |
| R21-R23 | Search/reaction internals, compatibility ports, bindings, and MCP | Complete |
| R24 | Shared validation and CI harnesses | Complete |
| R25 | Final orchestration splits and release-grade verification | Complete |
| R26 | Low-risk test extraction and bounded parser/CIP ownership | Complete |
| R27 | Structural-alert catalog and test ownership | Complete |
| R28 | InChI dedup and indexed-graph ownership | Complete |
| R29 | RDKit depiction geometry and fragment ownership | Complete |
| R30 | Avalon fingerprint orchestration ownership | Complete |
| R31 | Final function-debt audit and closeout | Complete |
R17-R31 reduced the checked debt baseline from 14 file and 76 function allowances to 0 file and 47 function allowances. The program separated:
- standardization stages, reaction projection, SMARTS/VF2/MCS ownership, and CIP/canonical/ring orchestration;
- CJSON/MOL2 conversion policy from loss reporting;
- layout, depiction preflight, PNG/EPS rendering, and periodic-neighbor work;
- MMFF, InChI, PDB, valence, ring-stereo, and RDKit-compatibility branches;
- CLI, Python, WASM, MCP transport/schema, and validation-script boundaries.
R26 moved PDB, POSCAR, reaction-SMARTS, SMARTS-parity and SMILES-writer tests out of production modules, isolated the reaction-SMARTS parser, and gave E/Z completeness its own CIP module. This closed the PDB, POSCAR, reaction-SMARTS and CIP file allowances without changing public paths or chemistry behavior.
R27 moved the immutable PAINS and Brenk SMARTS catalogs and their tests out of
the alert runtime module. Pattern text and order, cache construction, matching
budgets, public APIs, and fail-safe behavior are unchanged. This closes the
alerts.rs file allowance without treating ordered chemistry data as runtime
logic.
R28 moved typed indexed-graph relation comparison and the dedup test suite out
of the InChI candidate-grouping module. Existing public names are re-exported
from the same dedup path; graph strictness, atom-map policy, diagnostic
ordering, native-InChI evidence and feature-gated behavior are unchanged. This
closes the dedup.rs file allowance.
R29 moved RDKit-compatible 2D geometry primitives and embedded-fragment state
into physical include files under the existing depiction module. This keeps
floating-point operation order, private visibility, and the public facade
unchanged while closing the depict.rs file allowance.
R30 moved Avalon's operation-order-sensitive pattern-counting function into a bounded physical include file. Hash insertion order, wrapping arithmetic, branch order, public flags and fingerprint output remain unchanged. This closes the final production-file allowance.
R31 extracted three bounded decisions from Avalon path emission, Avalon ring aromaticity and RDKit-compatible collision repair. The original traversal, mutation and floating-point order are retained, while all three orchestration functions now satisfy the normal function budget. The remaining 47 entries were re-reviewed and retained because they are ordered chemistry ports, bounded searches, format state machines or generated-table dispatch.
R0-R30 passed their affected suites and PR gates before merge. R31 was validated with the affected crates' complete test suites, warnings-as-errors clippy, formatting, frozen fingerprint and coordinate fixtures, the budget scanner, and diff checks; repository-wide release and binding gates remain the responsibility of the PR CI before merge.
Retained debt
The remaining function allowances are ordered chemistry data, bounded graph/search algorithms, format state machines, or compatibility ports whose branch and accumulation order is observable. They are reviewed debt, not exemptions. No production Rust file exceeds the checked limit.
Remove one bounded stage at a time with its domain corpus. Do not split tables or reorder chemistry merely to reduce line count. A new phase is warranted only when it can lower the ratchet without changing public behavior.
Required checks for future refactors
- Run formatting, affected tests, and clippy with warnings denied.
- Run the budget checker and scanner tests.
- Run relevant Rust, Python, WASM/Node, and cross-binding gates.
- Compare outputs for every touched chemistry or format domain.
- Measure paired time or instructions before accepting a hot-path change.
Moving code alone is not completion. Public contracts must remain stable, applicable gates must pass, and every retained exception must remain justified in the inventory.