fix: prune stale in-memory rate limit keys#1001
Open
saurabhhhcodes wants to merge 1 commit into
Open
Conversation
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\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_useralias from the Guard router and moves tests onto public helper methods so the limiter internals stay encapsulated.\n\n## Changes\n\n- add publicclear_local_attempts()andcleanup_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 frombackend/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.