Repository navigation
fix(ratelimit): make Redis Retry-After cover a full minute window - #2485
Conversation
When a key had used up both its per-second and per-minute budget, RedisLimiter.Allow answered with the per-second wait, so a client that honored Retry-After was refused again. Wait for the minute window whenever it is full, and never less than the second window. Closes #2483 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 24 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This changes the retry guidance shown to users for Redis-backed request-limit 429s: the web client reads
Suggested fix: attach those before-and-after screenshots and update the Evidence section to describe what they show. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee0ef26b6b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Both window keys roll over on wall-clock boundaries, so the time left in a full minute window already covers the second window. Taking the second key's cleanup TTL as well added a needless second to refusals in the minute's last second. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #2483
Related issue: #2211
Validation tasks: none
When a Redis-backed rate limit refuses a request because a key has used up both its per-second and its per-minute budget,
Retry-Aftergives only the per-second wait (one or two seconds). A client that waits that long is refused again, and only the second 429 carries the real wait until the minute window resets. This affects request rate limits withratelimit.backend = redis, and after #2211 the on-view translation budget whenever Redis is configured.RedisLimiter.Allowused the minute-window wait only when the second window still had room. This change uses it whenever the minute window is full, and never returns less than the second window's wait.Approach
The Retry-After choice moves into a small
redisRetryAfterhelper ininternal/ratelimit/redis.go, which returns the time left in the current minute whenever the minute window is full. Both window keys are named by wall-clock time, so that remainder also covers a full second window; the per-second key's TTL is a cleanup timer that can outlive its window and is not added on top. The remainder comes from the samenowthat names the minute key, so it matches the window the request was counted against. The per-second-only case is unchanged.No contract or schema changes. Clients see a longer
Retry-AfterandX-RateLimit-Reseton this one kind of refusal, which is the correct value.Validation
RedisLimiter.Allowfailed: with both windows full, Retry-After was 2s when the minute window had 50s (unit) and 29s (Redis) left. Both pass after it, and the unit test also checks that a refusal in the minute's last second waits 1s.SILO_TEST_REDIS_URL, as other Redis tests in the repo are. I ran it against a local Redis.go test.go build ./...,go vet,gofmt, andgolangci-lint --new-from-patchare clean.Evidence
Evidence: none, no user-visible change
Risks
None identified. The in-memory limiter has the same short-Retry-After behavior when both of its buckets are empty; that is #2486 and not changed here.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix Redis Retry-After to cover the full minute window in
RedisLimiter.AllowAdds
redisRetryAfterin redis.go. When the minute window is at its limit, the Retry-After value now spans the remaining time to the next minute boundary, even if the second window is also full. Otherwise the second-window TTL is still returned.SILO_TEST_REDIS_URLis set.redisRetryAfter.Macroscope summarized 179d1cb.