refactor(dspy): use acall usage tracking#99
Merged
Conversation
enitrat
commented
Jan 3, 2026
Collaborator
Author
enitrat
left a comment
There was a problem hiding this comment.
[AUTOMATED]
Summary
This PR refactors DSPy module invocations from aforward to acall to leverage DSPy's built-in usage tracking mechanism, and replaces manual token usage accumulation with dspy.track_usage() context manager for streaming. This is a solid architectural improvement that simplifies code and improves reliability.
Strengths
- Cleaner usage tracking: Removing manual
_accumulate_usageand relying on DSPy'sacall/track_usage()is the right approach - Reduced complexity: ~11 fewer lines of production code with less manual plumbing
- Better separation of concerns: Usage tracking is now handled by the framework where it belongs
- Comprehensive test updates: All mocks properly updated to include
acallalongside existing methods
Minor Observations
- The
combine_usagefunction intypes.pyis no longer imported inrag_pipeline.pybut remains in the codebase (used elsewhere or could be dead code) - The
optimizer_artifacts_optionalfixture globally setsOPTIMIZER_RUN=1which is a reasonable approach for test isolation
Overall, this is a well-executed refactor that improves code quality. Tests pass according to the PR description.
- Remove unused `combine_usage` function from types.py - Remove corresponding `TestCombineUsage` tests - Add null guard with warning log for `lm_usage` in server/app.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2a6fd82 to
040e0b9
Compare
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
Context
DSPy attaches usage in module wrappers; moving to avoids missing usage and centralizes tracking.
Test Plan