refactor(epic-1975): consolidate code duplication across LLM providers and utilities#2015
Merged
refactor(epic-1975): consolidate code duplication across LLM providers and utilities#2015
Conversation
…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.
This was
linked to
issues
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidate 8 code duplication patterns identified in audit
.local/audit/003-duplication-analysis.md:UsageTrackerstruct to eliminate ~60 lines of duplication across 4 LLM providers (Claude, OpenAI, Ollama, Gemini)BoxFuturetype alias in zeph-memoryChannelError::other()helper to reduce boilerplate in 14 channel error-wrapping sitesIntentionally skipped DRY-02, 03, 07, 08 as having insufficient value-to-effort ratio.
Changes
crates/zeph-llm/src/usage.rs— newUsageTrackerstructUsageTrackerinstead of duplicate Mutex fields#[derive(Clone)]for Ollama and Gemini providersChannelError::other()helper and replaced 14 call sitesBoxFuturealiasTest Results
Validation
Closes #1975