[chat/streaming] _active_streams dict has no eviction, TTL, or size limit #736

Closed
opened 2026-06-03 00:10:52 +02:00 by sleepy · 0 comments
Owner

Problem

routes/chat_routes.py line 43 defines _active_streams: Dict[str, dict] = {} — a module-level dictionary that tracks active streaming sessions.

Entries are added when streaming starts and removed in finally blocks. However:

  1. If the finally block fails (e.g., exception during partial-save), the entry persists forever
  2. No TTL or expiry on stale entries
  3. No size limit — a burst of concurrent streams could grow this without bound
  4. No periodic cleanup

This is the same pattern flagged in #682 for _RUNS in agent_runs.py.

Impact

  • Memory leak in long-running processes if finally cleanup is skipped
  • Stale entries make /api/chat/stream_status return stale data

Suggested fix

  1. Add a TTL to entries and reject stale lookups (e.g., entries older than 30 minutes are invalid)
  2. Add a periodic cleanup coroutine or a max-size eviction policy
  3. Or merge this with the agent_runs tracking into a unified stream registry
## Problem `routes/chat_routes.py` line 43 defines `_active_streams: Dict[str, dict] = {}` — a module-level dictionary that tracks active streaming sessions. Entries are added when streaming starts and removed in `finally` blocks. However: 1. If the `finally` block fails (e.g., exception during partial-save), the entry persists forever 2. No TTL or expiry on stale entries 3. No size limit — a burst of concurrent streams could grow this without bound 4. No periodic cleanup This is the same pattern flagged in #682 for `_RUNS` in agent_runs.py. ## Impact - Memory leak in long-running processes if `finally` cleanup is skipped - Stale entries make `/api/chat/stream_status` return stale data ## Suggested fix 1. Add a TTL to entries and reject stale lookups (e.g., entries older than 30 minutes are invalid) 2. Add a periodic cleanup coroutine or a max-size eviction policy 3. Or merge this with the `agent_runs` tracking into a unified stream registry
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sleepy/odysseus#736
No description provided.