refactor(rate-limit): key free-model limit on user id for authenticated requests#3004
Open
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
Open
refactor(rate-limit): key free-model limit on user id for authenticated requests#3004kilo-code-bot[bot] wants to merge 1 commit intomainfrom
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
Conversation
…ed requests Authenticated free-model requests are now rate-limited per user id regardless of feature or source IP. Anonymous requests continue to be rate-limited per IP, counting only anonymous usage so they aren't skewed by authenticated users on shared IPs. This removes the feature/Cloudflare-IP special case that existed for cloud-agent, code-review and app-builder.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Reviewed by gpt-5.5-2026-04-23 · 158,490 tokens |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
free_model_usageso the limit is not skewed by authenticated users sharing the same IP.USER_RATE_LIMITED_FEATURES/isUserRateLimitedFeature/ Cloudflare-IP special case forcloud-agent,code-review, andapp-builder— they are handled uniformly now.Behavioural notes:
resolveRateLimitnow awaits auth before deciding the key. The pre-auth IP fast-path for authenticated callers is gone; the trade-off is correct per-user accounting across shared-infra IPs.checkFreeModelRateLimit(ipAddress)is now anonymous-only;checkFreeModelRateLimitByUser(userId)is unchanged and used for every authenticated request.checkPromotionLimit(10k/24h anonymous gate) is unaffected.Verification
apps/web/src/app/api/openrouter/[...path]/route.tsto confirm anonymous free-model requests still run through the promotion limit, and authenticated ones hit the user-keyed counter.feature-detection.test.tsto confirm only the removed helper's tests needed deletion.Full
pnpm typecheck/pnpm test/pnpm formatwere skipped locally (sandbox has nonode_modules); CI will run them.Visual Changes
N/A
Reviewer Notes