Skip to content

fix: prune stale in-memory rate limit keys#1001

Open
saurabhhhcodes wants to merge 1 commit into
SdSarthak:mainfrom
saurabhhhcodes:fix/rate-limiter-stale-key-cleanup-928
Open

fix: prune stale in-memory rate limit keys#1001
saurabhhhcodes wants to merge 1 commit into
SdSarthak:mainfrom
saurabhhhcodes:fix/rate-limiter-stale-key-cleanup-928

Conversation

@saurabhhhcodes

Copy link
Copy Markdown
Contributor

Summary\n\nCloses #928\n\nThe shared distributed rate limiter now periodically prunes stale in-memory keys instead of letting the fallback dict grow forever. It also removes the direct _scan_attempts_by_user alias from the Guard router and moves tests onto public helper methods so the limiter internals stay encapsulated.\n\n## Changes\n\n- add public clear_local_attempts() and cleanup_stale_local_attempts() helpers\n- track the longest window seen per key so stale cleanup stays safe across endpoints\n- prune expired local entries during periodic cleanup sweeps\n- remove the direct internal alias from backend/app/api/v1/guard.py\n- update conftest and Guard tests to use the public helper instead of private state\n\n## Validation\n\n- git diff --check\n- /Users/saurabhkumarbajpaiai/.cache/codex-runtimes/codex-primary-runtime/dependencies/python/bin/python3 -m pytest backend/tests/test_rate_limit_helper.py backend/tests/test_guard_api.py backend/tests/integration/test_rate_limiting.py -q\n\n## Notes\n\nThe broader backend suite still has unrelated deprecation warnings in the current checkout, but the touched rate-limit paths passed cleanly.

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.

2 participants