Repository navigation
fix(llm): clamp huge usage counters instead of wrapping them - #740
Merged
Merged
Conversation
A token counter above u32::MAX from a compatible endpoint was cast with `as u32`, so a value just past the limit wrapped to a small number and the usage was lost before accumulation. The three counters are now clamped to u32::MAX, for the legacy, new and camelCase field names alike, with tests at and above the boundary.
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
The prompt, completion and total token counters read from a provider response are clamped to
u32::MAXinstead of being cast withas u32, for the legacy, new and camelCase field names alike.Why
A counter above
u32::MAXwrapped to a small number (u32::MAX + 1became 0), so the usage was lost before accumulation. Reported in #713; this PR covers the numeric-boundary part only, the rest of that issue is a separate request and stays open. Refs #713.Testing
u32::MAX(every field name) and exactly at the boundary.cargo fmt --all -- --check,cargo clippy --all-targets --features tree-sitter -- -D warnings,cargo test --features tree-sitter.