Skip to content

Conversation

@b3nw
Copy link
Contributor

@b3nw b3nw commented Jan 17, 2026

Summary

  • Prevents stale API responses (returning remainingFraction: 1.0) from resetting local quota tracking to 0
  • Uses max(current_count, used_requests) to ensure the API can only increase our count, never decrease it
  • Applied fix to both primary model and grouped models to maintain state consistency

Problem

When background refresh syncs with the API and receives a cached/stale response showing 100% remaining, the calculated used_requests becomes 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 using max() to ensure the count only increases.

  • Behavior:
    • Fixes stale API responses resetting quota count to 0 in update_quota_baseline() in usage_manager.py.
    • Uses max(current_count, used_requests) to ensure API can only increase count, not decrease it.
    • Applies fix to both primary and grouped models for consistency.
  • Misc:
    • Updates quota_display to use synced_count instead of used_requests.

This description was created by Ellipsis for f663c45. You can customize this summary. It will automatically update as commits are pushed.

…a count (Mirrowel#75)

When background refresh receives remainingFraction: 1.0 (100% remaining)
from a stale/cached API response, the calculated used_requests becomes 0,
which was incorrectly wiping out local request tracking.

Use max(current_count, used_requests) to ensure the API can only increase
our count (if we missed requests), never decrease it. Applied to both
primary model and grouped models to maintain state consistency.
@b3nw b3nw requested a review from Mirrowel as a code owner January 17, 2026 06:03
@mirrobot-agent
Copy link
Contributor

I'm starting my review of the quota reset bug fix in usage_manager.py. I'll be checking if the use of max() correctly handles stale API responses while still allowing legitimate count updates.

Copy link
Contributor

@mirrobot-agent mirrobot-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Assessment

The fix for the quota reset bug (#75) is solid and correctly addresses the issue where stale API responses could reset the local request count to zero. By using max(current_count, used_requests), the UsageManager now ensures that local tracking only ever moves toward authority or increases, preventing accidental over-usage due to cached/stale API data.

Architectural Feedback

The implementation is consistent with the existing quota group logic. Using max() is a safe and effective defensive programming pattern here. Since authoritative resets of the request_count are still managed by local window timers and the _reset_model_data method, this change correctly protects against transient state corruption without interfering with legitimate quota resets.

Key Suggestions

None. The implementation is clean and directly solves the reported issue.

Questions for the Author

None.

This review was generated by an AI assistant.

@Mirrowel
Copy link
Owner

Actually, API can also increase too. I hit 0% quota remaining multiple times without hitting an API error. So API reporting can also increase. @b3nw

@Mirrowel
Copy link
Owner

Gonna look at possible solutions though. Maybe just by tightening counting locally. I think this needs a more complex system as we can't rely on the API anymore.

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.

2 participants