Support additional rate limit categories in Codex usage#269
Conversation
The wham usage API can return additional rate limit categories via the additional_rate_limits field which was previously ignored, causing data loss during sync. https://claude.ai/code/session_017aLMXajKTAGqTgYimP7UXk
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request updates the whamUsageResponse struct to include a map for additional rate limits and implements logic to process these limits in fetchCodexUsage. Feedback was provided to filter out keys that are already explicitly handled to prevent duplicate entries in the results and to note the non-deterministic nature of map iteration.
| for name, cat := range usage.AdditionalRateLimits { | ||
| if cat == nil { | ||
| continue | ||
| } | ||
| if w := cat.PrimaryWindow; w != nil { | ||
| windows = append(windows, mapWhamWindow(name, "primary", w)) | ||
| } | ||
| if w := cat.SecondaryWindow; w != nil { | ||
| windows = append(windows, mapWhamWindow(name, "secondary", w)) | ||
| } | ||
| } |
There was a problem hiding this comment.
The iteration over AdditionalRateLimits does not check for potential key collisions with the explicitly handled fields (rate_limit and code_review_rate_limit). If the backend returns these keys within the additional_rate_limits map, it will result in duplicate entries in the windows slice with identical LimitIDs. Consider skipping these keys to ensure uniqueness. Additionally, note that map iteration in Go is non-deterministic, so the order of these additional windows in the slice will vary between calls.
for name, cat := range usage.AdditionalRateLimits {
if name == "rate_limit" || name == "code_review_rate_limit" {
continue
}
if cat == nil {
continue
}
if w := cat.PrimaryWindow; w != nil {
windows = append(windows, mapWhamWindow(name, "primary", w))
}
if w := cat.SecondaryWindow; w != nil {
windows = append(windows, mapWhamWindow(name, "secondary", w))
}
}
Summary
Extended the Codex rate limit handling to support additional rate limit categories beyond the primary
rate_limitandcode_review_rate_limitfields.Key Changes
AdditionalRateLimitsfield towhamUsageResponsestruct to capture additional rate limit categories from the backend API responsefetchCodexUsage()to iterate through and process additional rate limit categories, mapping both primary and secondary windows for each categoryImplementation Details
The new
AdditionalRateLimitsfield is a map that allows the API response to include arbitrary additional rate limit categories. The code processes each category similarly to the existing rate limit categories, extracting primary and secondary windows and converting them to the internalCodexRateLimitDataformat using the existingmapWhamWindow()function.https://claude.ai/code/session_017aLMXajKTAGqTgYimP7UXk