fix: defer DEFAULT_DB_PATH resolution to fix profile HERMES_HOME mismatch#15330
Open
GumbyEnder wants to merge 1 commit into
Open
fix: defer DEFAULT_DB_PATH resolution to fix profile HERMES_HOME mismatch#15330GumbyEnder wants to merge 1 commit into
GumbyEnder wants to merge 1 commit into
Conversation
…atch When a user launches a profile (e.g. ) while points to a different profile B, the TUI gateway, slash worker, and systemd gateway service open profile B's state.db, logs, and sessions instead of profile A's. Root cause: is evaluated at module import time, before in has corrected to the requested profile. The same race affects 's module-level and any subprocess that inherits a stale env. Changes: - Replace eager constant with descriptor that defers resolution until first access, by which time has set the correct env var. - now explicitly injects into the child env when missing, preventing inheritance of a stale shell value. - Add comment to noting the lazy resolution. The lazy descriptor preserves the module-level name (so existing imports continue to work) while providing a method for test fixtures that swap HERMES_HOME via monkeypatch. Fixes: NousResearch#4707 (same class of bug, different trigger) Related: NousResearch#4671, NousResearch#4587, NousResearch#4402, NousResearch#4426
11 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.
Summary
When a user launches a profile (e.g.
hermes --tui -p A) while~/.hermes/active_profilepoints to a different profile B, the TUI gateway, slash worker, and systemd gateway service open profile B'sstate.db, logs, and sessions instead of profile A's. The TUI shows "ready" but never responds — messages go into the wrong profile's session store.Root Cause
hermes_state.DEFAULT_DB_PATH = get_hermes_home() / "state.db"is evaluated at module import time, before_apply_profile_override()inhermes_cli/main.pyhas correctedHERMES_HOMEto the requested profile.The same race affects:
tui_gateway/server.py's module-level_hermes_home_SlashWorker) that inherits a stale shellHERMES_HOMEHERMES_HOME=~/.hermesand relies onactive_profileresolution at runtimeReproduction
hermes profile use B(writesBto~/.hermes/active_profile)hermes --tui -p Als -la /proc/$(pgrep -f tui_gateway.entry)/fd/ | grep state.db→ points to profile B'sstate.dbChanges
hermes_state.py— LazyDEFAULT_DB_PATHReplace the eager constant:
With a lazy descriptor that defers resolution until first attribute access:
The descriptor preserves the module-level name (so
from hermes_state import DEFAULT_DB_PATHstill works) and provides a_reset()method for test fixtures that swapHERMES_HOMEvia monkeypatch.tui_gateway/server.py— ExplicitHERMES_HOMEin slash worker env_SlashWorkernow explicitly injectsHERMES_HOMEinto the child env when missing, preventing inheritance of a stale shell value.tools/session_search_tool.py— Comment updateNotes that
DEFAULT_DB_PATHis now lazy-resolved.Testing
test_hermes_state.pytests passactive_profile, confirmed FDs now point to the correct profile'sstate.dbRelated Issues
~/.hermesinstead of profileHERMES_HOME#4707 — Same class of bug (cron under profile-scoped launchd gateway)Note to Reviewers
The
_LazyDefaultDBPathapproach preserves backward compatibility (same import path, same attribute access patterns) while fixing the core race. An alternative would be to audit every import site and convert them to function calls, but that's a larger refactor with more breakage risk. The lazy descriptor is the minimal safe fix.