Skip to content

The agent that grows with you

fix(constants): engage the warn-once latch on the first check, not only on the warning branch

ygd58c1a59688c183
diff --git a/hermes_constants.py b/hermes_constants.py
index c1a5ee9f5bc..d14c93579ad 100644
--- a/hermes_constants.py
+++ b/hermes_constants.py
@@ -83,6 +83,10 @@ def _warn_profile_fallback_once() -> None:
global _profile_fallback_warned
if _profile_fallback_warned:
return
+ # Latch on the FIRST check regardless of outcome (one-shot contract). Previously the latch
+ # was only set on the warning branch, so with no active_profile (or "default") the stat +
+ # read re-ran on every get_hermes_home() call (#90065).
+ _profile_fallback_warned = True
try:
fallback_home = _get_platform_default_hermes_home()
active_path = fallback_home / "active_profile"
@@ -90,7 +94,6 @@ def _warn_profile_fallback_once() -> None:
except (UnicodeDecodeError, OSError):
active = ""
if active and active != "default":
- _profile_fallback_warned = True
# Direct stderr, not logging: runs at import time (often before logging is
# configured) and root-logger propagation would double-emit.
msg = (
diff --git a/tests/test_hermes_constants.py b/tests/test_hermes_constants.py
index 6254802a320..a32c8f54d6a 100644
--- a/tests/test_hermes_constants.py
+++ b/tests/test_hermes_constants.py
@@ -86,6 +86,16 @@ class TestGetDefaultHermesRoot:
class TestGetHermesHome:
"""Tests for get_hermes_home() platform-aware fallback."""
+ def test_warn_once_latch_engages_on_first_check_even_without_warning(self, tmp_path, monkeypatch):
+ """Regression for #90065: the latch must engage on the first check even when there is
+ nothing to warn about, otherwise every get_hermes_home() call re-stats active_profile."""
+ monkeypatch.delenv("HERMES_HOME", raising=False)
+ monkeypatch.setattr(hermes_constants, "_profile_fallback_warned", False)
+ monkeypatch.setattr(hermes_constants, "_get_platform_default_hermes_home", lambda: tmp_path)
+
+ get_hermes_home()
+ assert hermes_constants._profile_fallback_warned is True
+
@pytest.mark.windows_only
def test_windows_fallback_uses_localappdata(self, tmp_path, monkeypatch):
"""When HERMES_HOME is unset on Windows, use %LOCALAPPDATA%\\hermes."""