fix(integrations): prevent Hermes bm mcp process leaks#1046
fix(integrations): prevent Hermes bm mcp process leaks#1046a-m-brewer-marve wants to merge 2 commits into
Conversation
Signed-off-by: a-m-brewer-marve <a-m-brewer-marve@users.noreply.github.com>
|
|
There was a problem hiding this comment.
💡 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".
| with _provider_singleton_lock: | ||
| if _provider_singleton is None: | ||
| _provider_singleton = BasicMemoryProvider() | ||
| _active_providers.append(_provider_singleton) | ||
| provider = _provider_singleton |
There was a problem hiding this comment.
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.
|
Thanks for the contribution. Two contributor gates are still blocking this PR:
Once both checks are green, maintainers can take over any remaining implementation changes needed to get this merged. |
|
Thank you for digging into the repeated Hermes initialization leak and for adding lifecycle tests—the diagnosis was useful. We have now merged #1059, which fixes #1017 by reusing the provider actor across repeated initialization while explicitly resetting per-session capture state and guaranteeing actor/thread/child-process cleanup on failed startup and shutdown. We chose that lifecycle-scoped approach instead of a process-wide provider singleton because the singleton could leak provider configuration and session state across independent registrations. Since the issue is now fixed and tested in the merged implementation, I am closing this PR as superseded. We appreciate the contribution. |
Summary
BasicMemoryProvidersingleton during Hermes plugin registration_BmMcpActorbefore provider reinitializationregister()and repeatedinitialize()lifecyclesWhy
Fixes/mitigates #1017. In long-running Hermes gateway/dashboard processes, repeated plugin registration or provider initialization can otherwise create multiple
bm mcpsubprocesses that stay alive and retain memory.Tests
uv run --with pytest pytest integrations/hermes/tests/test_provider.py integrations/hermes/tests/test_commands.py -quv run --with pytest pytest integrations/hermes/tests -quv run ruff check integrations/hermes/__init__.py integrations/hermes/tests/conftest.py integrations/hermes/tests/test_provider.pyuv run ruff format --check integrations/hermes/tests/conftest.py integrations/hermes/tests/test_provider.py