mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-25 19:20:16 +00:00
c75ce33280
PR #1421 (SessionDB WAL handle leak fix on cached-agent reuse path) had a sibling leak at the LRU eviction site that I caught during pre-review: api/streaming.py SESSION_AGENT_CACHE.popitem(last=False) was discarding the evicted entry with `evicted_sid, _ = ...`. The agent's _session_db was dropped on the floor and only released when GC eventually finalized the agent — which on a long-running server may be never (cyclic refs, extension types holding C handles, etc.). Same fix shape as #1421: capture the evicted entry, call _evicted_agent._session_db.close() explicitly. SessionDB.close() is idempotent + thread-safe (with self._lock: if self._conn:), so the double-close-is-benign property still holds. 5 regression tests in test_v050259_sessiondb_fd_leak.py: - Source-level: cached-agent reuse path closes before replace - Source-level: LRU eviction path captures + closes evicted agent - Behavioral: SessionDB.close() is idempotent (3 calls safe) - Behavioral: cached-agent reuse with mock — close called exactly once - Behavioral: LRU eviction with mock — only evicted agent's DB closes Full suite: 3615 passed, 0 failed. Nathan explicitly authorized 'just go ahead and merge it as a small release' since the PR is 9 LOC, focused, has Opus pre-release follow-up + tests, and matches the empirically-confirmed leak shape (73-handle leak at EMFILE).