Skip to content

fix: defer DEFAULT_DB_PATH resolution to fix profile HERMES_HOME mismatch#15330

Open
GumbyEnder wants to merge 1 commit into
NousResearch:mainfrom
GumbyEnder:fix/profile-import-time-path-caching
Open

fix: defer DEFAULT_DB_PATH resolution to fix profile HERMES_HOME mismatch#15330
GumbyEnder wants to merge 1 commit into
NousResearch:mainfrom
GumbyEnder:fix/profile-import-time-path-caching

Conversation

@GumbyEnder

Copy link
Copy Markdown

Summary

When a user launches a profile (e.g. hermes --tui -p A) while ~/.hermes/active_profile 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. 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() in hermes_cli/main.py has corrected HERMES_HOME to the requested profile.

The same race affects:

  • tui_gateway/server.py's module-level _hermes_home
  • Any subprocess (_SlashWorker) that inherits a stale shell HERMES_HOME
  • The systemd gateway service, which sets HERMES_HOME=~/.hermes and relies on active_profile resolution at runtime

Reproduction

  1. hermes profile use B (writes B to ~/.hermes/active_profile)
  2. From another terminal: hermes --tui -p A
  3. TUI shows "ready" but agent never responds
  4. Forensic check: ls -la /proc/$(pgrep -f tui_gateway.entry)/fd/ | grep state.db → points to profile B's state.db

Changes

hermes_state.py — Lazy DEFAULT_DB_PATH

Replace the eager constant:

DEFAULT_DB_PATH = get_hermes_home() / "state.db"  # evaluated at import time

With a lazy descriptor that defers resolution until first attribute access:

DEFAULT_DB_PATH: _LazyDefaultDBPath = _LazyDefaultDBPath()

The descriptor preserves the module-level name (so from hermes_state import DEFAULT_DB_PATH still works) and provides a _reset() method for test fixtures that swap HERMES_HOME via monkeypatch.

tui_gateway/server.py — Explicit HERMES_HOME in slash worker env

_SlashWorker now explicitly injects HERMES_HOME into the child env when missing, preventing inheritance of a stale shell value.

tools/session_search_tool.py — Comment update

Notes that DEFAULT_DB_PATH is now lazy-resolved.

Testing

  • All 174 test_hermes_state.py tests pass
  • Manual verification: launched TUI with mismatched active_profile, confirmed FDs now point to the correct profile's state.db

Related Issues

Note to Reviewers

The _LazyDefaultDBPath approach 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.

…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
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants