You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Local rate-limit window: throttle the eviction sweep when the key table is full of live keys #21907
In autobot_shared/rate_limiter_window.py, when the local key table is at LOCAL_WINDOW_MAX_KEYS and every key is still live, each request for a new key scans the whole table under the lock (_live / _evict_stale) before refusing. During a Redis outage in LOCAL mode, a flood of distinct keys makes that scan run on every request, costing event-loop CPU. It is bounded by the cap, so this is hardening, not a defect.
Acceptance criteria
The full-table eviction sweep runs at most once per configurable interval (env-backed constant), and new keys are refused without a scan in between
A test shows N new-key calls on a full live table trigger at most one sweep per interval
autobot_shared/rate_limiter.py stays under 600 lines (it was 599 at review time; split if touched)
Closure check: PR #21966 merged at a40a7d4. Each criterion below was verified against origin/main.
AC
Evidence
Sweep runs at most once per interval, env-backed, and new keys are refused with no scan in between
autobot_shared/rate_limiter_window.py:62 defines LOCAL_WINDOW_SWEEP_INTERVAL = env_float_clamped("AUTOBOT_RATE_LIMIT_LOCAL_SWEEP_INTERVAL", 1.0, positive_finite=True). _sweep_if_due (L138-143) returns early while mono - self._last_sweep < self._sweep_interval. _last_sweep is monotonic and only touched under _lock (L91).
A test shows N new keys trigger at most one sweep per interval
autobot_shared/rate_limiter_window_18087_test.py:240TestSweepThrottle, :253test_n_new_keys_on_a_full_live_table_sweep_once_per_interval: 50 new keys give 1 scan. With the throttle removed it fails with assert 50 == 1 (shown in #21966).
rate_limiter.py stays under 600 lines
autobot_shared/rate_limiter.py is 599 lines on main and was not touched by #21966.
Activity
fix(rate-limit): validate sweep interval env, document refusal window…
test(rate-limit): probe sweep-interval env on a throwaway module copy…
Merge pull request #21966 from mrveiss/issue-21907-eviction-throttle
mrveiss commentedon Nov 21, 2026
Closure check: PR #21966 merged at a40a7d4. Each criterion below was verified against
origin/main.autobot_shared/rate_limiter_window.py:62definesLOCAL_WINDOW_SWEEP_INTERVAL = env_float_clamped("AUTOBOT_RATE_LIMIT_LOCAL_SWEEP_INTERVAL", 1.0, positive_finite=True)._sweep_if_due(L138-143) returns early whilemono - self._last_sweep < self._sweep_interval._last_sweepis monotonic and only touched under_lock(L91).autobot_shared/rate_limiter_window_18087_test.py:240TestSweepThrottle,:253test_n_new_keys_on_a_full_live_table_sweep_once_per_interval: 50 new keys give 1 scan. With the throttle removed it fails withassert 50 == 1(shown in #21966).rate_limiter.pystays under 600 linesautobot_shared/rate_limiter.pyis 599 lines on main and was not touched by #21966.fix(rate-limit): throttle the local window's eviction sweep on a full…