fix: guard total_cached_tokens against None in Gemini metrics#208
Open
sumleo wants to merge 1 commit into
Open
fix: guard total_cached_tokens against None in Gemini metrics#208sumleo wants to merge 1 commit into
sumleo wants to merge 1 commit into
Conversation
Author
|
Hi @baquy96, gentle nudge on this when you have a moment. It's a small, self-contained prompt-caching fix, and I'm happy to rebase or tweak anything if that would make review easier. Thanks for the project and your time! |
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.
What
GeminiInteractions._get_metricsassignscache_read_tokenswithout a null guard:total_cached_tokensisOptional[int]and comes back asNoneon a cache miss, socache_read_tokensends upNone. That value is later summed inMetrics.__add__, which raisesTypeError: unsupported operand type(s) for +: 'int' and 'NoneType'when metrics are accumulated across turns.Fix
Default to
0, matching the sibling assignments right above it (lines 976-978) and the equivalent handling ingemini.py:1439:Test
Added
test_cache_read_tokens_noneinTestGeminiInteractionsGetMetrics, mirroring the existingtest_cache_read_tokensand asserting that aNonecached-token count maps to0.Notes
The test module currently carries a module-level
pytest.skip(...)left over from an earlier refactor, so the suite is skipped in CI as-is. I confirmed the new case passes locally with the skip temporarily lifted (the wholeTestGeminiInteractionsGetMetricsclass is green). I left the skip untouched to keep this change scoped to the bug fix.