Skip to content

feat: per-author rate limiting to prevent runaway agent loops#3

Merged
Killea merged 2 commits intoKillea:mainfrom
bertheto:feat/rate-limiting
Feb 28, 2026
Merged

feat: per-author rate limiting to prevent runaway agent loops#3
Killea merged 2 commits intoKillea:mainfrom
bertheto:feat/rate-limiting

Conversation

@bertheto
Copy link
Contributor

@bertheto bertheto commented Feb 27, 2026

Problem

Runaway agents can flood threads with messages, creating infinite loops or consuming all resources.

Solution

Per-author rate limiting in msg_post() before any DB write. Default: 30 messages/minute.

Changes

  • src/config.py: RATE_LIMIT_MSG_PER_MINUTE env var (default: 30) + RATE_LIMIT_ENABLED
  • src/db/crud.py: RateLimitExceeded exception, enforcement in msg_post()
    Uses author_id (agent identity) when available, falls back to author string
  • src/main.py: HTTP 429 response with Retry-After header
  • src/tools/dispatch.py: JSON error via MCP tool
  • test_rate_limit_unit.py: 9 unit + CRUD-level tests (no server needed)

Configuration

Env Var Default Description
AGENTCHATBUS_RATE_LIMIT 30 Messages per 60s per author (0 = disabled)

Backward Compatible

Set AGENTCHATBUS_RATE_LIMIT=0 to disable. No schema changes. No breaking API changes.

Tests

9 passed in 0.39s

bertheto and others added 2 commits February 27, 2026 16:54
Limit message posting per author per 60s window to prevent runaway agents
from flooding threads. Default limit: 30 msg/min (configurable).

- src/config.py: RATE_LIMIT_MSG_PER_MINUTE + RATE_LIMIT_ENABLED env vars
- src/db/crud.py: RateLimitExceeded exception + enforcement in msg_post()
  Uses author_id when available (agent identity), falls back to author string
- src/main.py: HTTP 429 + Retry-After header on RateLimitExceeded
- src/tools/dispatch.py: JSON error via MCP tool
- test_rate_limit_unit.py: 9 unit + CRUD-level tests (no server needed)

Backward-compatible: AGENTCHATBUS_RATE_LIMIT=0 to disable. No schema changes.
Made-with: Cursor
@Killea Killea merged commit d4c8a29 into Killea:main Feb 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants