fix(profiles): honour active_profile when HERMES_HOME points to hermes root#22654
Closed
wesleysimplicio wants to merge 1 commit into
Closed
fix(profiles): honour active_profile when HERMES_HOME points to hermes root#22654wesleysimplicio wants to merge 1 commit into
wesleysimplicio wants to merge 1 commit into
Conversation
…s root
Problem:
After `hermes profile use NAME`, the gateway (started via systemd with
HERMES_HOME=/root/.hermes hardcoded) ignores the active profile and
always runs as the Default profile. WebUI, Telegram, and all non-CLI
platforms are affected.
Root cause:
_apply_profile_override() contained an early-return guard:
if profile_name is None and os.environ.get("HERMES_HOME"):
return # trust the inherited value
The intent was to let child processes inherit their parent's profile via
HERMES_HOME without redundantly re-reading active_profile. But
systemd also sets HERMES_HOME — to the hermes root (/root/.hermes),
not a profile directory — so the guard fired and silently skipped the
active_profile check. The user's `hermes profile use NAME` write to
~/.hermes/active_profile was never seen by the gateway process.
Fix:
Only skip the active_profile check when HERMES_HOME is already a
profile directory, identified by its immediate parent directory being
named "profiles" (e.g. ~/.hermes/profiles/coder or
/opt/data/profiles/coder). When HERMES_HOME points to a root
directory (parent name != "profiles"), continue to read active_profile.
Tests:
- test_hermes_home_at_root_with_active_profile_is_redirected: the
bug scenario — HERMES_HOME=/root/.hermes + active_profile=coder →
HERMES_HOME must be redirected to .../profiles/coder.
Stash-verified: FAILS without fix, PASSES with fix.
- test_hermes_home_already_profile_dir_is_trusted: child-process
inheritance contract unchanged — .../profiles/coder is trusted as-is.
- test_hermes_home_unset_reads_active_profile: classic path unchanged.
- test_hermes_home_unset_default_profile_no_redirect: "default" still
produces no redirect.
4/4 tests green.
Closes NousResearch#22502.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression where non-CLI entrypoints (notably systemd-started gateway/WebUI/Telegram) ignore the sticky active_profile when HERMES_HOME is set to the Hermes root rather than a specific profile directory.
Changes:
- Refines
_apply_profile_override()to only “trust” an inheritedHERMES_HOMEwhen it already points to.../profiles/<name>(parent directory name isprofiles). - Adds regression tests covering the systemd/root case vs the child-process/profile-dir inheritance case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
hermes_cli/main.py |
Adjusts the early-return guard so active_profile is still honored when HERMES_HOME is set to the Hermes root. |
tests/hermes_cli/test_apply_profile_override.py |
Adds regression tests for the updated HERMES_HOME guard behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+82
to
+86
| assert "profiles" in result, ( | ||
| f"Expected HERMES_HOME to point into profiles/ dir, got: {result!r}" | ||
| ) | ||
| assert result.endswith("coder"), ( | ||
| f"Expected HERMES_HOME to end with 'coder', got: {result!r}" |
Comment on lines
+125
to
+126
| assert result is not None | ||
| assert "coder" in result |
Contributor
|
Merged via salvage PR #22677. Your commit was cherry-picked onto current main with your authorship preserved in git log (rebase-merge). Thanks for the contribution! |
19 tasks
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.
Problem
After
hermes profile use NAME, the gateway (started via systemd withHERMES_HOME=/root/.hermeshardcoded) ignores the active profile and always runs as the Default profile. WebUI, Telegram, and all non-CLI platforms are affected.Root cause
_apply_profile_override()inhermes_cli/main.pyhad an early-return guard:The intent was correct for child processes that inherit
HERMES_HOMEalready pointing to a profile directory (e.g.~/.hermes/profiles/coder). But systemd also setsHERMES_HOME— to the hermes root (/root/.hermes), not a profile directory — so the guard fired and theactive_profilecheck was silently skipped.Fix
Only skip the
active_profilecheck whenHERMES_HOMEis already a profile directory, identified by its immediate parent being named"profiles":This preserves the child-process inheritance contract while fixing the systemd case.
Tests
New file
tests/hermes_cli/test_apply_profile_override.py:test_hermes_home_at_root_with_active_profile_is_redirectedHERMES_HOME=/root/.hermes+active_profile=coder.../profiles/codertest_hermes_home_already_profile_dir_is_trustedHERMES_HOME=.../profiles/codertest_hermes_home_unset_reads_active_profiletest_hermes_home_unset_default_profile_no_redirectactive_profile=defaultStash-verified: key regression test FAILS without fix, PASSES with fix. 4/4 tests green.
Closes #22502.