fix(py-gov-rag): expose rate_limit_window_seconds on RAGPolicy#2159
Merged
imran-siddique merged 1 commit intoMay 12, 2026
Merged
Conversation
RAGGovernor instantiated RateLimiter(window_seconds=60) directly, so even though RAGPolicy.max_retrievals_per_minute is configurable, the window length wasn't. Callers wanting a 5-second burst window or a 300-second quota window had to monkey-patch self._rate_limiter after construction. Adds rate_limit_window_seconds: int = 60 to RAGPolicy (default preserves prior behaviour). The governor forwards it to RateLimiter, and the resulting RateLimitExceededError surfaces the configured window so error messages no longer hard-code "per 60s". __post_init__ rejects non-positive windows up front rather than silently disabling the limiter (window=0) or pushing the sliding cutoff into the future (negative). Verified: PYTHONPATH=src python -m pytest tests/ -q -> 93 passed, 1 skipped.
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI Compatibility
|
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: test-generator — `governor.py`
|
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
🤖 AI Agent: code-reviewer — View detailsTL;DR: 1 blocker, 0 warnings. The change introduces a potential security bypass if the rate limit window is not properly validated.
Action items: Ensure that the Warnings: No warnings found. Fine as follow-up PRs. |
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
PR Review Summary
Verdict: ❌ Changes needed |
MohammadHaroonAbuomar
pushed a commit
to MohammadHaroonAbuomar/agt-acs
that referenced
this pull request
Jun 1, 2026
…soft#2159) RAGGovernor instantiated RateLimiter(window_seconds=60) directly, so even though RAGPolicy.max_retrievals_per_minute is configurable, the window length wasn't. Callers wanting a 5-second burst window or a 300-second quota window had to monkey-patch self._rate_limiter after construction. Adds rate_limit_window_seconds: int = 60 to RAGPolicy (default preserves prior behaviour). The governor forwards it to RateLimiter, and the resulting RateLimitExceededError surfaces the configured window so error messages no longer hard-code "per 60s". __post_init__ rejects non-positive windows up front rather than silently disabling the limiter (window=0) or pushing the sliding cutoff into the future (negative). Verified: PYTHONPATH=src python -m pytest tests/ -q -> 93 passed, 1 skipped.
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
governor.py'sRAGGovernor.__init__instantiatedRateLimiter(window_seconds=60)with the 60 hard-coded. The companionpolicy.py'sRAGPolicyexposesmax_retrievals_per_minutebut not the window length, so callers wanting a 5-second burst window or a 300-second quota window had to monkey-patchgovernor._rate_limiterafter construction.Change
Adds
rate_limit_window_seconds: int = 60toRAGPolicy(default preserves prior behaviour).RAGGovernorforwards it toRateLimiter, and the resultingRateLimitExceededErrorsurfaces the configured window in its message rather than the hard-coded "per 60s".RAGPolicy.__post_init__rejects non-positive windows up front with aValueError—0would silently disable the limiter (whichmax_retrievals_per_minute=0is already the documented switch for), and negative values would push the sliding cutoff into the future.The docstring on
max_retrievals_per_minutenow points at the new field instead of saying "60-second sliding window."Tests
New
tests/test_rate_limit_window.pypins the behaviour:test_default_window_is_sixty_secondstest_governor_propagates_window_to_rate_limitertest_short_window_expires_faster_than_defaultRateLimitExceededError.window_seconds == 1test_long_window_keeps_state_past_defaulttest_non_positive_window_rejected0and negative values raiseValueErrorTest plan
test_rate_limiter.py/test_governor.py/test_policy.pycases still pass (default window unchanged)test_rate_limit_window.pycases passRateLimitExceededError.window_secondsreflects the configured policy value, not the previous hard-coded 60Surfaced during independent audit conducted by @finnoybu (Ken Tannenbaum, AEGIS Initiative); [LOW, Python Governance].