Skip to content

fix(llm): clamp huge usage counters instead of wrapping them - #740

Merged
ajianaz merged 1 commit into
developfrom
fix/usage-counter-saturate
Nov 16, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/usage-counter-saturate

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What

The prompt, completion and total token counters read from a provider response are clamped to u32::MAX instead of being cast with as u32, for the legacy, new and camelCase field names alike.

Why

A counter above u32::MAX wrapped to a small number (u32::MAX + 1 became 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

  • New tests with counters above 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.

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.
@ajianaz
ajianaz merged commit 92ce93c into develop Nov 16, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant