Repository navigation
Description
Description
When the Hermes gateway runs multiple concurrent sessions (email threads, cron jobs, subagents) in one process, each session gets its own MemTensorProvider instance. Every MemosBridgeClient() construction closes whatever client holds the per-process (agent, no_viewer, runtime_home) singleton slot in _ACTIVE_CLIENTS — which belongs to a different session's provider.
Root cause
The module-level singleton tracker _ACTIVE_CLIENTS in bridge_client.py was keyed by (agent, no_viewer, runtime_home) — one slot per process. This was correct as a guard against issue #1910 (bridge process leak where one provider kept spawning new bridges per turn), but fatal when N provider instances coexist in one gateway process.
Evidence chain:
- Gateway process hosts 2+
bridge.mjs --no-viewerchildren, replacing one every 2-3s (PIDs churn constantly) - Dashboard (single session, one provider) has one stable bridge, zero churn
- The only difference: provider-instance count
- Daemon (
bridge.cjs --daemon, systemd, :18800) stable throughout
Fix
Widen the singleton key to (agent, no_viewer, runtime_home, owner_id) so concurrent provider instances in one process coexist instead of fighting.
Changes:
- bridge_client.py: key type widened
tuple[str, bool, str]->tuple[str, bool, str, str];owner_id: str | Noneparameter added to__init__;_singleton_ownerfield set fromowner_id or f\"anon-{id(self)}\"; key construction in both_register_activeand_unregister_activeupdated - init.py: both construction sites (
initialize()and_reconnect_bridge()) in both shared-bridge and legacy modes passowner_id=f\"provider-{id(self)}\"
Expected steady state after fix: daemon + 1 bridge per host process = 3 total; reconnect counts -> ~0.
Alternatives
- HTTP transport (Feature request: native HTTP transport for MemosBridgeClient (remote bridge) #1985) — the architectural end-state, but needs more design
- Process-wide shared ref-counted client — one JSON-RPC per process, sessions multiplexed
Type of change
- Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
- Unit Test — the local test script verifies: distinct provider instances coexist in the tracker, same-owner replacement works, and unregister only removes self
- Living on production (kiwipaulrob's homelab) since 12 Aug 2026 — zero
bridge client is closedstorms since deployment (was thousands/day)
Checklist
- I have performed a self-review of my own code
- I have commented my code in hard-to-understand areas
- I have linked the issue to this PR (if applicable) — related: Bridge process leak: every turn spawns new bridge.cjs, 4+ processes accumulated #1910, fix: initialize() spawns new headless bridge without closing old one — process leak #1927, Feature request: native HTTP transport for MemosBridgeClient (remote bridge) #1985
Activity
Memtensor-AI commentedon Aug 27, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
5daf587c668e1502Working branch:
bugfix/autodev-2291-20260827191701124Target 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.
kiwipaulrob commentedon Aug 27, 2026
Superseded by PR #2292 — this was opened via the wrong API endpoint (issue instead of PR).
[-]fix(hermes-adapter): widen _ACTIVE_CLIENTS key with owner_id to prevent intra-process bridge fight[/-][+]Accidental issue — superseded by PR #2292[/+]fix(hermes-adapter): widen _ACTIVE_CLIENTS key with owner_id (MemTens…
Memtensor-AI commentedon Aug 27, 2026
✅ AutoDev task
5daf587c668e1502completed.Summary: Fixes #2291. Widens the module-level
_ACTIVE_CLIENTSkey inapps/memos-local-plugin/adapters/hermes/memos_provider/bridge_client.pyfrom(agent, no_viewer, runtime_home)to(agent, no_viewer, runtime_home, owner_id)so concurrentMemTensorProviderinstances in one Hermes gateway process (email threads, cron jobs, subagents) stop reaping each other's bridge subprocesses.Changes:
bridge_client.py: addsowner_id: str | None = NonetoMemosBridgeClient.__init__; storesself._singleton_owner = owner_id or f"anon-{id(self)}"; widens_ACTIVE_CLIENTStype annotation todict[tuple[str, bool, str, str], MemosBridgeClient];_register_active/_unregister_activebuild the four-tuple key.adapters/hermes/memos_provider/__init__.py: both provider construction sites (initialize()and_reconnect_bridge()) in shared and legacy bridge modes now passowner_id=f"provider-{id(self)}".tests/python/test_bridge_client.py: adds three regression tests — distinct owners coexist without displacement, same-owner replacement still reaps predecessor (preserves Bridge process leak: every turn spawns new bridge.cjs, 4+ processes accumulated #1910 guarantee), anonymous fallback yields unique keys per instance. Updates the two existing Bridge process leak: every turn spawns new bridge.cjs, 4+ processes accumulated #1910-era tests to pass explicit owner ids.Verification:
python3 -m unittest discover -s tests/python→ 126 tests pass, 0 failed, 0 errored. Full log excerpt: "Ran 126 tests in 17.707s — OK". No production tests removed; only two pre-existing #1910 unit tests widened to assert on the four-tuple key.Expected steady state after deploy: daemon + 1 bridge per host process = 3 total instead of 2 bridges churning every 2-3s; reconnect counts approach zero. Related history: #1910 (bridge process leak, now defended alongside #2291), #1927 (double-initialize), #1985 (HTTP transport, the eventual architectural end-state).
Base branch:
mainBranch:
bugfix/autodev-2291-20260827191701124Commit:
8dc5bf9PR: #2293
Assigned to: @Wang-Daoji
Reviewers: @WeiminLee