Skip to content

fix(ratelimit): make Redis Retry-After cover a full minute window - #2485

Merged
Quick104 merged 2 commits into
mainfrom
fix/ratelimit-retry-after-minute-window
Oct 14, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/ratelimit-retry-after-minute-window

Conversation

@Quick104

@Quick104 Quick104 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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-After gives 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 with ratelimit.backend = redis, and after #2211 the on-view translation budget whenever Redis is configured.

RedisLimiter.Allow used 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 redisRetryAfter helper in internal/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 same now that 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-After and X-RateLimit-Reset on this one kind of refusal, which is the correct value.

Validation

  • Before the fix, a unit test for the helper and a Redis-backed test through RedisLimiter.Allow failed: 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.
  • The Redis-backed test is skipped without SILO_TEST_REDIS_URL, as other Redis tests in the repo are. I ran it against a local Redis.
  • The ratelimit package and every package that imports it pass go test. go build ./..., go vet, gofmt, and golangci-lint --new-from-patch are clean.
  • Not reproduced on a live deployment; the source path and the tests are the proof.

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

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated. No human has verified it yet.
  • Adversarial review: plan round skipped (a few-line fix where the source shows the root cause; nothing added). Code review with three read-only finders found no defect in the diff; their test-cleanup suggestions were applied. Background review by gpt-6.1-sol on ee0ef26 found nothing new. It confirmed the Codex review bot's comment that a full-minute refusal in the minute's last second added an unnecessary second; that is fixed. No findings left open.

🤖 Generated with Claude Code

Note

Fix Redis Retry-After to cover the full minute window in RedisLimiter.Allow

Adds redisRetryAfter in 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.

  • Adds table-driven unit tests for minute-window capacity, a full mid-minute window, and a full final second.
  • Adds an integration test that fills both windows and checks the delay; it runs only when SILO_TEST_REDIS_URL is set.
  • Behavioral Change: refused requests that exhaust the minute window receive a larger Retry-After value (until the next minute boundary) instead of the second-window TTL in redisRetryAfter.

Macroscope summarized 179d1cb.

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

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T21:32:53.307608Z 179d1cb New commits
🔒 Security Review ✅ Completed 2026-10-14T21:34:19.422769Z 179d1cb New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d74fcc91-b5fd-4de1-9d8c-ecaf71d70219
📥 Commits

Reviewing files that changed from the base of the PR and between efdc731 and 179d1cb.

📒 Files selected for processing: 2
  • internal/ratelimit/redis.go
  • internal/ratelimit/redis_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 14, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 14, 2026

Copy link
Copy Markdown

This changes the retry guidance shown to users for Redis-backed request-limit 429s: the web client reads Retry-After and uses it in visible rate-limit/cooldown messages. The Evidence section says no user-visible change, so it does not cover this effect.

  • internal/ratelimit/redis.go — add before-and-after screenshots of the same affected 429 state in the web UI, showing the changed retry guidance; identify the surface and build or commit. Redis test output alone does not show the user-visible change.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/ratelimit/redis.go Resolved
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

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit f346117 into main Oct 14, 2026
18 checks passed
@Quick104
Quick104 deleted the fix/ratelimit-retry-after-minute-window branch October 14, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Redis rate limit sends a too-short Retry-After when the minute window is also full

1 participant