[chat] Add eviction and TTL to _active_streams (#736) #834

Closed
sleepy wants to merge 0 commits from fix/active-streams-eviction-736 into main
Owner

Fixes #736

Problem

_active_streams dict in routes/chat_routes.py grows indefinitely — entries are added when streams start but never cleaned up on timeout/error/abandon.

Fix

  • Added _STREAM_TTL_SECONDS constant (30 minutes)
  • Added _evict_stale_streams() helper that prunes entries older than TTL
  • Added _created_at timestamp to each entry on creation
  • Lazy eviction called on every read/write path (insert, _stream_set update, chat_stream_status read)

No new test failures. All 7 pre-existing failures remain unchanged.

Fixes #736 ## Problem `_active_streams` dict in `routes/chat_routes.py` grows indefinitely — entries are added when streams start but never cleaned up on timeout/error/abandon. ## Fix - Added `_STREAM_TTL_SECONDS` constant (30 minutes) - Added `_evict_stale_streams()` helper that prunes entries older than TTL - Added `_created_at` timestamp to each entry on creation - Lazy eviction called on every read/write path (insert, `_stream_set` update, `chat_stream_status` read) No new test failures. All 7 pre-existing failures remain unchanged.
The module-level _active_streams dict tracked streaming sessions but
never cleaned up entries from abandoned streams (client disconnect,
unhandled error, etc.). Over time this could grow without bound.

Add:
- _STREAM_TTL_SECONDS constant (30 min)
- _evict_stale_streams() helper that prunes entries older than TTL
- _created_at timestamp on each entry
- Lazy eviction on every read/write path (insert, update, status check)
sleepy closed this pull request 2026-06-04 11:42:16 +02:00

Pull request closed

Sign in to join this conversation.
No description provided.