Skip to content

Expose rate-limit bucket idle-eviction window as admin-configurable #73

Open

Description

@prometheusgr

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

  1. Add nullable SystemSettings column rate_limit_bucket_stale_after_seconds, following the exact pattern of the existing rate-limit fields in rate_limit_config_service.py.
  2. Wire into rate_limiter_service.py, replacing the module constant.
  3. Add to the existing Settings UI "Rate Limiting" section (added in the Settings Screen Help Text work) with a tooltip.
  4. Audit-log on change, folded into the existing "rate_limit.config_update" event.

Definition of Done

  • rate_limit_bucket_stale_after_seconds nullable column + Alembic migration.
  • resolve_rate_limit_config extended, 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_update event).
  • RBAC call-out per AGENTS.md TDD Discipline step 0: admin feature.
  • Standard merge gate from AGENTS.md's Definition of Done applies in full.

Activity

  1. added
    polishAdmin/UI surfacing or refinement of existing capability, not new functionality
    type:improvementMakes an existing capability better/safer/more complete
    priority:P3Deferred/speculative — explicitly not scheduled yet
    effort:SSmall: single file/component, hours not days
    area:rate-limitingToken-bucket rate limiting for chat/auth endpoints
    on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:rate-limitingToken-bucket rate limiting for chat/auth endpointseffort:SSmall: single file/component, hours not dayspolishAdmin/UI surfacing or refinement of existing capability, not new functionalitypriority:P3Deferred/speculative — explicitly not scheduled yettype:improvementMakes an existing capability better/safer/more complete

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions