fix(bridge): use os.homedir() for PID file path so Windows stops creating <drive>:\tmp stray folders - #2225
Conversation
process.env.HOME is not set on Windows (USERPROFILE is used instead), so pidFilePath() fell back to '/tmp' which Node resolves relative to the current drive root. Every bridge/daemon start on Windows then created a stray <drive>:\tmp\.hermes\memos-plugin\daemon\bridge.pid folder on whichever drive the process happened to run from, and the singleton guard could not see PID files written from other drives (e.g. install.ps1 from D: vs daemon_manager from C:), allowing multiple daemons to fight over the viewer port. Replace the fallback with os.homedir(), which resolves correctly on Windows, POSIX, and macOS alike. Fixes stray folder creation and restores cross-entry singleton protection.
🤖 Open Code ReviewTarget: PR #2225 ✅ OpenCodeReview: No supported files changed. Generated by cloud-assistant via Open Code Review. |
|
✅ Automated Test Results: PASSEDAll tests passed (35/35 executed). memos_local_plugin/unit: 35/35. Duration: 5s [advisory, non-gating] AI-generated tests on branch test/auto-gen-b454687b5703bb12-20260807021221: 41/41 passed — these do NOT affect the PR verdict; review the branch manually. Branch: |
Problem
On Windows, every bridge/daemon start creates a stray folder at the root of whichever drive the process happens to run from.
process.env.HOMEis not set on Windows (Windows usesUSERPROFILE), sopidFilePath()falls back to"/tmp":Node resolves
/tmprelative to the current drive root of the process cwd. Concretely:C:→ writesC:\tmp\.hermes\memos-plugin\daemon\bridge.pidD:→ writesD:\tmp\.hermes\memos-plugin\daemon\bridge.pidStart-Processwithout-WorkingDirectory, so the daemon inherits whatever directory the installer was run from — users who install fromD:\get the PID file onD:\tmpTwo consequences:
C:\tmp\.hermes\...andD:\tmp\.hermes\...) appear on drive roots after any bridge/daemon start — confusing, and they accumulate.C:cannot see the PID file written by one started fromD:(or vice-versa).killExistingBridge()then fails to kill the previous holder and two daemons fight over the viewer port (observed: twoserver.startedon :18800 from independent processes).Fix
Use
os.homedir()instead ofprocess.env.HOME ?? "/tmp".homedir()is cross-platform: on Windows it returnsC:\Users\<user>(viaUSERPROFILE), on POSIX/macOS it returns the user home. The PID file now always lands at~/.hermes/memos-plugin/daemon/bridge.pidregardless of cwd or entry point, restoring the singleton guard.Verification (Windows 10)
C:createdC:\tmp\.hermes\memos-plugin\daemon\bridge.pid; fromD:createdD:\tmp\...; both stale entries pointed to dead PIDs while a third live daemon wrote to yet another location.C:\Users\<user>\.hermes\memos-plugin\daemon\bridge.pid, matching the actual listener PID. NoC:\tmp/D:\tmpfolders are created.Notes