hermes - 💡(How to fix) Fix [Bug]: Hindsight still leaks aiohttp ClientSession/connector after fix #4762 [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11923Fetched 2026-04-18 05:58:12
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
commented ×1

Error Message

if self._client is not None: try: if self._mode == "local_embedded": try: self._client.close() except RuntimeError: pass else: _run_sync(self._client.aclose()) except Exception: pass self._client = None

Fix Action

Fix / Workaround

Bug Description

The Hindsight memory integration still emits aiohttp resource-leak warnings in a long-running Hermes gateway process even after the earlier Hindsight fix from PR #4762 (fix(hindsight): correct client constructor, add configurable base_url, and fix sequential tool dispatch).

Additional Context

This looks like a follow-up / regression gap after PR #4762 rather than a brand-new issue. The previous repair addressed constructor/base_url/dispatch problems, but not the persistent aiohttp session cleanup problem.

Code Example

ERROR asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x...>
ERROR asyncio: Unclosed connector
connector: <aiohttp.connector.TCPConnector object at 0x...>

---

if self._client is not None:
    try:
        if self._mode == "local_embedded":
            try:
                self._client.close()
            except RuntimeError:
                pass
        else:
            _run_sync(self._client.aclose())
    except Exception:
        pass
    self._client = None

---

ERROR asyncio: Unclosed client session
ERROR asyncio: Unclosed connector

---

INFO plugins.memory.hindsight: Hindsight initialized: mode=cloud, api_url=http://YOUR_HINDSIGHT_HOST:8888, bank=main_hermes, budget=mid, memory_mode=hybrid, prefetch_method=recall, client=0.5.0
ERROR asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x...>
ERROR asyncio: Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x...>, ...)])']
connector: <aiohttp.connector.TCPConnector object at 0x...>
RAW_BUFFERClick to expand / collapse

Bug Description

The Hindsight memory integration still emits aiohttp resource-leak warnings in a long-running Hermes gateway process even after the earlier Hindsight fix from PR #4762 (fix(hindsight): correct client constructor, add configurable base_url, and fix sequential tool dispatch).

The previous fix improved the plugin, but it did not eliminate the underlying Unclosed client session / Unclosed connector problem.

Symptoms

Observed repeatedly in gateway logs:

ERROR asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x...>
ERROR asyncio: Unclosed connector
connector: <aiohttp.connector.TCPConnector object at 0x...>

Why this looks unresolved

The Hindsight plugin now has shutdown cleanup logic that calls self._client.aclose() during provider teardown, but the warnings still occur during normal runtime in the gateway logs, not only at final process shutdown.

Relevant code path in plugins/memory/hindsight/__init__.py:

if self._client is not None:
    try:
        if self._mode == "local_embedded":
            try:
                self._client.close()
            except RuntimeError:
                pass
        else:
            _run_sync(self._client.aclose())
    except Exception:
        pass
    self._client = None

That suggests one of these is still happening:

  1. A client/session is created outside the lifecycle covered by provider shutdown.
  2. The async client owns an aiohttp session that is not being fully closed in all paths.
  3. The shared background loop / cleanup timing still leaves transport resources orphaned.
  4. The leak happens during repeated memory operations in a long-running process, so shutdown cleanup is too late to prevent runtime warnings.

Steps to Reproduce

  1. Configure Hermes to use the Hindsight memory provider.
  2. Run the gateway as a long-lived process.
  3. Trigger memory activity (for example: normal chat flow with memory prefetch, or direct hindsight_recall / hindsight_reflect / hindsight_retain usage).
  4. Check gateway logs.

Expected Behavior

No aiohttp resource leak warnings should appear during normal operation.

Actual Behavior

Gateway logs still show:

ERROR asyncio: Unclosed client session
ERROR asyncio: Unclosed connector

Sanitized Evidence

Example sanitized log sequence:

INFO plugins.memory.hindsight: Hindsight initialized: mode=cloud, api_url=http://YOUR_HINDSIGHT_HOST:8888, bank=main_hermes, budget=mid, memory_mode=hybrid, prefetch_method=recall, client=0.5.0
ERROR asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x...>
ERROR asyncio: Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x...>, ...)])']
connector: <aiohttp.connector.TCPConnector object at 0x...>

This was observed multiple times across separate runtime windows, not as a one-off shutdown-only warning.

Environment

  • Hermes Agent: current local deployment (exact upstream commit not verified before filing)
  • Memory provider: Hindsight
  • Hindsight client version reported by logs: 0.5.0
  • Hindsight mode: cloud / external server
  • Python runtime: long-running gateway process

Additional Context

This looks like a follow-up / regression gap after PR #4762 rather than a brand-new issue. The previous repair addressed constructor/base_url/dispatch problems, but not the persistent aiohttp session cleanup problem.

It may be worth auditing:

  • all Hindsight client creation sites,
  • whether one Hindsight instance internally owns multiple async sessions,
  • whether cleanup happens on the same event loop that created the underlying resources,
  • whether per-call temporary sessions survive even when the top-level client is reused.

extent analysis

TL;DR

The Hindsight memory integration issue can be addressed by ensuring proper cleanup of aiohttp client sessions and connectors, potentially by auditing client creation sites and implementing robust shutdown logic.

Guidance

  • Review the Hindsight client creation process to ensure that all sessions are properly closed, focusing on the cloud mode and external server configuration.
  • Verify that the self._client.aclose() call in the __init__.py file is executed on the same event loop that created the underlying resources to prevent transport resources from being orphaned.
  • Investigate whether the Hindsight instance internally owns multiple async sessions and ensure that all sessions are properly cleaned up during shutdown.
  • Consider implementing a try-except-finally block to guarantee that self._client is set to None after cleanup, even if an exception occurs.

Example

try:
    # ...
finally:
    if self._client is not None:
        try:
            _run_sync(self._client.aclose())
        except Exception:
            pass
        self._client = None

Notes

The issue may be related to the shared background loop and cleanup timing, which could leave transport resources orphaned. Further investigation is needed to determine the root cause.

Recommendation

Apply a workaround by auditing the Hindsight client creation sites and implementing robust shutdown logic to ensure proper cleanup of aiohttp client sessions and connectors. This approach is recommended because it addresses the potential root cause of the issue and provides a clear path forward for resolving the problem.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [Bug]: Hindsight still leaks aiohttp ClientSession/connector after fix #4762 [1 comments, 2 participants]