Skip to content

[codex] Prune stale rate-limit buckets#208

Open
pq198363-ops wants to merge 1 commit into
Agentpay-Org:mainfrom
pq198363-ops:bounty-142-ratelimit-prune
Open

[codex] Prune stale rate-limit buckets#208
pq198363-ops wants to merge 1 commit into
Agentpay-Org:mainfrom
pq198363-ops:bounty-142-ratelimit-prune

Conversation

@pq198363-ops

Copy link
Copy Markdown

Closes #142

Summary

  • add deterministic rate-limit bucket helpers that prune stale IP buckets without real sleeping in tests
  • opportunistically sweep expired buckets on each rate-limit hit so one-shot IP churn does not grow the map forever
  • preserve active buckets and the existing 429 rate_limited response shape with Retry-After
  • document the pruning behavior in the README

RED/GREEN

  • RED: npm run build failed before implementation because src/ratelimit-prune.test.ts imported missing applyRateLimitHit and pruneExpiredRateBuckets helpers.
  • GREEN: $env:NODE_ENV='test'; node --test dist/ratelimit-prune.test.js passed 4 pruning and active-limiter scenarios.

Verification

  • npm run build
  • $env:NODE_ENV='test'; node --test dist/ratelimit-prune.test.js -> 4 tests passed
  • $env:NODE_ENV='test'; node --test dist/*.test.js dist/**/*.test.js -> 93 tests passed
  • npm run lint
  • npx prettier --check README.md src/middleware/index.ts src/ratelimit-prune.test.ts
  • git diff --check

Note: the package npm test script uses Unix-style NODE_ENV=test; the Windows PowerShell equivalent above was used locally after clearing dist and rebuilding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prune empty IP buckets from the rate limiter to stop slow memory growth under churn

1 participant