[agent_runs.py] Unbounded in-memory _RUNS dict with no size limit #682

Closed
opened 2026-06-02 23:43:47 +02:00 by sleepy · 1 comment
Owner

agent_runs.py uses unbounded in-memory dict with no size limit

File: src/agent_runs.py

_RUNS: Dict[str, _Run] = {}

This dict holds run buffers indefinitely. While there is a grace-period eviction (3 minutes after last subscriber disconnects on a finished run), there is no overall size cap:

  • A burst of 1000 sessions each streaming large responses could consume gigabytes
  • If runs never get subscribers (started but never subscribed to), the eviction timer still fires — but if they stay "running" indefinitely (wedged background task), they never get evicted
  • No metric or logging of _RUNS size for monitoring

Additionally

  • _Run.buffer is a list that grows unbounded during a run — a very long agent loop with many rounds accumulates all SSE events
  • No max-buffer-size protection

Suggested fix

  • Add a MAX_RUNS cap (e.g. 100) with oldest-first eviction
  • Add periodic logging of _RUNS size
  • Cap _Run.buffer at a max number of events or bytes
  • Consider using WeakValueDictionary or explicit TTL-based eviction
## agent_runs.py uses unbounded in-memory dict with no size limit ### File: `src/agent_runs.py` ```python _RUNS: Dict[str, _Run] = {} ``` This dict holds run buffers indefinitely. While there is a grace-period eviction (3 minutes after last subscriber disconnects on a finished run), there is no overall size cap: - A burst of 1000 sessions each streaming large responses could consume gigabytes - If runs never get subscribers (started but never subscribed to), the eviction timer still fires — but if they stay "running" indefinitely (wedged background task), they never get evicted - No metric or logging of `_RUNS` size for monitoring ### Additionally - `_Run.buffer` is a `list` that grows unbounded during a run — a very long agent loop with many rounds accumulates all SSE events - No max-buffer-size protection ### Suggested fix - Add a `MAX_RUNS` cap (e.g. 100) with oldest-first eviction - Add periodic logging of `_RUNS` size - Cap `_Run.buffer` at a max number of events or bytes - Consider using `WeakValueDictionary` or explicit TTL-based eviction
Author
Owner

Fixed via PR #879 — replaced Dict with OrderedDict, added 200-entry cap with FIFO eviction and graceful cancellation.

Fixed via PR #879 — replaced Dict with OrderedDict, added 200-entry cap with FIFO eviction and graceful cancellation.
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#682
No description provided.