Skip to content

Improvements and query adjustments#6

Merged
khaliqgant merged 3 commits into
mainfrom
claude/optimize-agent-messaging-BoAQ1
Feb 9, 2026
Merged

Improvements and query adjustments#6
khaliqgant merged 3 commits into
mainfrom
claude/optimize-agent-messaging-BoAQ1

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Feb 9, 2026

Copy link
Copy Markdown
Member

Address 7 critical bottlenecks that would cause failures under chatty agent load:

1. N+1 queries: Batch message enrichment (replies, reactions, read receipts,
   attachments) into 4 queries total instead of 200+ per request
2. DB pool: Increase from 10 to 25 connections, add connect_timeout and
   max_lifetime settings
3. WS broadcast: Index clients by workspace:channel for O(subscribers)
   broadcast instead of O(all_clients) linear scan
4. Redis caching: Add 60s TTL cache for channel metadata lookups,
   invalidate on mutations
5. Event durability: Add pending_events table with retry/backoff for
   webhook delivery instead of fire-and-forget
6. Presence: Use Redis SETs (SADD/SMEMBERS) for O(1) presence queries
   instead of per-agent EXISTS checks
7. Rate limiting: Add per-route rate limits and in-memory token bucket
   fallback when Redis is unavailable

https://claude.ai/code/session_01Qa9PWXYRiMPFQbynkmkrCw
- Event queue: atomic claim with FOR UPDATE SKIP LOCKED to prevent
  duplicate processing across workers
- Event queue: use attempts from RETURNING result to fix off-by-one
- Event queue: remove publishEvent (route handles real-time, queue
  handles durable webhook delivery only)
- Event queue: clean up both completed and failed events in cleanup
- Rate limiter: in-memory fallback now respects per-route multipliers

https://claude.ai/code/session_01Qa9PWXYRiMPFQbynkmkrCw

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 8 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/server/src/middleware/rateLimit.ts Outdated
@khaliqgant khaliqgant merged commit 4301026 into main Feb 9, 2026
1 check passed
@khaliqgant khaliqgant deleted the claude/optimize-agent-messaging-BoAQ1 branch February 9, 2026 10:01
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