fix(setup+gateway): defer config write, PID-based gateway kill, scoped systemd service names#1499
Merged
fix(setup+gateway): defer config write, PID-based gateway kill, scoped systemd service names#1499
Conversation
_update_config_for_provider() was called immediately after provider selection for zai, kimi-coding, minimax, minimax-cn, and anthropic — before model selection happened. Since the gateway re-reads config.yaml per-message, this created a race where the gateway would pick up the new provider but still use the old (incompatible) model name. Capture selected_base_url in each provider block, then call _update_config_for_provider() once, after model selection completes, right before save_config(). The in-memory _set_model_provider() calls stay in place so the config object remains consistent during setup. Closes #1182
Contributor
|
Thanks for the cherry-pick and the test coverage! Glad the fix made it in. |
cmd_update only ran 'systemctl --user restart hermes-gateway', which left manually-started gateway processes alive, causing duplicates. Now uses get_running_pid() from gateway/status.py (scoped to HERMES_HOME) to find and SIGTERM this installation's gateway before restarting. Safe with multiple Hermes installations since each HERMES_HOME has its own PID file. If no systemd service exists, informs the user to restart manually. Based on PR #1131 by teknium1. Dropped the cli.py Rich from_ansi changes (already on main).
Multiple Hermes installations on the same machine now get unique systemd service names: - Default ~/.hermes → hermes-gateway (backward compatible) - Custom HERMES_HOME → hermes-gateway-<8-char-hash> Changes: - Add get_service_name() in hermes_cli/gateway.py that derives a deterministic service name from HERMES_HOME via SHA256 - Replace all hardcoded 'hermes-gateway' systemd references with get_service_name() across gateway.py, main.py, status.py, uninstall.py - Add HERMES_HOME env var to both user and system systemd unit templates so the gateway process uses the correct installation - Update tests to use get_service_name() in assertions
- Update messaging guide to use 'hermes gateway' CLI commands instead of raw systemctl (auto-resolves the correct service name) - Add info callout explaining multi-install service name scoping - Update HERMES_HOME env var docs to mention PID + service name scoping
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
Three related setup/gateway fixes for multi-install safety:
1. Defer config.yaml write until after model selection (setup.py)
_update_config_for_provider()was called before model selection, creating a race where the gateway picks up a new provider with the old model. Now deferred to right beforesave_config().Cherry-picked from PR #1188 by @ygd58 (authorship preserved). Closes #1182.
2. Kill gateway via PID file before restart on update (main.py)
hermes updateonly ransystemctl restart, leaving manually-started gateways alive (duplicates). Now usesget_running_pid()(scoped to HERMES_HOME) to SIGTERM this installation's gateway first.Based on PR #1131 by @teknium1.
3. Scope systemd service name to HERMES_HOME (NEW)
Multiple installations on the same machine now get unique systemd service names:
~/.hermes→hermes-gateway(backward compatible)hermes-gateway-<8-char-hash>get_service_name()derives a deterministic name via SHA256 of the resolved HERMES_HOME path. All systemd references acrossgateway.py,main.py,status.py, anduninstall.pynow use it.The systemd unit template also now sets
Environment="HERMES_HOME=..."so the gateway process knows which installation it belongs to.Test Plan
pytest tests/ -n0 -q # 4537 passed, 1 pre-existing failure (unrelated)