You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bridge process leak: every turn spawns new bridge.cjs, 4+ processes accumulated #1910
Every conversation turn spawns a new bridge.cjs --agent=hermes --no-viewer process. Old processes are not cleaned up. Over a session, 4+ bridge processes accumulate:
The newest process has grown to 343MB RSS. Over longer sessions with many turns, this would lead to significant memory pressure (especially on 16GB macOS devices already constrained by 26.5.1 resource limits).
Expected behavior
Bridge should be initialized once per session, with subsequent turns reusing the existing connection. Or at minimum, old bridge processes should be cleaned up when a new one spawns.
Note
This may be related to NousResearch/hermes-agent#20939 which reports the same symptom from the Hermes side: "MemOS memory provider spawns new bridge.cts process on every single turn."
Impact
Memory leak: each process consumes 70-340MB RSS
On long-running sessions (50+ turns), this could consume 3-10GB of RAM
macOS 26.5.1 already imposes disk write limits; memory pressure from leaked processes compounds this
Adapter side (this repo): the bridge subprocess is owned per provider instance with nothing enforcing the one-bridge-per-process invariant, and three reference legs make abandoned instances immortal: (a) bound-method hooks appended to the host's global plugin manager and never removed, (b) a per-instance keepalive thread that never stops — and even resurrects the bridge if you kill -9 it (verified: killed pid, new bridge respawned within one 5s cycle), (c) reader thread ↔ Popen stdin pipe pinning each other so GC can never trigger stdin-EOF exit. Also initialize() doesn't close an existing self._bridge, so re-init leaks too.
Deterministic repro (real unmodified adapter, stub bridge with identical lifecycle semantics): 3 abandoned provider instances → exactly 4 live --no-viewer processes, matching the ps output in this report.
Fix direction (defense on the adapter side, independent of host behavior): promote the bridge client to a process-wide shared resource (refcounted module-level singleton — the JSON-RPC protocol is already multi-session), single keepalive bound to the shared client, hook registration deduped at process level and unregistered on shutdown, idempotent initialize().
Summary: Fixes #1910: bridge.cjs process leak in @memtensor/memos-local-plugin Hermes adapter where every conversation turn spawned a new bridge.cjs --agent=hermes --no-viewer subprocess without reaping the previous one, accumulating 4+ processes per session (RSS up to ~340 MB each). Linked symptom on Hermes side: NousResearch/hermes-agent#20939.
Applied three layered defenses so at most one live stdio bridge exists per agent:
(1) bridge_client.py adds a module-level _ACTIVE_CLIENTS singleton tracker keyed by (agent, no_viewer). MemosBridgeClient.__init__ synchronously closes any displaced predecessor; close() only evicts the slot when it is still the current owner, so late closes on stale clients never knock out their replacement.
(2) MemTensorProvider.initialize() is now idempotent: it closes any pre-existing self._bridge before respawning, eliminating the orphan-leak path when the host re-enters initialize on the same instance.
(3) bridge.cts extends the existing PID-file singleton (#1765) to cover --no-viewer mode via a dedicated bridge-stdio.pid file, separate from the viewer-port owner's bridge.pid so the two paths never collide. Defense in depth across Python processes; activates after dist/ rebuild.
Verification: 4 new pytest cases (same-agent reap, distinct-agent isolation, stale-close non-eviction, provider idempotency); full unit suite python3 -m unittest test_bridge_client test_hermes_provider_pipeline runs 46 tests, all pass. ruff check and ruff format are clean across the touched files.
Activity
fancyboi999 commentedon Jun 12, 2026
I've reproduced this locally and traced the root cause — claiming this one, fix PR incoming.
TL;DR: accumulation of live
--no-viewerbridges = multiple liveMemosBridgeClientinstances in the Hermes host process. Two compounding sides:load_memory_provider()constructs a freshMemTensorProvideron every call — module is cached, instance is not), and the abandoned fork never callsshutdown().oneshot.pystill lacksskip_memory=Truetoday.kill -9it (verified: killed pid, new bridge respawned within one 5s cycle), (c) reader thread ↔ Popen stdin pipe pinning each other so GC can never trigger stdin-EOF exit. Alsoinitialize()doesn't close an existingself._bridge, so re-init leaks too.Deterministic repro (real unmodified adapter, stub bridge with identical lifecycle semantics): 3 abandoned provider instances → exactly 4 live
--no-viewerprocesses, matching the ps output in this report.Fix direction (defense on the adapter side, independent of host behavior): promote the bridge client to a process-wide shared resource (refcounted module-level singleton — the JSON-RPC protocol is already multi-session), single keepalive bound to the shared client, hook registration deduped at process level and unregistered on shutdown, idempotent
initialize().fix(hermes-adapter): read singular traceId from turn.end per core con…
fix(hermes-adapter): stop bridge subprocess leak by sharing one clien…
fix(hermes-adapter): read singular traceId from turn.end per core con…
Memtensor-AI commentedon Jun 15, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
dba10126f96caab2Working branch:
bugfix/autodev-1910Target branch:
latest dev* branchWorkflow: opsp (analysis → coding → testing → PR)
I will post the PR link here once done. If I need more information, I will ask in the comments.
fix(memos-local-plugin): close previous bridge before spawning a new …
Memtensor-AI commentedon Jun 15, 2026
✅ AutoDev task
dba10126f96caab2completed.Summary: Fixes #1910: bridge.cjs process leak in @memtensor/memos-local-plugin Hermes adapter where every conversation turn spawned a new
bridge.cjs --agent=hermes --no-viewersubprocess without reaping the previous one, accumulating 4+ processes per session (RSS up to ~340 MB each). Linked symptom on Hermes side: NousResearch/hermes-agent#20939.Applied three layered defenses so at most one live stdio bridge exists per agent:
(1)
bridge_client.pyadds a module-level_ACTIVE_CLIENTSsingleton tracker keyed by(agent, no_viewer).MemosBridgeClient.__init__synchronously closes any displaced predecessor;close()only evicts the slot when it is still the current owner, so late closes on stale clients never knock out their replacement.(2)
MemTensorProvider.initialize()is now idempotent: it closes any pre-existingself._bridgebefore respawning, eliminating the orphan-leak path when the host re-enters initialize on the same instance.(3)
bridge.ctsextends the existing PID-file singleton (#1765) to cover--no-viewermode via a dedicatedbridge-stdio.pidfile, separate from the viewer-port owner'sbridge.pidso the two paths never collide. Defense in depth across Python processes; activates afterdist/rebuild.Verification: 4 new pytest cases (same-agent reap, distinct-agent isolation, stale-close non-eviction, provider idempotency); full unit suite
python3 -m unittest test_bridge_client test_hermes_provider_pipelineruns 46 tests, all pass.ruff checkandruff formatare clean across the touched files.Base branch:
mainBranch:
bugfix/autodev-1910Commit:
f37d223PR: #1922
Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219
Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219
Fix #1910: Bridge process leak: every turn spawns new bridge.cjs, 4+ …
Fix #1910: Bridge process leak: every turn spawns new bridge.cjs, 4+ … (
fix(hermes-adapter): widen _ACTIVE_CLIENTS key with owner_id (MemTens…
fix(hermes-adapter): warn on anonymous owner_id and tighten singleton…
Fix MemTensor#1910: Bridge process leak: every turn spawns new bridge…