MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

Hermes adapter: viewer daemon dies silently mid-session, never re-spawned (2.0.20)

Open rayraiser opened this issue 1 month ago • 5 comments

Hermes adapter: viewer daemon (:18800) dies silently mid-session and is never re-spawned

Plugin: @memtensor/memos-local-plugin v2.0.20 (adapter: Hermes)

Behavior

The Hermes viewer daemon (the standalone --daemon bridge owning :18800) is only guaranteed to start at gateway startup / first shared-bridge spawn. Once it dies while the gateway process is alive, nothing re-launches it. In our case the daemon received SIGTERM and the viewer stayed down for ~72 hours while all memory functionality (stdio chat bridges) kept working normally — so nothing upstream of the viewer detected the outage.

Observed lifecycle (times redacted; only the sequence is what matters):

T0        daemon started (plugin update flow)
T0 + 8m   SIGTERM -> re-spawned (update flow)
T1        SIGTERM (gateway restart)
T1 + 4m   re-spawned (first agent session after restart)
...       further re-spawns tied to session/gateway events, viewer healthy
T2        SIGTERM during an active agent task (bridge singleton kill)
          -> no re-spawn ever; viewer dead for ~72h until manual fix

Root cause (as I read the code)

ensure_viewer_daemon() is invoked solely from _prepare_shared_bridge(), which is wired as the before_spawn callback of SHARED_BRIDGE_REGISTRY.acquire(...). Within a single gateway process lifetime the registry only ever spawns once, so before_spawn (and the daemon probe/launch) executes once per gateway lifetime. The running_memos -> return True probe is correct for the "don't re-launch if alive" direction; the defect is that after the first spawn, a dead daemon is never re-probed — the check does not happen on subsequent acquire() / session reconnects.

Also relevant: the bridge's PID-file singleton logic lets a newly spawned viewer-owning bridge SIGTERM the previous holder. When that happens mid-session, the "replacement" does not outlive the spawning context, leaving port 18800 ownerless with no recovery mechanism.

Suggested fixes (any one of these closes it)

  • Run the ensure_viewer_daemon probe on every acquire()/reconnect, not only on first spawn (cheap: it's a port probe).
  • Or: give the daemon its own supervisor (systemd unit / watchdog) with an auto-restart, decoupled from the gateway process.
  • Or at least: log a loud, repeated MemOS: viewer daemon missing when a session opens against a dead daemon, so the outage is observable.

Workaround we used

A 10-minute cron watchdog that two-stage probes :18800 and re-spawns the daemon if it stays dead for 60s. Happy to share the script if useful.

rayraiser avatar Oct 28 '26 08:10 rayraiser

🤖 AutoDev has picked up this issue and started working on it.

Task ID: 169ab3faf77a43d3 Working branch: bugfix/autodev-2546-20261028081837820 Target branch: latest dev* branch Workflow: 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.

Memtensor-AI avatar Oct 28 '26 08:10 Memtensor-AI

🤔 AutoDev task 169ab3faf77a43d3 needs clarification to proceed: The execution budget, service interruption or model failure stopped this attempt. Continue from the saved workspace and session? The suggested default is only used if a maintainer explicitly confirms it. Please reply with one of the following commands (only issue author or repo collaborators):

  • /autodev confirm yes — agree and continue with the suggested default assumption
  • /autodev confirm no <additional info> — provide more details
  • /autodev cancel — cancel this task If there is no reply within 24h, AutoDev will cancel this task using the same outcome as /autodev cancel. It will not continue with the suggested default automatically.

Memtensor-AI avatar Oct 28 '26 08:10 Memtensor-AI

⏰ AutoDev task 169ab3faf77a43d3 received no /autodev confirm reply within 24h. AutoDev cancelled this task using the same outcome as /autodev cancel; it will not continue with the suggested default automatically.

Memtensor-AI avatar Oct 29 '26 08:10 Memtensor-AI

/autodev confirm yes

rayraiser avatar Oct 30 '26 14:10 rayraiser

I reproduced the missed viewer check on the current Hermes Python adapter (identical on main and dev-v2.0.36): after the first provider starts, both explicit and lazy acquisition of a second session reuse the healthy stdio bridge without calling ensure_viewer_daemon again.

Would you accept a focused contribution from @PeaceMaker-best for this issue and assign it to me? I see that the previous AutoDev attempt was cancelled and found no open PR for #2546. I have prepared an AI-assisted local patch and offline tests; no PR has been published.

Proposed scope:

  • Recheck the independent viewer daemon when an explicit or lazy session acquires the shared bridge, retaining the existing daemon manager's probe/start locking and port ownership checks.
  • Keep an unavailable viewer non-fatal for memory capture; do not restart a healthy stdio bridge or reap other data homes.
  • Cover viewer exit followed by reacquisition, false/exceptional viewer checks, bridge reuse, and the captured runtime home. The Python adapter suite passes locally (135 tests); the two new reacquisition regressions fail against the original code.

This is recovery at the next session acquisition, not a periodic watchdog. I plan to target dev-v2.0.36; please let me know if you prefer another base or a different recovery boundary.

PeaceMaker-best avatar Nov 04 '26 08:11 PeaceMaker-best