Repository navigation
fix(anthropic): keep weekly usage readings across 5h rollovers - #8723
Merged
Wei-Shaw merged 1 commit intoNov 16, 2026
Merged
Conversation
A 5h window rollover cleared the sampled 7d and 7d_oi readings along with the 5h utilization. Only Fable responses carry 7d_oi, and a Fable-exhausted account stops receiving Fable requests, so its 7d F reading stayed empty until the weekly reset. Weekly thresholds also lost their input after every rollover. Clear the 5h utilization as before, but keep a weekly reading while its own reset is still ahead. Readings without a reset or past their reset are still cleared.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
When the 5h window rolls over,
UpdateSessionWindowclears every sampled usage reading. That includes the 5h utilization and also the 7d and 7d_oi utilization and reset:The weekly windows have their own reset times, and a reading only comes back when a later response carries that window's headers. For 7d_oi, those responses stop:
anthropic-ratelimit-unified-7d_oi-*.persistAnthropicFableWindowLimitsets theclaude-fable-5model limit (anthropic_7d_oi_window_exhausted), so the account receives no further Fable requests.We saw this on setup-token accounts. Every account that had lost its 7d F reading had served no Fable requests in its current 5h window, and most of them were under the Fable window limit. Every account that had served at least one Fable request in the window still had its reading.
The weekly scheduling thresholds in
account_scheduling_threshold_eval.goread the same keys. They also lose their input at each rollover, until the next weekly sample arrives.Fix
rolloverPassiveUsageClearsbuilds the rollover update:session_window_utilization, which belongs to the previous 5h window. This is unchanged.passive_usage_7d_*orpassive_usage_7d_oi_*) while its stored reset is still in the future.passive_usage_sampled_atonly when no weekly reading is kept, because the sample time still describes any reading that remains.The next sample with weekly headers replaces a kept reading. After its reset passes, the next rollover clears it.
Tests
TestUpdateSessionWindow_RolloverKeepsCurrentWeeklyReadings: a Fable-exhausted account gets a non-Fable response (5h and 7d headers, no 7d_oi) when its 5h window has expired. The 7d F reading must survive, and the 5h and 7d readings must take the new values. This test fails onmain.TestRolloverPassiveUsageClears: current, expired and missing resets, with reset values stored as int64, float64,json.Numberand string.TestUpdateSessionWindow_ClearsFable7dOiOnWindowReset(no stored reading, so everything is still cleared).go test ./internal/service/... ./internal/repository/...passes.