Skip to content

refactor(epic-1975): consolidate code duplication across LLM providers and utilities#2015

Merged
bug-ops merged 2 commits intomainfrom
epic-1975-dry
Mar 19, 2026
Merged

refactor(epic-1975): consolidate code duplication across LLM providers and utilities#2015
bug-ops merged 2 commits intomainfrom
epic-1975-dry

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 19, 2026

Summary

Consolidate 8 code duplication patterns identified in audit .local/audit/003-duplication-analysis.md:

  • DRY-01 + DRY-06: Extract UsageTracker struct to eliminate ~60 lines of duplication across 4 LLM providers (Claude, OpenAI, Ollama, Gemini)
  • DRY-05: Remove duplicate BoxFuture type alias in zeph-memory
  • DRY-04: Add ChannelError::other() helper to reduce boilerplate in 14 channel error-wrapping sites

Intentionally skipped DRY-02, 03, 07, 08 as having insufficient value-to-effort ratio.

Changes

  • Created crates/zeph-llm/src/usage.rs — new UsageTracker struct
  • Updated 4 providers to use UsageTracker instead of duplicate Mutex fields
  • Enabled #[derive(Clone)] for Ollama and Gemini providers
  • Added ChannelError::other() helper and replaced 14 call sites
  • Removed duplicate BoxFuture alias
  • Updated CHANGELOG.md

Test Results

  • 5932/5932 tests pass (15 skipped)
  • No regressions
  • Clippy clean
  • Formatting clean

Validation

  • ✅ Architecture review (architect + critic)
  • ✅ Security audit (5 areas, no issues)
  • ✅ Test validation (5932 tests)
  • ✅ Implementation critique (2 required fixes applied)
  • ✅ Code review (approved)

Closes #1975

bug-ops added 2 commits March 19, 2026 15:07
…d channels

DRY-01+06: Extract UsageTracker struct to crates/zeph-llm/src/usage.rs.
Replace duplicate last_usage/last_cache Mutex fields in Claude, OpenAI,
Ollama, and Gemini providers. Ollama and Gemini now use #[derive(Clone)]
where possible; Claude and Gemini retain manual Clone with UsageTracker::default().

DRY-05: Remove duplicate BoxFuture type alias from in_memory_store.rs;
import from vector_store.rs which is the canonical definition.

DRY-04: Add ChannelError::other() helper to zeph-core. Replace 14 sites
of .map_err(|e| ChannelError::Other(e.to_string())) in telegram, discord,
slack, and cli channels with .map_err(ChannelError::other).

Also fix pre-existing large_futures clippy warning in src/runner.rs.

5932 tests pass, clippy clean, fmt clean.
- Fix missed ChannelError::Other site in telegram.rs:267
- Remove pub(crate) from UsageTracker field in Ollama and Gemini providers
- Update gemini clone_resets_usage test to not access private field directly
- Add CHANGELOG.md entry under [Unreleased] for DRY-01+04+05+06 consolidations

Branch name exception: epic-1975-dry was created by EnterWorktree tool and
renaming would break the worktree session; name documents the epic scope.
@github-actions github-actions bot added refactor Code refactoring without functional changes size/L Large PR (201-500 lines) documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) channels zeph-channels crate (Telegram) rust Rust code changes core zeph-core crate and removed size/L Large PR (201-500 lines) refactor Code refactoring without functional changes labels Mar 19, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 19, 2026 14:35
@bug-ops bug-ops merged commit f257c91 into main Mar 19, 2026
22 checks passed
@bug-ops bug-ops deleted the epic-1975-dry branch March 19, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channels zeph-channels crate (Telegram) core zeph-core crate documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) rust Rust code changes

Projects

None yet

1 participant