Skip to content

fix: preserve user PATH across login shell snapshot#1669

Open
KingBoyAndGirl wants to merge 1 commit into
EKKOLearnAI:mainfrom
KingBoyAndGirl:fix/preserve-user-path-in-shell-snapshot
Open

fix: preserve user PATH across login shell snapshot#1669
KingBoyAndGirl wants to merge 1 commit into
EKKOLearnAI:mainfrom
KingBoyAndGirl:fix/preserve-user-path-in-shell-snapshot

Conversation

@KingBoyAndGirl

Copy link
Copy Markdown

Summary

Fixes a PATH snapshot bug where user-installed tools (e.g. nmem via uv tool install) become invisible to Hermes after init_session() captures the login shell environment.

Root Cause

BaseEnvironment.init_session() spawns bash -l -c "export -p > snapshot". On most Linux distros, /etc/profile unconditionally overwrites PATH with a static list:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This discards entries that _make_run_env() added from the parent process — most critically ~/.local/bin, where uv tool install places binaries like nmem. The captured snapshot then has a degraded PATH, and all subsequent commands source this bad snapshot.

Impact

  • nmem (and any uv tool install binary) appears missing after Hermes restarts
  • hermes memory status reports Nowledge Mem provider as "unavailable"
  • Other user-installed CLI tools under ~/.local/bin are also affected

Fix

Two new idempotent patches in apply-hermes-patches.mjs:

  1. local-parent-path-preserve — In LocalEnvironment._run_bash(), stash the pre-login PATH into HERMES_INIT_PARENT_PATH environment variable before bash -l runs
  2. base-restore-parent-path — In BaseEnvironment.init_session()'s bootstrap script, restore HERMES_INIT_PARENT_PATH back into PATH and unset it before export -p captures the snapshot

Verification

  • Confirmed on a live Hermes Studio instance on LazyCat LPK
  • nmem status → ok (remote mode, database connected, search ready)
  • hermes memory status → provider available
  • Survives container restart with whole-home persistence (/lzcapp/var/home:/home/agent)

Test

Added tests/desktop/apply-hermes-patches.test.ts with three test cases:

  • Verifies local.py patch adds HERMES_INIT_PARENT_PATH stashing
  • Verifies base.py patch restores PATH before export -p
  • Verifies idempotency (re-running skips already-applied patches)

Root cause: `BaseEnvironment.init_session()` runs `bash -l -c` to
capture an environment snapshot. On most Linux distros, `/etc/profile`
unconditionally overwrites PATH with a static list, discarding entries
that `_make_run_env` added (e.g. `~/.local/bin` from the parent
process or user profile). The `export -p` snapshot then captures the
degraded PATH, causing user-installed tools (like `nmem` from
`uv tool install`) to be invisible to subsequent commands.

Fix: stash the pre-login PATH in `HERMES_INIT_PARENT_PATH` inside
`_run_bash`, then restore it in `init_session`'s bootstrap script
before the `export -p` snapshot.

Changes:
- packages/desktop/scripts/apply-hermes-patches.mjs: add two new
  idempotent patches for hermes-agent's local.py and base.py
- tests/desktop/apply-hermes-patches.test.ts: regression tests for
  the new patches (local.py stash, base.py restore, idempotency)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant