fix(session): bound the in-memory session cache

Keep only 128 recently used sessions strongly cached while retaining weak references to evicted sessions still owned by active callers. This bounds idle memory growth without allowing duplicate live Session objects or skipping shutdown flushes.

Add LRU, lifecycle, SDK, and flush regression coverage.

Refs #4786
This commit is contained in:
KDB authored and Xubin Ren committed 2026-07-18 17:37:07 +08:00
1 parent d4f5abe004
commit d35f99abfc
4 files changed
+137 -9

No files matched your search

+2 -2
View File
@@ -66,7 +66,7 @@ class SessionClient:
def get(self, session_key: str) -> SessionSnapshot | None:
"""Return a display-safe snapshot without creating a new session on disk."""
cached = self._loop.sessions._cache.get(session_key)
cached = self._loop.sessions._cached(session_key)
if cached is not None:
return snapshot_from_session(cached)
payload = self._loop.sessions.read_session_file(session_key)
@@ -90,7 +90,7 @@ class SessionClient:
def export(self, session_key: str) -> SessionSnapshot | None:
"""Return a trusted full snapshot, including model-only runtime context."""
cached = self._loop.sessions._cache.get(session_key)
cached = self._loop.sessions._cached(session_key)
if cached is not None:
return snapshot_from_session(cached, include_runtime_context=True)
payload = self._loop.sessions.read_session_file(session_key)