fix(gateway): cap cached session sources with LRU eviction

Follow-up on top of Zyproth's session-source cache: swap the unbounded
dict for an OrderedDict with a 512-entry LRU cap so long-running
gateways can't accumulate stale entries for dead sessions forever.

- self._session_sources is now an OrderedDict
- _cache_session_source() move_to_end + popitem(last=False) above cap
- _get_cached_session_source() move_to_end on hit (LRU read bump)
- restart_test_helpers.py wires OrderedDict + _session_sources_max
This commit is contained in:
teknium1 2026-05-07 05:14:10 -07:00 committed by Teknium
parent 176b93575a
commit 333598cb0e
2 changed files with 27 additions and 4 deletions

View file

@ -1,4 +1,5 @@
import asyncio
from collections import OrderedDict
from unittest.mock import AsyncMock, MagicMock
from gateway.config import GatewayConfig, Platform, PlatformConfig
@ -74,7 +75,8 @@ def make_restart_runner(
runner._update_prompt_pending = {}
runner._voice_mode = {}
runner._session_model_overrides = {}
runner._session_sources = {}
runner._session_sources = OrderedDict()
runner._session_sources_max = 512
runner._shutdown_all_gateway_honcho = lambda: None
runner._update_runtime_status = MagicMock()
runner._queue_or_replace_pending_event = GatewayRunner._queue_or_replace_pending_event.__get__(