fix(memos-local-plugin): bridge status detection misses hermes chat with global flags
Description
In apps/memos-local-plugin/bridge.cts, the isHermesChatRunning() function uses pgrep -f "hermes chat" to detect whether a Hermes chat session is active. This pattern only matches when "hermes" and "chat" are adjacent tokens in the process command line.
However, the hermes CLI supports global flags that are placed before the subcommand. For example, the --skills flag (and others like -m, --provider) can be used either as chat-level flags:
hermes chat --skills memory-routing
or as global flags:
hermes --skills memory-routing chat
In the latter case, the process command line becomes:
/usr/local/lib/hermes-agent/venv/bin/hermes --skills memory-routing chat
The substring "hermes chat" does not appear contiguously here, so pgrep -f "hermes chat" returns no match even though a chat session is actively running.
Impact
This only affects the daemon mode bridge (--daemon flag), where applyStaleRule() uses isHermesChatRunning() to upgrade the status from "disconnected" to "reconnecting". The stdio mode (the default when started via memtensor provider or systemd) is not affected — it manages its own lifecycle via the stdio connection directly.
Suggested Fix
Replace the fixed-string pattern with a regex that allows optional flags between "hermes" and "chat":
- const out = childProcess.execFileSync("pgrep", ["-f", "hermes chat"], {
+ const out = childProcess.execFileSync("pgrep", ["-f", "hermes\\s.*chat\\b"], {
This pattern matches "hermes" followed by a whitespace character, then any characters (including flags), then "chat" at a word boundary. It covers both:
hermes chat(adjacent, no flags)hermes --skills memory-routing chat(global flags before subcommand)hermes chat --skills memory-routing(flags after subcommand, already matched by the original pattern)
The risk of false positives is minimal — matching a process that contains "hermes" and "chat" in unrelated positions on the same command line is unlikely in practice.
Environment
- Hermes Agent: any version supporting global flags before subcommands
- memos-local-plugin: any version (confirmed in v2.0.19 / npm v2.0.7)
- Platform: Linux (Ubuntu/Debian based)
hey can i work on this issue?
🤖 AutoDev has picked up this issue and started working on it.
Task ID: 0ab7858ed9b05e2b
Working branch: bugfix/autodev-1915
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.
✅ AutoDev task 0ab7858ed9b05e2b completed.
Summary: Fixes #1915. isHermesChatRunning() in apps/memos-local-plugin/bridge.cts was using pgrep -f "hermes chat" as a literal substring, so it silently missed any session launched with global flags before the subcommand (e.g. hermes --skills memory-routing chat). In daemon mode this left applyStaleRule() permanently stuck on "disconnected" instead of upgrading to "reconnecting". Stdio mode was unaffected (it manages its own status via markConnected / markDisconnected).
The pattern + helper were extracted into a new ESM module apps/memos-local-plugin/bridge/hermes-process.ts, exporting HERMES_CHAT_PROCESS_PATTERN = "hermes\\s.*chat\\b", a JS-side matchesHermesChatCommandLine(cmd) predicate, and an isHermesChatRunning(execFile?) wrapper with injectable execFile for testing. bridge.cts now loads the helper via the same runtimeModule() / importEsm() machinery as its other dependencies and threads it into createBridgeStatusTracker via DI. The new regex covers hermes chat, hermes chat --…, and hermes --… chat while still rejecting hermesctl, hermes status, and unrelated processes thanks to the \s anchor and the \b word boundary.
Verification: pnpm exec vitest run tests/unit/bridge/ → 28 passed (13 new regex / pgrep-wrapper assertions + 15 existing methods/stdio); pnpm run lint (tsc --noEmit) → exit 0; live-fire on Linux spawned a fake /usr/local/bin/hermes --skills memory-routing chat process and confirmed the old literal pattern missed it while the new regex matched it. Two unit failures in tests/unit/storage/{migrator,traces-count}.test.ts were confirmed pre-existing on the base branch (stashed this diff and re-ran) and are unrelated.
Branch bugfix/autodev-1915 pushed to origin at commit ccb369da. Reviewers @MatthewZhuang @CarltonXiang @syzsunshine219.
Base branch: main
Branch: bugfix/autodev-1915
Commit: ccb369d
PR: https://github.com/MemTensor/MemOS/pull/1925
Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219
Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219