fix(langchain): Stop double-counting usage in multi-candidate responses - #7064
Merged
alexander-alderman-webb merged 7 commits intoAug 10, 2026
Merged
Conversation
Contributor
Codecov Results 📊✅ 99560 passed | ⏭️ 6671 skipped | Total: 106231 | Pass Rate: 93.72% | Execution Time: 348m 44s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 88.89%. Project has 2501 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 90.01% 90.00% -0.01%
==========================================
Files 193 193 —
Lines 25020 25021 +1
Branches 9032 9032 —
==========================================
+ Hits 22521 22520 -1
- Misses 2499 2501 +2
- Partials 1434 1438 +4Generated by Codecov Action |
alexander-alderman-webb
marked this pull request as ready for review
August 6, 2026 13:38
sentrivana
approved these changes
Aug 7, 2026
alexander-alderman-webb
enabled auto-merge (squash)
August 10, 2026 09:16
alexander-alderman-webb
disabled auto-merge
August 10, 2026 09:19
alexander-alderman-webb
enabled auto-merge (squash)
August 10, 2026 09:19
alexander-alderman-webb
disabled auto-merge
August 10, 2026 09:19
alexander-alderman-webb
enabled auto-merge (squash)
August 10, 2026 09:20
alexander-alderman-webb
deleted the
webb/langchain/stop-double-counting-candidate-tokens
branch
August 10, 2026 09:23
6 tasks
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.
Description
Take token usage from the first candidate object in each generation, instead of summing token usage from each candidate.
The inner list in
LLMResult.generationscontains candidate generations (multiple output choices). Candidates do not have independent token usage, butlangchainhooks duplicate the token usage on each candidate.Add a test using a
google-genairesponse, asChatOpenAImodels do not enter theelse:branch below:sentry-python/sentry_sdk/integrations/langchain.py
Lines 769 to 774 in f670a1b
Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)