Repository navigation
Expose rate-limit bucket idle-eviction window as admin-configurable #73
Description
Context
docs/CONFIG_AUDIT_2026-09-04.md found that backend/app/services/rate_limiter_service.py:58 hardcodes _STALE_AFTER_SECONDS = 3600 — governing when an idle in-process rate-limit bucket entry (keyed per user_id or IP) is evicted, to bound memory growth. This sits right next to the already-DB-backed rate-limit capacity/refill fields (rate_limit_chat_capacity, rate_limit_chat_refill_per_minute, etc., Phase 4f) but wasn't included in that config surface.
Why this matters
An operator running with a much lower refill rate than the eviction logic's assumed baseline (the code comment assumes roughly 1 token/min) might want this window raised so buckets aren't evicted before they'd naturally refill, or lowered to bound memory more aggressively on a high-cardinality IP-keyed endpoint (POST /api/auth/token, unauthenticated and attacker-influenced per Phase 4f's hardening notes).
Scope
- Add nullable
SystemSettingscolumnrate_limit_bucket_stale_after_seconds, following the exact pattern of the existing rate-limit fields inrate_limit_config_service.py. - Wire into
rate_limiter_service.py, replacing the module constant. - Add to the existing Settings UI "Rate Limiting" section (added in the Settings Screen Help Text work) with a tooltip.
- Audit-log on change, folded into the existing
"rate_limit.config_update"event.
Definition of Done
-
rate_limit_bucket_stale_after_secondsnullable column + Alembic migration. -
resolve_rate_limit_configextended, unit-tested. - Wired into
rate_limiter_service.py's eviction logic. - Settings UI field + tooltip added to the existing Rate Limiting section.
- Audit logging on change (existing
rate_limit.config_updateevent). - RBAC call-out per
AGENTS.mdTDD Discipline step 0: admin feature. - Standard merge gate from
AGENTS.md's Definition of Done applies in full.
Activity