Repository navigation
Description
What happened
Hermes Desktop becomes unstable after extended use (3-16+ hours), showing random "session not found" errors during normal conversation. The backend process crashes and restarts in a loop.
Root Cause
The Hindsight memory plugin leaks aiohttp ClientSession and TCPConnector objects. Connections are created on every retain/recall/reflect operation but never properly closed on error paths.
Evidence from logs
Before every WebSocket write failure:
ERROR asyncio: Unclosed client session
ERROR asyncio: Unclosed connector
connections: ['deque([(..., 60597.968)])']
Connection ages of 60,597 seconds (16.8 hours) prove connections are never closed — they live from first API call until process death.
Crash chain
aiohttp connections accumulate
→ process becomes sluggish
→ WebSocket write times out
→ Desktop frontend kills backend (SIGHUP)
→ backend restarts
→ 'session not found'
→ loop
Leak Points Found
1. _run_hindsight_operation() line 1031 (PRIMARY)
self._client = None # old client orphaned, aclose() never calledWhen a retriable embedded error occurs, the old client is replaced without closing it. Each retry leaks one aiohttp session.
2. HindsightEmbedded.del disabled (line 899)
HindsightEmbedded.__del__ = lambda self: NoneDestructor is monkey-patched to no-op, so GC cannot clean up unclosed sessions.
3. shutdown() swallows exceptions (line 1768)
except Exception:
pass # close failures silently ignoredIf aclose() fails (wrong event loop, timeout), the session leaks silently.
4. No del on HindsightMemoryProvider
When providers are garbage-collected without explicit shutdown(), the underlying aiohttp session is never closed.
Why This Only Affects Desktop Mode
- TUI: frontend and backend share one process; no WebSocket, so slow backend just causes a pause
- Desktop: frontend and backend communicate via WebSocket; slow backend causes write timeout → frontend disconnects → 'session not found'
Environment
- Windows 11, 16GB RAM
- Hermes Desktop 0.16.0
- Hindsight Docker (ghcr.io/vectorize-io/hindsight:latest)
- Python 3.11.15
- aiohttp 3.13.3
Workaround
Restart Desktop every 3-4 hours to flush accumulated connections.
Suggested Fix
Close old client before replacing in _run_hindsight_operation():
old_client = self._client
self._client = None
if old_client is not None:
try:
self._run_sync(old_client.aclose())
except Exception:
try:
old_client.close()
except Exception:
passAlso: add del to HindsightMemoryProvider, stop disabling HindsightEmbedded.del, and log close failures in shutdown() instead of swallowing them.
Activity
liuhao1024 commentedon Jun 14, 2026
This is fixed by #45693 — close aiohttp client on retry to prevent connection leak.
GottZ commentedon Jul 29, 2026
Summary
One PR addresses issue #45676. #45693 closes the orphaned aiohttp client before retrying and centralizes explicit shutdown cleanup, directly fixing the primary leak path, but its destructor-related changes conflict with the repository’s documented cross-event-loop cleanup design.
Related pull requests
best fix— (+123/-27) — partial fix: The diff replaces the retry branch’s bare_client = Nonewith_close_client(), directly closing the leaked client before reconstruction, and adds focused regression tests. The COMMENTED keep_open review on fix(hindsight): close aiohttp client on retry to prevent connection leak #45693 supports that core fix but requests retainingHindsightEmbedded.__del__suppression and removing the new provider__del__, because GC-time cleanup can cross event loops and cannot cover SIGKILL.Suggested consolidation
Merge #45693 after applying its COMMENTED keep_open review: preserve the
_close_client()helper, retry-path closure, shutdown reuse, and associated tests, while restoring the embedded destructor suppression and removing the provider-level__del__. There are no duplicate PRs to close.Complex graph
flowchart LR classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937 classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151 classDef best stroke-width:3px,stroke:#b45309 classDef target stroke-width:3px,stroke:#4338ca I45676(["issue #45676 (open)"]) P45693["PR #45693 (open)"] P45693 -->|best fix| I45676 class I45676 open class I45676 target class P45693 open class P45693 best click I45676 "https://github.com/NousResearch/hermes-agent/issues/45676" click P45693 "https://github.com/NousResearch/hermes-agent/pull/45693"Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).
Cross-PR triage: Reviewed 1 pull request and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 8 kB of PR diffs, 6 kB of issue/PR text, 1 kB of discussion (2 comments), 2 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
teknium1 commentedon Oct 6, 2026
Thanks for this, @strugglerrr. Hindsight no longer ships inside Hermes: it moved out of core in 4cbf862 and now installs as Vectorize's plugin from the plugin catalog (
hermes plugins install hindsight; existing setups migrate automatically). The retry path still looks leaky there:hindsight-integrations/hermes/__init__.py:816(at d56c4acdf59) drops the old client withself._client = Nonewithout closing it first, so the patch from #45693 should carry over almost unchanged. Fixes and features for it now belong in https://github.com/vectorize-io/hindsight (the plugin lives underhindsight-integrations/hermes) — please open it there. Closing here.