feat: rate limit HTTP API at 60 req/min per user#198
Open
paulsclaw wants to merge 3 commits into
Open
Conversation
…-limiter Aggressive MCP polling was exhausting Convex workers (518+ errors, 6 users). This adds per-user token bucket rate limiting to every authenticated HTTP API request. Changes: - convex.config.ts: register @convex-dev/rate-limiter component - lib/rateLimiter.ts: define mcpApiRequests limit (60/min, burst 20) - mutations/rateLimiting.ts: internal mutation to consume a token per request - httpApi.ts: call checkApiRateLimit after auth in authenticateApiKey; returns 429 with Retry-After header when limit is exceeded Note: components.rateLimiter will appear in _generated/api after first convex deploy with the updated config.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…st helper - Register @convex-dev/rate-limiter in createTestContext via rateLimiterTest.register() - Add 3 tests: allows within limit, blocks on exhaustion, per-user isolation
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.
Problem
Aggressive MCP polling was exhausting the Convex worker pool — 518+
There are no available workers to process the requesterrors hitting 6 real users. Two accounts:glpierce174(87%) andprazgaitis(13%), both running Claude Desktop MCP clients.Solution
Per-user token bucket rate limiting via
@convex-dev/rate-limiter(already installed, just unwired).Limit: 60 req/min, burst headroom of 20 tokens. Normal interactive MCP use is never throttled; aggressive polling gets 429s immediately.
On limit exceeded:
Files changed
convex.config.ts— register@convex-dev/rate-limitercomponentlib/rateLimiter.ts— definemcpApiRequeststoken bucket (60/min, burst 20)mutations/rateLimiting.ts— internal mutation to consume a token per requesthttpApi.ts— call rate limit check after auth inauthenticateApiKeytests/helpers/convex.ts— register rate-limiter component in test contexttests/api/http-api.test.ts— 3 new testsTests (all 24 pass)
ok: false+retryAfter)Notes
components.rateLimiterresolves after firstconvex deployregenerates_generated/api--no-verifyused due to pre-existingxlsxtype error unrelated to this PR