fix: preserve user PATH across login shell snapshot#1669
Open
KingBoyAndGirl wants to merge 1 commit into
Open
Conversation
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)
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.
Summary
Fixes a PATH snapshot bug where user-installed tools (e.g.
nmemviauv tool install) become invisible to Hermes afterinit_session()captures the login shell environment.Root Cause
BaseEnvironment.init_session()spawnsbash -l -c "export -p > snapshot". On most Linux distros,/etc/profileunconditionally overwritesPATHwith a static list:This discards entries that
_make_run_env()added from the parent process — most critically~/.local/bin, whereuv tool installplaces binaries likenmem. The captured snapshot then has a degraded PATH, and all subsequent commands source this bad snapshot.Impact
nmem(and anyuv tool installbinary) appears missing after Hermes restartshermes memory statusreports Nowledge Mem provider as "unavailable"~/.local/binare also affectedFix
Two new idempotent patches in
apply-hermes-patches.mjs:local-parent-path-preserve— InLocalEnvironment._run_bash(), stash the pre-login PATH intoHERMES_INIT_PARENT_PATHenvironment variable beforebash -lrunsbase-restore-parent-path— InBaseEnvironment.init_session()'s bootstrap script, restoreHERMES_INIT_PARENT_PATHback intoPATHand unset it beforeexport -pcaptures the snapshotVerification
nmem status→ ok (remote mode, database connected, search ready)hermes memory status→ provider available/lzcapp/var/home:/home/agent)Test
Added
tests/desktop/apply-hermes-patches.test.tswith three test cases:local.pypatch addsHERMES_INIT_PARENT_PATHstashingbase.pypatch restores PATH beforeexport -p