fix(gateway): load $HERMES_HOME/.env from systemd unit so plugins see env vars - #18606
Closed
vvb-1 wants to merge 1 commit into
Closed
fix(gateway): load $HERMES_HOME/.env from systemd unit so plugins see env vars#18606vvb-1 wants to merge 1 commit into
vvb-1 wants to merge 1 commit into
Conversation
… env vars Closes #2765 (root cause; warnings added in #2768 made this visible without resolving it). systemd starts services with a clean environment; ~/.hermes/.env was never loaded by the generated hermes-gateway.service unit, so plugins that declare requires_env (Hindsight, OpenAI-backed tools, internal HTTP plugins, etc.) silently skipped registration and the gateway booted into a degraded toolset. The user-facing symptom in the field was a gateway exposing only the default-fallback tools while the same Hermes install in an interactive shell exposed the full set, because the shell's exported env never reached the systemd cgroup. Both unit templates (system-wide and --user) now contain: EnvironmentFile=-{hermes_home}/.env inserted directly under [Service] and before any Environment= lines so unit-defined values still win on conflict. The leading '-' makes the directive optional; a missing file does not fail unit start. The reference resolves through the same {hermes_home} interpolation already used by Environment="HERMES_HOME=...", so profile-aware paths (e.g. ~/.hermes-dev/.env) work without further changes. Tests: two new cases under TestGeneratedSystemdUnits assert the directive is present and points at a *.env file for both the user and system unit.
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
Both generated
hermes-gateway.serviceunit templates (system-wide and--user) are missing anEnvironmentFile=directive, so~/.hermes/.envis never loaded when the gateway runs under systemd. The shell-exported env vars that work in interactivehermessessions never reach the systemd cgroup.User-visible symptom: plugins that declare
requires_env(Hindsight, OpenAI-backed tools, internal HTTP plugins, etc.) silently skip registration and the gateway boots into a degraded toolset, while the same Hermes install run interactively exposes the full toolset.This is the root cause of #2765. PR #2768 added warnings that surface the symptom but does not fix the underlying unit template.
Repro
On a Linux host with
systemd --user:Even though
~/.hermes/.envcontains valid keys, the gateway process never sees them.Fix
Add an
EnvironmentFile=-{hermes_home}/.envline under[Service]in both templates (rendered bygenerate_systemd_unit()inhermes_cli/gateway.py):Environment=lines so unit-defined values still take precedence on conflict.-makes the directive optional — a missing.envfile does not fail unit start.{hermes_home}interpolation already used forEnvironment="HERMES_HOME=...", so profile-aware paths (e.g.~/.hermes-dev/.env) resolve correctly without further changes.After this change, the same repro yields a non-zero count corresponding to the keys present in
~/.hermes/.env. Plugins that previously skipped registration now register their tools, and the gateway exposes the full toolset to messaging platforms (Telegram, Discord, etc.).Tests
Two new cases in
tests/hermes_cli/test_gateway_service.py::TestGeneratedSystemdUnits:test_user_unit_loads_hermes_env_filedefault.target) rendersEnvironmentFile=-…/.envtest_system_unit_loads_hermes_env_filemulti-user.target) rendersEnvironmentFile=-…/.envResult locally:
5 passedfor the fullTestGeneratedSystemdUnitsclass (3 existing + 2 new).Backwards compatibility
-prefix means hosts without~/.hermes/.envare unaffected (no new failure mode)._normalize_service_definition) compare normalized text, so existing installs will be flagged as outdated and refreshed by the nexthermes gateway start/restart/install— same path already used for any other unit-template change.hermes gateway run).Related