fix(claude): prefer limits[] session over stale five_hour after 5h rollover - #334
Merged
Merged
Conversation
…llover After a session window resets, the legacy five_hour.utilization field can transiently report 1.0 (normalized to 100%) for the new 5h window while claude.ai shows only 5% — same bug class as #210, which was fixed for the weekly lane in 0.48.0 by preferring limits[] weekly_all over seven_day. Apply the same pattern to the session (5h) lane: prefer the limits[] entry (kind=="session", group=="session") over legacy five_hour.utilization in both the OAuth and web API paths. When the limits[] session entry is absent, fall back to the legacy field (backwards compatible), then to the informational placeholder (web) / 0% (oauth). Fixes #279.
…reference chain The web_api issue-279 tests duplicated the limits[]-over-legacy preference chain inline instead of calling the production code, risking silent drift if the chain changes. Extract the chain into build_rate_windows so both production and tests share one canonical implementation. Net -9 lines.
This was referenced Aug 16, 2026
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.
Summary
Fixes #279.
After a session (5h) window resets, the legacy
five_hour.utilizationfield can transiently report1.0(normalized to100%) for the new window, even though claude.ai shows only5%. This is the same bug class as #210, which was fixed for the weekly/all-models lane in 0.48.0 by preferring thelimits[]weekly_allentry over legacyseven_day.utilization.This PR applies the identical pattern to the session (5h) lane, in both the OAuth and web API paths.
Root cause
Right after a window rollover, Anthropic leaves the legacy
five_hour.utilizationfield stale (reporting1.0→100%) while thelimits[]array already carries the fresh value as an entry withkind == "session",group == "session". The legacy field was read directly, so the stale100%won transiently until the legacy field caught up.Fix
scoped_weekly.rs: addsession_window(limits)— reads the 5h session window from thelimits[]array (kind == "session",group == "session"), mirroringweekly_all_window.web_api.rs: the primary lane now preferssession_window(&usage.limits)over legacyfive_hour, falling back to the legacy field, then the informational 5h placeholder.oauth/mod.rs: the primary lane now preferssession_window(&response.limits)over legacyfive_hour, falling back to the legacy field, then0%.Provider-specific logic stays inside
rust/src/providers/claude/(no cross-provider branching). No secrets/tokens are logged.Backwards compatible
When no
limits[]session entry is present (older API shape), the legacyfive_hourfield is still the source of truth — verified by a dedicated fallback test in each path.Test plan
cargo test --manifest-path rust/Cargo.toml— 1220 passed, 0 failedcargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleanscoped_weekly::tests::session_window_prefers_limits_percent_over_stale_five_hourscoped_weekly::tests::session_window_ignores_mismatched_group_and_null_percentweb_api::tests::issue_279_session_limits_win_over_stale_five_hour_after_rolloverweb_api::tests::session_falls_back_to_legacy_five_hour_without_limits_entryoauth::tests::issue_279_session_limits_win_over_stale_five_hour_after_rolloveroauth::tests::session_falls_back_to_legacy_five_hour_without_limits_entryNo UI/tray/float-bar behavior changed; no CUA proof needed (backend parser fix only).
Fixes #279.