Skip to content

The agent that grows with you

fix(gateway): route identity-file HERMES_HOME readers through get_process_hermes_home

teknium1bfa2c4919688
diff --git a/gateway/lifecycle_ledger.py b/gateway/lifecycle_ledger.py
index 8eb0364ab07..d3e33c204c3 100644
--- a/gateway/lifecycle_ledger.py
+++ b/gateway/lifecycle_ledger.py
@@ -26,10 +26,10 @@ logger = logging.getLogger(__name__)
def _process_hermes_home() -> Path:
"""HERMES_HOME for process-level identity files (ignore task overrides)."""
- from hermes_constants import get_hermes_home
+ from hermes_constants import get_hermes_home, get_process_hermes_home
- val = os.environ.get("HERMES_HOME", "").strip()
- return Path(val) if val else get_hermes_home()
+ # get_process_hermes_home expands ``~``/``$VAR`` (python -m gateway.run skips the CLI normalizer).
+ return get_process_hermes_home() if os.environ.get("HERMES_HOME", "").strip() else get_hermes_home()
def _home_path(home: Optional[Path], *relative: str) -> Path:
diff --git a/gateway/shutdown_forensics.py b/gateway/shutdown_forensics.py
index 912b1ac3d0c..e2e8d3720d0 100644
--- a/gateway/shutdown_forensics.py
+++ b/gateway/shutdown_forensics.py
@@ -101,7 +101,7 @@ def snapshot_shutdown_context(received_signal: Any = None) -> Dict[str, Any]:
# --replace instance is killing us". Filenames mirror gateway.status; literals keep the signal-
# handler path import-light.
with contextlib.suppress(Exception): # noqa: BLE001 — never raise from a signal handler
- hermes_home_str = os.environ.get("HERMES_HOME")
+ hermes_home_str = os.path.expanduser(os.environ.get("HERMES_HOME", ""))
if hermes_home_str:
raw = _read_marker(Path(hermes_home_str) / ".gateway-takeover.json")
if raw is not None:
diff --git a/gateway/shutdown_watchdog.py b/gateway/shutdown_watchdog.py
index 028b78c0c23..87fcc19e7c8 100644
--- a/gateway/shutdown_watchdog.py
+++ b/gateway/shutdown_watchdog.py
@@ -23,7 +23,7 @@ from pathlib import Path
from typing import Any, Callable, Dict, Optional
from gateway.restart import GATEWAY_SERVICE_RESTART_EXIT_CODE
-from hermes_constants import get_hermes_home
+from hermes_constants import get_hermes_home, get_process_hermes_home
from utils import atomic_json_write
logger = logging.getLogger(__name__)
@@ -164,8 +164,7 @@ def _mark_exited_quietly(exit_code: int, reason: str) -> None:
def _process_hermes_home() -> Path:
"""HERMES_HOME for process-level identity files (ignore profile overrides)."""
- val = os.environ.get("HERMES_HOME", "").strip()
- return Path(val) if val else get_hermes_home()
+ return get_process_hermes_home() if os.environ.get("HERMES_HOME", "").strip() else get_hermes_home()
def _home(home: Optional[Path]) -> Path:
diff --git a/gateway/status.py b/gateway/status.py
index fac4715ac7a..b351cd03fdc 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -20,7 +20,7 @@ from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Callable, NamedTuple, Optional
-from hermes_constants import _get_platform_default_hermes_home, get_hermes_home
+from hermes_constants import _get_platform_default_hermes_home, get_hermes_home, get_process_hermes_home
from utils import atomic_json_write
if sys.platform == "win32":
@@ -88,8 +88,7 @@ def _get_process_hermes_home() -> Path:
"""Launch-home HERMES_HOME for identity files (PID, lock, status, markers):
``get_hermes_home()`` honors the per-session ``_HERMES_HOME_OVERRIDE`` and would misroute
them."""
- val = os.environ.get("HERMES_HOME", "").strip()
- return Path(val) if val else _get_platform_default_hermes_home()
+ return get_process_hermes_home()
def _canonical_hermes_home(path: Path | str) -> Path: