fix: stop rescaling Claude utilization below 1% to 100% - #274
Open
yozu wants to merge 1 commit into
Open
Conversation
`normalize_utilization` treated any `utilization` value in (0, 1] as a fraction and multiplied it by 100. The Claude usage API already reports these values in percent units, so a session at 1% was rendered as a fully consumed quota with a red "used up" state, while the Claude settings page showed 1%. The sibling `limits[].percent` field has always been consumed as-is by `scoped_weekly::weekly_all_window`, and issue payloads carry the same value in both fields (`seven_day.utilization: 1.0` alongside `weekly_all.percent: 1.0`), confirming the unit. Drop the rescaling in both the OAuth and web API fetchers so five-hour, seven-day, model-scoped and routines windows all report percent directly.
Collaborator
|
Thanks for the PR, I will review this ASAP. |
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.
Problem
A Claude session at 1% is displayed as 100% used, with the red "used up" state, while the Claude settings page reports 1% for the same window.
normalize_utilization(duplicated in the OAuth and web API fetchers) treats anyutilizationvalue in(0, 1]as a fraction and multiplies it by 100:The API already reports these values in percent units, so every window at or below 1% is inflated by 100x. Values above 1 are unaffected, which is why the bug only shows up on freshly reset windows.
Why percent is the right unit
scoped_weekly::weekly_all_windowalready consumes the siblinglimits[].percentfield as-is, without rescaling.weekly_all_limit_wins_over_stale_seven_day_utilizationtest carries"seven_day": {"utilization": 1.0}next to"kind": "weekly_all", "percent": 1.0— the same window, the same value, in both fields.limits[]path satisfied it;to_rate_windowdid not.Change
Remove
normalize_utilizationfrom both fetchers and useutilizationdirectly. This covers the five-hour session, seven-day, model-scoped (Opus/Sonnet), OAuth apps and Daily Routines windows.Tests
converts_fractional_utilization_to_percenttokeeps_sub_one_utilization_in_percent_unitsin both modules and flipped the expectation (0.23stays0.23).one_percent_session_is_not_reported_as_full_quotacovering the reported symptom directly.parses_current_snake_case_oauth_usage_response, which encoded the old behaviour (1.0->100.0,0.14->14.0).cargo test: 1207 passed, 0 failed.cargo clippy --all-targets: no new warnings.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.