fix(gateway): fall back to python3 when venv lacks bare python symlink - #7985
Closed
hugobiais wants to merge 1 commit into
Closed
fix(gateway): fall back to python3 when venv lacks bare python symlink#7985hugobiais wants to merge 1 commit into
hugobiais wants to merge 1 commit into
Conversation
`get_python_path()` only checked `venv/bin/python`, so if that symlink was missing the helper fell through to `sys.executable`, which on a uv-managed install resolves to the base interpreter. `generate_systemd_unit()` then baked the base interpreter into `ExecStart`, while still setting `VIRTUAL_ENV=` and `PATH=` to the venv — causing the service to start without the venv's `site-packages` and crash with `ModuleNotFoundError` for any dependency installed into the venv (e.g. `yaml`). Try `python`, then `python3`, then `pythonX.Y` inside the venv before giving up on it, so the generated unit uses an interpreter that can actually import the Hermes dependencies. Fixes NousResearch#7976
4 tasks
Contributor
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 #7976.
hermes gateway install --systemgenerates a unit file whoseExecStartpoints at the base uv-managed Python interpreter instead of the project venv. The service starts, cannot importyaml(or any other Hermes dependency installed into the venv'ssite-packages), and crash-loops.Root cause is in
get_python_path()inhermes_cli/gateway.py:The venv is detected correctly via
sys.prefix, but the helper only probesvenv/bin/python. On uv-managed installs where the barepythonsymlink is absent (and onlypython3/python3.11exist inside the venv'sbin/), the.exists()check fails and the function falls through tosys.executable, which on such installs resolves to the base interpreter under~/.local/share/uv/python/....generate_systemd_unit()then bakes that base interpreter intoExecStart— while still (correctly) settingVIRTUAL_ENV=andPATH=to the venv — so the running service has no access to the venv'ssite-packagesand anyimport yaml(and similar) blows up on startup.Fix
Try
python, thenpython3, thenpythonX.Yinside the detected venv before giving up on it.pythonis still checked first, so installs where the bare symlink exists are unaffected.The change is scoped to
get_python_path()—generate_systemd_unit()itself is untouched, and the_remap_path_for_user()pipeline that rewrites/root/...into the target user's home for--systeminstalls still works unchanged sincepython_pathis assigned through the same helper before remapping.Tests
Added
TestGetPythonPathintests/hermes_cli/test_gateway_service.pycovering:test_prefers_bare_python_when_available— existing behavior preserved when the barepythonsymlink is present.test_falls_back_to_python3_when_bare_python_missing— the regression scenario: onlypython3/python3.11in the venv → returnsvenv/bin/python3.test_falls_back_to_versioned_python— only the versionedpythonX.Yexists → returns that.test_returns_sys_executable_when_venv_has_no_interpreter— empty venvbin/→ falls back tosys.executable(unchanged).test_returns_sys_executable_when_no_venv_detected—_detect_venv_dir()returnsNone→ falls back tosys.executable(unchanged).All 67 tests in
test_gateway_service.pypass (62 pre-existing + 5 new), no other files touched.Reproduction (for reference)
Host: Ubuntu 24.04, Hermes Agent v0.8.0, standard installer, running as root on a VPS.
Generated unit (pre-fix):
The meanwhile-workaround (systemd drop-in override that hardcodes the venv python) is documented in #7976.