fix(memos-local-plugin): use POSIX-ERE-compatible pgrep pattern for hermes chat detection - #2192
fix(memos-local-plugin): use POSIX-ERE-compatible pgrep pattern for hermes chat detection#2192kiwipaulrob wants to merge 1 commit into
Conversation
…ermes chat detection The MemTensor#1915 pattern used `(?:\s+\S+)*` — a PCRE non-capturing group. `pgrep -f` on Linux compiles patterns with glibc's POSIX ERE, which has no non-capturing groups, so every call failed with: pgrep: regex error: Invalid preceding regular expression `isHermesChatRunning()` swallows the error and returns `false`, so the daemon viewer was permanently stuck on "disconnected" even with a `hermes chat` session attached. The JS unit test passed because JavaScript RegExp accepts `(?:…)` — the proxy was not faithful for ERE. Replace the non-capturing group with a plain capturing group `(\s+\S+)*`, which is valid in both POSIX ERE and JavaScript RegExp, and update the doc comment to warn that the pattern must stay within ERE. Add a regression test that runs the real `pgrep` binary and asserts it does not exit 2 (regex syntax error), so a PCRE-ism can never silently return.
🤖 Open Code ReviewTarget: PR #2192 ✅ OpenCodeReview: No comments generated. Looks good to me. Generated by cloud-assistant via Open Code Review. |
|
|
Thanks for running the checks. A quick note on the AutoTest result: This failure is an environment-preparation issue, not a test failure. The report states "Environment preparation failed before any gating tests executed" — the runner never reached the memos_local_plugin test suite, so there is no test result from this run to act on. For reference, here's what does validate this change:
Could the AutoTest environment be re-run when convenient (or is there a known issue with environment prep for the |
Summary
Fixes the Hermes chat process detection regex in the memos-local-plugin. The pattern introduced to fix #1915 used
(?:\s+\S+)*— a PCRE non-capturing group — butpgrep -fon Linux compiles patterns with glibc's POSIX ERE, which has no non-capturing groups. Every call failed with:isHermesChatRunning()swallows the error and returnsfalse, so the daemon-mode bridge viewer was permanently stuck on"disconnected"even when ahermes chatsession was attached — exactly the symptom #1915 set out to fix.Root cause
The unit test for the pattern passes
matchesHermesChatCommandLine()through JavaScript'sRegExp, which does support(?:…). The comment claimed this was a "faithful proxy" for the pgrep side — but the two engines are not equivalent for non-capturing groups. The proxy was faithful for matching behaviour, not for pattern validity.Fix
(\s+\S+)*, which is valid in both POSIX ERE and JavaScript'sRegExpand behaves identically for matching.(?:…)), so the constraint is visible at the constant's definition.pgrepbinary with the pattern and asserts it does not exit 2 (regex syntax error), so a PCRE-ism can never silently return again. Verified: the old pattern exits 2 with this test; the fixed pattern passes.Verification
vitest run tests/unit/bridge/hermes-process.test.ts— 15/15 tests pass (all existing match cases unchanged, plus the new pgrep regression test).pgrepexit 2 +Invalid preceding regular expression; fixed pattern → exit 0/1, no error, and the bridge status upgrades to"connected".Notes
dist/is gitignored, so only the TS source and its test are touched.dev-v2.0.x) if that's preferred for this fix.