Repository navigation
Description
Summary
daemon_manager.py's ensure_bridge_running(probe_only=True) caches _bridge_ok as a module-level global with no expiry mechanism. Once set to False by a transient failure (subprocess creation race, env-var load ordering), it stays False for the lifetime of the gateway process. This causes MemTensorProvider.is_available() to return False permanently, and agent_init.py skips adding the provider — MemOS is silently disabled despite the bridge daemon being perfectly healthy.
Root Cause
In adapters/hermes/memos_provider/daemon_manager.py, the caching logic at lines 130–133:
if _bridge_ok is not None and probe_only:
return _bridge_ok # ← returns stale False foreverThe sequence that triggers the bug:
- Hermes gateway starts, loads
.env(which setsMEMOS_NODE_BINARY) agent_init.pycallsis_available()→ensure_bridge_running(probe_only=True)- If
_node_available()fails at this moment (e.g. transient subprocess error on Windows, or.envnot yet loaded inos.environ),_bridge_okis set toFalse - Meanwhile
ensure_viewer_daemon()(called duringinitialize()withoutprobe_only) finds the bridge already running on port 18800 via_probe_viewer()and returnsTrue— without ever callingensure_bridge_running()again, so_bridge_okstaysFalseforever is_available()returnsFalse→agent_init.py:994skipsadd_provider()→ MemOS offline for the gateway's lifetime
Symptoms
- Repeated
"MemOS: Node.js not found on PATH"warnings in logs (from non-session contexts, no session ID prefix) - Bridge health endpoint (
/api/v1/health) showsllm.available: trueandembedder.available: true - But
bridge_clientnever logs any activity — the provider was never registered hermes doctorshows memtensor as unavailable
Proposed Fix
Three changes to daemon_manager.py, ~20 lines net new code:
1. TTL-based cache expiry
Add _bridge_ok_at: float = 0.0 timestamp and BRIDGE_OK_TTL_SEC = 60.0. Cached results expire after 60 seconds, forcing revalidation.
2. Running-bridge fallback
When _node_available() fails, check whether a bridge is already alive via _probe_viewer() == "running_memos". A live bridge process is definitive proof the environment is viable (the bridge itself was launched with Node.js).
3. shutdown_bridge() resets both variables
Fixed ensure_bridge_running:
def ensure_bridge_running(*, probe_only: bool = False) -> bool:
global _bridge_ok, _bridge_ok_at
with _lock:
now = time.time()
if _bridge_ok is not None and probe_only:
if (now - _bridge_ok_at) < BRIDGE_OK_TTL_SEC:
return _bridge_ok
# Cache expired — fall through to revalidate.
script = _bridge_script()
if not script.exists():
logger.warning("MemOS: bridge script missing at %s", script)
_bridge_ok = False
_bridge_ok_at = now
return False
if _node_available():
_bridge_ok = True
_bridge_ok_at = now
return True
# Node binary check failed. Check if bridge is already running.
if _probe_viewer() == "running_memos":
_bridge_ok = True
_bridge_ok_at = now
return True
logger.warning("MemOS: Node.js not found on PATH")
_bridge_ok = False
_bridge_ok_at = now
return FalseEnvironment
- MemOS version: 2.0.5 (
@memtensor/memos-local-plugin) - Hermes Agent on Windows 10
- Node.js v24.14.1 (path set via
MEMOS_NODE_BINARYin.env)
Notes
Happy to submit a PR if this direction looks right. The fix has been tested on Windows — syntax verified, logic tested with fresh import.
Activity
Memtensor-AI commentedon Jun 30, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
0c949574dc352cffWorking branch:
bugfix/autodev-1797Target 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(hermes): expire _bridge_ok cache so MemTensorProvider self-heals
Memtensor-AI commentedon Jun 30, 2026
✅ AutoDev task
0c949574dc352cffcompleted.Summary: Fixes #1797:
_bridge_okcache inapps/memos-local-plugin/adapters/hermes/memos_provider/daemon_manager.pyhad no expiry, so a single transient_node_available()failure during Hermes gateway startup permanently disabledMemTensorProvider. The cache now expires after 60 seconds, and_node_available()failures fall through to a_probe_viewer()check that accepts an already-running MemOS bridge on :18800 as proof the environment is viable.shutdown_bridge()also resets the new_bridge_ok_attimestamp.Added regression tests (
BridgeOkCacheTests, 6 cases) covering cold-start revalidation, cache-hit short-circuit within TTL, TTL-expiry recovery, running-bridge fallback, shutdown reset, and full-call (non-probe) revalidation. Full plugin python suite green: 48 passed (42 existing + 6 new). Ruff lint and format both clean. Branchbugfix/autodev-1797pushed toorigin; openspec artifacts archived tomemos-autodev-specs.Base branch:
mainBranch:
bugfix/autodev-1797Commit:
72f1756PR: #2001
Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
Memtensor-AI commentedon Jul 1, 2026
❌ AutoDev task
0c949574dc352cfffailed.Summary: Claude Code 未通过 submit_result 工具提交结果,且无文本输出
Error: Claude SDK stream ended without invoking submit_result and without producing any text
Fix #1797: bug(hermes): _bridge_ok cache permanently disables provide…
Fix MemTensor#1797: bug(hermes): _bridge_ok cache permanently disable…