stemedb/.agentive-remediation/unnecessary-cloning/history.md
jordan c59066949a feat: Add quickstart "Beyond Hello World" sections with Skeptic and Layered endpoints
- Add Layered() method to Go SDK for per-source-class consensus queries
- Add LayeredQueryParams, LayeredResult, TierResolution types to Go SDK
- Create conflict example demonstrating Skeptic and Layered endpoints
- Update quickstart.md with sections 6 (conflict detection) and 7 (authority tiers)
- Remove tracked Go binary and add data/ to .gitignore

The new quickstart sections demonstrate Episteme's differentiating features:
- Skeptic endpoint shows "Trust but Verify" conflict analysis
- Layered endpoint shows per-tier resolution (Clinical vs Anecdotal)

Note: Pre-existing large files flagged by pre-commit hook (technical debt from prior sessions)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 21:00:59 -07:00

1.8 KiB

Unnecessary Cloning Remediation

AUDIT (2026-02-01)

Pattern: .clone() calls that could potentially be avoided

Found: 237 total clone calls across codebase

Breakdown Analysis

Category Count Justified? Reason
Test code (tests/, mod tests) 160 Yes Tests need owned values for assertions
Arc/Store cloning 45 Yes Arc::clone is O(1), correct pattern
Lens::resolve() returns 13 Yes Must return owned from borrowed input
apply_decay() copies 6 Yes Creates modified assertion copies
API DTO construction 12 Yes Response structs need owned data
PathBuf for errors 7 Yes Error messages need owned paths

Key Insight: Lens Trait Signature

pub trait Lens {
    fn resolve(&self, candidates: &[Assertion]) -> Resolution;
}

pub struct Resolution {
    pub winner: Option<Assertion>,  // <-- OWNED
    // ...
}

Since candidates is borrowed and Resolution.winner is owned, cloning is mandatory. This is correct API design - the caller retains their data while getting a result.

Potential Future Optimization (NOT DEBT)

Could use Cow<'a, Assertion> in Resolution:

pub struct Resolution<'a> {
    pub winner: Option<Cow<'a, Assertion>>,
}

But this would:

  • Complicate every Lens implementation
  • Add lifetime parameters throughout the codebase
  • Save ~500 bytes per query (negligible)

Not worth the complexity.

DECISION

Status: CLOSED - NO ACTION REQUIRED

The audit found zero unnecessary clones. The codebase follows Rust best practices:

  • Arc for shared ownership
  • Clone when transferring ownership from borrowed to owned
  • Test code uses clone liberally (appropriate)

No FIX, VERIFY, ENFORCE, or DOCUMENT phases needed.