fix: detect synthetic weekly quota exhausted state#1619
Conversation
- Add usageRatio >= 1.0 check to set status='exhausted' and Ready=false - Previously only checked WarningThresholdRatio, missing exhausted state - Requests leaked through to upstream provider instead of being blocked - Update test to verify exhausted status and Ready=false for weekly limit
Greptile SummaryThis PR fixes a bug where the synthetic weekly token quota never reported an "exhausted" state, even when usage reached 100%, allowing requests to leak through to the upstream provider instead of being blocked.
Confidence Score: 5/5Safe to merge — the fix is minimal, targeted at a clear gap in exhausted-state detection, and the refactored The weekly quota exhausted detection bug ( No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[weeklyTokenLimitStatus called] --> B{PercentRemaining nil?}
B -- Yes --> C[status = available\nusageRatio = 0.0]
B -- No --> D[usageRatio = 1.0 - percentRemaining/100]
D --> E{usageRatio >= 1.0?}
E -- Yes --> F[status = exhausted]
E -- No --> G{usageRatio > WarningThresholdRatio?}
G -- Yes --> H[status = warning]
G -- No --> I[status = available]
F --> J[IsReadyStatus: false]
H --> K[IsReadyStatus: true]
I --> L[IsReadyStatus: true]
C --> L
J --> M[QuotaLimitStatus returned\nReady: false — blocks upstream]
K --> N[QuotaLimitStatus returned\nReady: true — allows upstream]
L --> N
Reviews (2): Last reviewed commit: "refactor(quota): use IsReadyStatus helpe..." | Re-trigger Greptile |
There was a problem hiding this comment.
Code Review
This pull request updates the weeklyTokenLimitStatus function to correctly identify and handle exhausted quotas by setting the status to 'exhausted' and the Ready flag to false when the usage ratio is 1.0 or greater. The associated unit tests were also updated to verify this behavior. Feedback suggests using the IsReadyStatus helper function for the Ready field to maintain consistency and improve code maintainability.
| Status: status, | ||
| UsageRatio: usageRatio, | ||
| Ready: true, | ||
| Ready: status != "exhausted", |
There was a problem hiding this comment.
For better consistency and maintainability, use the IsReadyStatus helper function defined in types.go instead of hardcoding the status check. This ensures that the logic for determining if a quota is 'ready' remains centralized and consistent with other parts of the codebase, such as the parseResponse function.
| Ready: status != "exhausted", | |
| Ready: IsReadyStatus(status), |
Replace status != "exhausted" with IsReadyStatus(status) in synthetic_checker, nanogpt_checker, and claudecode_checker for consistency with the rest of the codebase.
Purpose/Goal: Fix synthetic weekly token quota never reporting exhausted state, causing requests to leak through to upstream provider instead of being blocked by AxonHub.
Why
The synthetic weekly token quota was never reporting "exhausted" state even when usage reached 100%, causing requests to leak through to the upstream provider instead of being blocked by AxonHub.
What Accomplished
usageRatio >= 1.0to set status as "exhausted"Readyfield to returnfalsewhen quota is exhaustedSpirit/Intent
Ensure AxonHub properly enforces synthetic token quota limits by correctly detecting and blocking requests when the weekly quota is fully consumed, preventing unauthorized upstream calls and protecting against quota exhaustion.