fix(usage_manager): 🐛 prevent stale API responses from resetting quota count (#75) #81
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
remainingFraction: 1.0) from resetting local quota tracking to 0max(current_count, used_requests)to ensure the API can only increase our count, never decrease itProblem
When background refresh syncs with the API and receives a cached/stale response showing 100% remaining, the calculated
used_requestsbecomes 0. The previous code unconditionally overwrote local tracking with this value, wiping out accurate request counts.Solution
The API can only increase our count (if we missed requests), never decrease it. This prevents stale cache responses from corrupting local state while still allowing the API to correct our count upward if needed.
Fixes #75
Important
Fixes stale API responses resetting quota count to 0 in
update_quota_baseline()by usingmax()to ensure the count only increases.update_quota_baseline()inusage_manager.py.max(current_count, used_requests)to ensure API can only increase count, not decrease it.quota_displayto usesynced_countinstead ofused_requests.This description was created by
for f663c45. You can customize this summary. It will automatically update as commits are pushed.