# Remediation: Unnecessary Cloning
task: unnecessary-cloning
created: 2026-02-01
phase: AUDIT
status: NO_ACTION_REQUIRED

# Analysis Summary
total_clones: 237
breakdown:
  test_code: 160  # Files in tests/ + test modules in src
  arc_store_cloning: 45  # Arc::clone is O(1), correct pattern
  path_error_cloning: 7  # Required for error messages
  api_dto_cloning: 12  # Required for response construction
  lens_resolution: 13  # Required: resolve() returns owned Assertion from borrowed slice

# Conclusion
avoidable_clones: 0
justification: |
  All clone() calls in the codebase fall into justified categories:

  1. TEST CODE (160): Clones in test assertions and setup. Necessary.

  2. ARC/STORE CLONING (45): Arc::clone() is O(1) atomic increment.
     This is the correct pattern for sharing ownership.

  3. LENS RESOLUTION (13): The Lens trait signature is:
       fn resolve(&self, candidates: &[Assertion]) -> Resolution
     Resolution owns its winner Assertion. Since input is borrowed,
     we must clone to transfer ownership. This is the correct design.

  4. DECAY FUNCTIONS (6): apply_decay() creates modified copies of
     assertions with adjusted confidence. Cloning is semantically correct.

  5. API HANDLERS (12): Building response DTOs requires owning the data.
     String parameters must be cloned into response structs.

  6. ERROR CONSTRUCTION (7): PathBuf cloning for error messages.

# Recommendation
action: CLOSE_NO_FIX
reason: |
  The codebase has no unnecessary cloning debt. All clones serve legitimate
  purposes. The Rust compiler would warn about truly redundant clones.

  Potential future optimization (not debt):
  - Lens trait could use Cow<'_, Assertion> to avoid clones when winner
    is already owned. But this would complicate the API significantly
    for marginal gain (assertions are ~500 bytes, cloned at query time).
