Skip to content

[Architecture]: Massive code duplication creates merge conflict surface and policy drift #1030

Description

@morluto

Summary

Jacobian has three major code duplication zones that together produce the largest merge conflict surface in the repository, drive inconsistent policy enforcement, and create a maintenance burden far exceeding the duplicated code's value.

Root cause

1. verifier_support.py duplicated 233 times (#885)

  • 233 physical copies of the same 466-line file across benchmark datasets
  • Only 9 unique content hashes — 194 are byte-identical copies
  • 114,619 total lines of duplicated code
  • Appears in 394 merge conflict resolutions — the Adopt the v0.1 generic verification-kernel contract #1 conflict file
  • One merge commit touched 220 copies in a single merge
  • Duplication enforced by Harbor's separate-verifier build context (no symlinks, no parent COPY)

2. ~30,000 lines of duplicated verifier and spike code (#717)

  • Benchmark verifier code is hand-duplicated across dataset families
  • Provider feasibility spike utilities duplicated across multiple verifiers
  • Each copy can drift independently, creating policy inconsistencies

3. Duplicated capability helper code across domain contracts (#695, #696, #699)

  • Polynomial capability helpers duplicated, violating kernel-separation rules
  • Rational digit-bound validation duplicated across 5 contract modules
  • Hand-rolled linear algebra and combinatorial algorithms with maintained backends available

Evidence

Duplication Scale Conflict rate
verifier_support.py 233 copies, 114K lines 394 conflict resolutions
Verifier + spike code ~30,000 lines High merge conflict
Polynomial helpers 5+ modules Moderate
Rational digit-bound 5 contract modules Low

Impact

  • Adopt the v0.1 generic verification-kernel contract #1 merge conflict source: 394 conflict resolutions involving verifier_support.py
  • Repository bloat: ~114K lines of duplicated code
  • Slow PR review: 200+ file diffs in a single logical change
  • Policy drift: Each copy can diverge, creating inconsistent verifier behavior
  • Merge conflict amplification: N concurrent benchmark PRs all conflict against the same infrastructure change

Anti-patterns

  • Copy-paste reuse: Duplicating shared code instead of sharing it through a package or generated artifact
  • Enforced duplication: Validation gate requires physical copies, forbidding symlinks or shared imports
  • Drift-prone duplication: Each copy can independently diverge, creating policy inconsistencies
  • Hand-rolled reimplementations: Duplicating algorithms that maintained backends already provide

Best practices

  • Single source of truth: One human-edited source deterministically generates task-local runtime copies
  • Generated artifacts, not committed copies: CI verifies generated output matches source; it does not silently rewrite files
  • Shared packages: Extract shared code into a package that is vendored or available hermetically inside the build context
  • Content-addressable evidence: Use content-addressable evidence where the checksum is derived from the evidence itself, not from a pre-computed baseline
  • Reuse maintained backends: Do not reimplement linear algebra, combinatorics, or graph algorithms when SymPy, NetworkX, or other maintained backends provide them

Recommended architecture

  1. Short-term: Create a sync script that automatically propagates code changes to all verifier_support.py copies
  2. Medium-term: Investigate whether Docker multi-stage builds or build-time ADD <url> can fetch shared verifier code from a content-addressable location
  3. Long-term: Create a benchmark scaffolding tool that generates task directories from a template, stamping the correct verifier_support.py at generation time
  4. For capability helpers: Extract shared validation and conversion logic into domain-owned utility modules with explicit __all__ exports
  5. For reimplemented algorithms: Replace hand-rolled implementations with calls to maintained backends (SymPy, NetworkX, etc.)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1: highShould be addressed in the current or next iterationarea: architectureStructural refactoring, god classes, and design patternsarea: benchmarksBenchmark datasets, Harbor validation, and evaluation infrastructureepic: laterDeferred vs local-tool search+execute spinetech-debtTechnical debt and code quality issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions