Repository navigation
Description
Bug Description
Every Hermes Agent session that uses the basic-memory memory provider spawns its own bm mcp subprocess.
In multi-session environments (gateway with slash_worker subprocesses), each worker creates its own agent → loads the basic-memory plugin → calls BasicMemoryProvider.initialize() → creates a new _BmMcpActor → spawns a fresh bm mcp. When workers exit (e.g. SIGTERM during gateway restart), the bm mcp child processes are orphaned and accumulate.
Observed on a production instance: 18 orphaned bm mcp processes using ~2.3 GB RSS on a 3.7 GB machine.
Steps To Reproduce
- Install Hermes Agent with
memory.provider: basic-memory - Run the gateway in an environment with multiple sessions or slash commands
- Each
_SlashWorkeris asubprocess.Popenchild of the dashboard. Each callsload_memory_provider()→register()→BasicMemoryProvider()→initialize()→_BmMcpActor(argv).start()→bm mcpsubprocess - Kill sessions via gateway restart (SIGTERM) — the child
bm mcpprocesses outlive their parentslash_worker - Repeat steps 2–4
ps auxshows orphanedbm mcpprocesses accumulating
Expected Behavior
bm mcp subprocesses should be cleaned up when their spawning Hermes session ends. One bm mcp per process, not one per session.
Actual Behavior
BasicMemoryProvider.initialize() creates a new actor every call with no guard against duplicates:
# Lines 873-875 — no guard
actor = _BmMcpActor(argv)
actor.start(timeout=25.0)
self._actor = actor_BmMcpActor.start() DOES have an internal guard (if self._thread and self._thread.is_alive(): return), but since a new _BmMcpActor instance is created each time, this guard never triggers.
When _SlashWorker processes are killed (e.g. SIGTERM during gateway restart), their bm mcp children become orphaned. The atexit cleanup at line 1819 (_atexit_cleanup() → p.shutdown()) cannot run because Python's atexit handlers don't fire on SIGTERM.
Logs show repeated bm mcp spawns until memory exhaustion:
ERROR hermes.memory.basic-memory: basic-memory: MCP server failed to start:
basic-memory MCP server didn't initialize within 25.0s
Environment
- OS: Linux 5.15.0-generic (containerized)
- Python version: 3.13.5
- Basic Memory version: 0.22.1
- Installation method:
uv tool install basic-memory - Hermes Agent version: v0.17.0 (2026.6.19)
Additional Context
Process list showing the accumulation (all PPID=114 = dashboard):
PID ELAPSED RSS PPID CMD
218 23m 50MB 114 bm mcp
387 21m 50MB 114 bm mcp
406 21m 50MB 114 bm mcp
730 19m 50MB 114 bm mcp
...
3614 4m 454MB 114 bm mcp
---
18 processes, 2309MB RSS
Most processes sit at ~50 MB RSS (idle Python). The largest ones (~454 MB) are actively doing embedding work — the model is loaded per-process.
Possible Solution
The clearest actionable fix: add a guard in initialize() to prevent creating a duplicate actor on the same provider instance. If self._actor is already alive, reuse it rather than spawning a new bm mcp.
A module-level singleton (_shared_actor) would help when multiple BasicMemoryProvider instances exist within the same process (e.g. the dashboard calling load_memory_provider() multiple times). But it would NOT solve the gateway scenario — each _SlashWorker is a separate OS process, each with its own BasicMemoryProvider instance.
The real fix for gateway scenarios: _SlashWorker.close() currently kills only the worker process itself. The orphaned bm mcp grandchildren survive. Using os.killpg or prctl(PR_SET_PDEATHSIG, SIGTERM) on the spawned bm mcp process would ensure children die when the worker dies, preventing accumulation.
See _SlashWorker (tui_gateway/server.py line 304) for the cleanup path.
Activity
phernandez commentedon Jul 15, 2026
Thanks for the exceptionally detailed report — it holds up against current main (nothing in
integrations/hermeshas changed since you filed). Confirmed both parts:initialize()allocates a fresh_BmMcpActoron every call and overwritesself._actorwithout shutting the previous one down, so the internalstart()guard never helps; and cleanup is only registered viaatexit, which doesn't run on SIGTERM, so gateway restarts orphan thebm mcpchildren.Plan on our side: a reuse/duplicate guard in
initialize()plus a SIGTERM hook into the existing shutdown path so children get reaped on restart. The process-group death-link you suggested (os.killpg/PR_SET_PDEATHSIG) really belongs in the Hermes Agent gateway's_SlashWorker.close(), which lives in the hermes-agent repo — that half deserves an upstream issue, since the MCP SDK's spawn point here exposes no hook for it.fix(integrations): reap bm mcp child when SIGTERM or failure lands mi…