fix(gateway): remap HERMES_HOME to target user in system service unit - #4456
Merged
Conversation
When `sudo hermes gateway install --system --run-as-user <user>` generates the systemd unit, get_hermes_home() resolves to /root/.hermes because Path.home() returns root's home under sudo. The unit correctly sets HOME= and User= via _system_service_identity(), but HERMES_HOME was computed independently and pointed to root's config directory. Add _hermes_home_for_target_user() which remaps the current HERMES_HOME to the equivalent path under the target user's home. This handles: - Default ~/.hermes → target user's ~/.hermes - Profiles (e.g. ~/.hermes/profiles/coder) → preserves relative structure - Custom paths (e.g. /opt/hermes) → kept as-is Supersedes #3861 which only handled the default case and left profiles broken (also flagged by Copilot review). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 1, 2026
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
Salvage of #4447 by @deankerr onto current main.
When
sudo hermes gateway install --system --run-as-user <user>generates the systemd unit,get_hermes_home()resolves to/root/.hermesbecausePath.home()returns root's home under sudo. The unit correctly setsHOME=andUser=via_system_service_identity(), butHERMES_HOME=was computed independently and pointed to root's config directory.Adds
_hermes_home_for_target_user()which remaps the current HERMES_HOME to the equivalent path under the target user's home:~/.hermes→ target user's~/.hermes~/.hermes/profiles/coder) → preserves relative structure under target user/opt/hermes) → kept as-isSupersedes #3861 which only handled the default case and left profiles broken.
Test results
test_gateway_service.pytests pass (8 new)test_gateway.py+test_gateway_linger.pypass