Fix #1915: fix(memos-local-plugin): bridge status detection misses hermes chat with global #1925
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1915: fix(memos-local-plugin): bridge status detection misses hermes chat with global #1925Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
`isHermesChatRunning()` in `bridge.cts` was using `pgrep -f "hermes chat"` as a literal substring, which only matched when those two tokens were adjacent on the process command line. The `hermes` CLI accepts global flags (`--skills`, `-m`, `--provider`) before the subcommand, so real invocations such as `hermes --skills memory-routing chat` showed up in `/proc/<pid>/cmdline` with arbitrary tokens between `hermes` and `chat` and were silently missed. In daemon mode this left `applyStaleRule()` permanently stuck on `"disconnected"` instead of upgrading to `"reconnecting"` (#1915). Extracted the pattern + helper into a new `bridge/hermes-process.ts` ESM module so it is unit-testable, and replaced the literal with the regex `hermes\s.*chat\b`. That covers the three documented invocation shapes -- `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. `bridge.cts` now imports the helper via the existing `runtimeModule()` / `importEsm()` machinery and passes it into `createBridgeStatusTracker` via DI, keeping the bridge surface identical (same `execFileSync("pgrep", ...)` call site). Verification: - `pnpm exec vitest run tests/unit/bridge/` -> 28 passed (13 new + 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, confirmed old literal pattern missed it and the new regex matched it. - Wider failures in `tests/unit/storage/{migrator,traces-count}` are pre-existing on the base branch (verified by stashing this diff and re-running) and unrelated. Stdio mode (the default Hermes provider / systemd path) is unchanged: it manages its own status via `markConnected` / `markDisconnected` and never calls `isHermesChatRunning`.
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (35/35 executed, 35 skipped). memos_local_plugin/smoke: 0/0, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s Branch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1915.
isHermesChatRunning()inapps/memos-local-plugin/bridge.ctswas usingpgrep -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 leftapplyStaleRule()permanently stuck on"disconnected"instead of upgrading to"reconnecting". Stdio mode was unaffected (it manages its own status viamarkConnected/markDisconnected).The pattern + helper were extracted into a new ESM module
apps/memos-local-plugin/bridge/hermes-process.ts, exportingHERMES_CHAT_PROCESS_PATTERN = "hermes\\s.*chat\\b", a JS-sidematchesHermesChatCommandLine(cmd)predicate, and anisHermesChatRunning(execFile?)wrapper with injectableexecFilefor testing.bridge.ctsnow loads the helper via the sameruntimeModule()/importEsm()machinery as its other dependencies and threads it intocreateBridgeStatusTrackervia DI. The new regex covershermes chat,hermes chat --…, andhermes --… chatwhile still rejectinghermesctl,hermes status, and unrelated processes thanks to the\sanchor and the\bword 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 chatprocess and confirmed the old literal pattern missed it while the new regex matched it. Two unit failures intests/unit/storage/{migrator,traces-count}.test.tswere confirmed pre-existing on the base branch (stashed this diff and re-ran) and are unrelated.Branch
bugfix/autodev-1915pushed to origin at commitccb369da. Reviewers @MatthewZhuang @CarltonXiang @syzsunshine219.Related Issue (Required): Fixes #1915
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.
Reviewer Checklist