Repository navigation
Description
Summary
check_rate_limit has five definitions. Four are copy-paste — structurally identical in-process fixed-window limiters in the MCP API modules — and the canonical autobot_shared.rate_limiter.RateLimiter they should use already exists and is already used by api/secrets.py.
Found while retiring symbol-fork clusters under #12771. Deliberately not folded into #18082: that PR is mechanical renames, and this is a behaviour-changing migration of security-adjacent code. Different risk class, so it gets its own review.
The four
| module | counter | limit constant |
|---|---|---|
api/git_mcp.py:242 |
git_counter |
MAX_GIT_OPS_PER_MINUTE |
api/browser_mcp.py:181 |
request_counter |
MAX_REQUESTS_PER_MINUTE |
api/database_mcp.py:252 |
query_counter |
MAX_QUERIES_PER_MINUTE |
api/http_client_mcp.py:298 |
request_counter |
MAX_REQUESTS_PER_MINUTE |
Each is the same function with a different dict name, a different constant and differently-worded logging:
async with _rate_limit_lock:
now = now_utc()
elapsed = (now - <counter>["reset_time"]).total_seconds()
if elapsed >= 60:
<counter>["count"] = 0
<counter>["reset_time"] = now
if <counter>["count"] >= <MAX>:
logger.warning(...)
return False
<counter>["count"] += 1
return TrueThe fifth, api/secrets.py:522, is a different signature ((request) -> None, raises) and already delegates to the canonical limiter — it is the model to follow, not another fork.
This is the documented consolidation target
RateLimiter.acquire_window's own docstring records that it already absorbed three forks:
Generalizes the fixed minute/hour windows above to a caller-chosen
window_seconds— folded in fromagents/web_researcher.py,security/threat_intelligence.pyandapi/secrets.py(Issue #12646), each of which used one configurable window rather than the dual minute/hour scheme.
So these four are the next four, and the pattern is proven on a more sensitive surface than MCP.
Two behaviour changes a reviewer must sign off, not wave through
-
Per-process → cross-process. The dict counters are per worker, so with N workers the effective limit is N× the intended one. Migrating makes the limit global. That is a fix, but it will look like a tightening to anyone who tuned the constants against observed behaviour.
-
Fails closed → fails open. The dict counter always enforces.
_try_acquire_windowreturns(True, 0.0)when Redis is unavailable, which its docstring states is the deliberate "graceful-degradation policy used everywhere else in this class". Forgit,database,http_clientandbrowserMCP operations, a Redis outage would therefore remove rate limiting entirely.
Point 2 is the one that needs a decision rather than a migration. The house policy is fail-open and api/secrets.py already accepts it; whether MCP write operations should is a separate judgement, and if the answer is no then the canonical limiter needs a fail-closed option rather than these four keeping their own implementations.
Acceptance criteria
- The four MCP modules obtain rate limiting from
autobot_shared.rate_limiter.RateLimiter, with no local counter dict or lock left behind - A recorded decision on fail-open vs fail-closed for MCP operations, with a fail-closed option added to the canonical limiter if that is the answer
- A test pinning the cross-process behaviour, so the per-worker multiplication cannot come back
-
check_rate_limitremoved fromrepo_tests/symbol_fork_baseline.json(one definition left, inapi/secrets.py)
Activity
refactor: retire ten symbol-fork clusters — 364 to 354 (#12771)
mrveiss commentedon Oct 9, 2026
Owner decision (2026-10-10): the four MCP limiters (git, browser, database, http_client) and the session password-change limiter count globally across workers, keeping the configured numbers. Before, each worker counted separately, so with N workers the effective limit becomes 1/N of what it was; that is the intended reading of the configured value, and it is the security-correct one for the password limiter. If MCP tools throttle too early under load, raise the env-backed limits; do not go back to per-worker counting. While Redis is unreachable these callers fall back to per-worker counting (
WindowFailurePolicy.LOCAL) and do not fail open.refactor: retire ten symbol-fork clusters — 364 to 354 (#12771)
fix(ai-ml): the dynamic model loads consult the pinned registry, and …
mrveiss commentedon Oct 16, 2026
Verdict pass (read-only, origin/main 84faf18)
autobot_shared/rate_limiter.pyRateLimiter(12 prod importers;acquire_windowis a Lua window that doesn't record rejects).autobot_shared/rate_limit.pyIPRateLimiter(3 importers) records rejects (ZADD before ZCARD, so the window extends) and falls back to an enforcing in-process window when Redis is down, where the canonical fails open. It is to be absorbed, then removed (under refactor: consolidate 4+ in-process rate-limit implementations into autobot_shared/rate_limit.py #7271).git_mcp.py,browser_mcp.py,database_mcp.py,http_client_mcp.py), plusapi/auth.py:79andmcp_server/autobot_server.py:144(_TokenBucket), which the audit missed. All are in-process per-worker dicts with literal limits and one global key each.symbol_forksonly catches same-name functions); an AST guard is the last slice.mrveiss commentedon Oct 16, 2026
Owner decisions (2026-10-16): (1) after migration the limits are global at the currently configured values, so the effective limit tightens by about the worker count. The values become env-backed so they can be raised. (2) When Redis is down, security-relevant limiters (auth, password change, MCP tool calls) fail open, the canonical
RateLimiterbehaviour. No LOCAL/CLOSED policy is needed for these six.fix(security): MCP and auth throttling is logged again at each 429; s…
fix(security): the MCP-server quota key hashes the whole token; limit…
fix(security): rate-limiter logs carry only the limiter label, never …
mrveiss commentedon Oct 16, 2026
Merged via #18616 in train 21 (#18619 → main 5f2c667). Evidence on origin/main:
git_mcp.py,browser_mcp.py,database_mcp.pyandhttp_client_mcp.pyeach construct the canonicalRateLimiter((1 hit each), with no local counter state;utils/thread_safety_test.pyasserts the latter per module.autobot-backend/api/mcp_rate_limits_18087_test.py:140test_two_workers_share_one_countand:166test_password_change_limit_is_global_and_429_text_unchanged.check_rate_limitis no longer inrepo_tests/symbol_fork_baseline.json(onlyapi/secrets.pystill defines one).mrveiss commentedon Nov 6, 2026
Reopened 2026-11-06 (maintainer decision: a closed issue whose work is not on main gets reopened). The rate-limiter fold from local branch
issue-18087-rate-limiter-forksis not on main. The pending hunks are listed on umbrella #7271: #7271 (comment). Redo it on current main by hunk picks; never revive the branch whole-file.10 remaining items
docs(rate-limit): the rate-limit registry docstring and the guard's p…
fix(rate-limit): bound local window keys, keep longer provider pause,…
Merge pull request #21823 from mrveiss/issue-18087-rate-limiter-forks
github-actions commentedon Nov 20, 2026
Landed in #21823, merge
bcd41c623dmrveiss commentedon Nov 20, 2026
Closure pass after #21823 merged (merge
bcd41c623d). Verified againstorigin/main:RateLimiter.WindowFailurePolicy.FAIL_CLOSEDinautobot_shared/rate_limiter.py(~L498), alongsideFAIL_OPEN(the default) andLOCAL. The MCP bridges still run on the default and fail open;docs/developer/ENV_VARS.md:371-375say "Fails open while Redis is unreachable". No recorded sign-off on fail-open vs fail-closed for MCP operations exists, and this criterion requires one.Decision needed (owner):
FAIL_CLOSEDon the five MCP limiters and updating ENV_VARS.md.Follow-up from review: #21907 (eviction-sweep throttle).
mrveiss commentedon Nov 20, 2026
Owner decision (2026-11-21): MCP operations keep FAIL-OPEN while Redis is unreachable. Behaviour on main already matches: the five MCP limiters use the default
WindowFailurePolicy.FAIL_OPEN, documented indocs/developer/ENV_VARS.md:371-375. A fail-closed option exists (WindowFailurePolicy.FAIL_CLOSED,autobot_shared/rate_limiter.py) if this is revisited. AC2 is met. All four ACs are verified, so closing as completed via #21823 (mergebcd41c623d). #21907 (hardening) stays open on its own.refactor(rate-limit): fold IPRateLimiter, the four MCP counters and t…
refactor(rate-limit): guard that no second rate limiter appears outsi…
refactor(rate-limit): drop .test_durations entries for the deleted ra…
refactor(rate-limit): IntegrationRateLimiter windows ride the canonic…
fix(integrations): a GitHub rate-limit reset is measured on the wall …