Skip to content

fix(integrations): prevent Hermes bm mcp process leaks#1046

Open
a-m-brewer-marve wants to merge 2 commits into
basicmachines-co:mainfrom
marve-net:marve/hermes-bm-mcp-leak-fix
Open

fix(integrations): prevent Hermes bm mcp process leaks#1046
a-m-brewer-marve wants to merge 2 commits into
basicmachines-co:mainfrom
marve-net:marve/hermes-bm-mcp-leak-fix

Conversation

@a-m-brewer-marve

Copy link
Copy Markdown

Summary

  • reuse a process-local BasicMemoryProvider singleton during Hermes plugin registration
  • shut down any existing _BmMcpActor before provider reinitialization
  • add regression tests for repeated register() and repeated initialize() lifecycles

Why

Fixes/mitigates #1017. In long-running Hermes gateway/dashboard processes, repeated plugin registration or provider initialization can otherwise create multiple bm mcp subprocesses that stay alive and retain memory.

Tests

  • uv run --with pytest pytest integrations/hermes/tests/test_provider.py integrations/hermes/tests/test_commands.py -q
  • uv run --with pytest pytest integrations/hermes/tests -q
  • uv run ruff check integrations/hermes/__init__.py integrations/hermes/tests/conftest.py integrations/hermes/tests/test_provider.py
  • uv run ruff format --check integrations/hermes/tests/conftest.py integrations/hermes/tests/test_provider.py

Signed-off-by: a-m-brewer-marve <a-m-brewer-marve@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 320f6c68ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1851 to +1855
with _provider_singleton_lock:
if _provider_singleton is None:
_provider_singleton = BasicMemoryProvider()
_active_providers.append(_provider_singleton)
provider = _provider_singleton

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reset per-session state before reusing the singleton

When Hermes starts another session in the same process, this singleton can be initialized again after the prior session has captured turns. shutdown() only clears _actor and _initialized, while _session_note_id and _first_user_msg remain set; the next session's first sync_turn() will therefore take the append path in _capture_turn() and write into the previous session transcript, and its summary can link/use the previous session state. Please clear the session-scoped fields when reusing the provider for a new session.

Useful? React with 👍 / 👎.

Reset _session_note_id, _first_user_msg, _session_started_at, and _session_id
when the provider is cleaned up so reusing a singleton across sessions does not
append to the previous session transcript or lose the opening message.

Addresses Codex review on PR basicmachines-co#1046.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants