Skip to content

The agent that grows with you

fix(agent): trim the #126005 salvage to the one-line active-home fix (#125974)

teknium18affd9aeaa68
diff --git a/agent/agent_init.py b/agent/agent_init.py
index c2671a642b5..1711fdd12a1 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -700,29 +700,11 @@ def _setup_logging(agent):
# agent.log (INFO+) + errors.log (WARNING+); idempotent so per-message gateway agents
# don't duplicate handlers.
from hermes_logging import setup_logging, setup_verbose_logging
- # The ACTIVE home, not run_agent's import-time freeze: a Desktop serve backend builds
- # agents for several profiles inside set_hermes_home_override() (#125974), and the
- # frozen home made setup_logging() see a home it already served — so it never adopted
- # the profile and logged every profile's records into the launch profile's files.
- # A home that cannot host logs (a named profile that is missing or tombstoned —
- # mkdir_under_hermes_home refuses to materialize it on purpose) falls back to the
- # launch home: logging setup must never take agent construction down.
- from hermes_constants import get_hermes_home, get_process_hermes_home
- try:
- setup_logging(hermes_home=get_hermes_home())
- except FileNotFoundError:
- # Never materialize a missing/tombstoned named profile just to host logs
- # (mkdir_under_hermes_home refuses on purpose). Retry against the process
- # launch home when it is a different, live home; if that cannot host logs
- # either, proceed without file logging rather than break construction.
- try:
- setup_logging(hermes_home=get_process_hermes_home())
- except FileNotFoundError:
- print(
- "hermes: no usable Hermes home for log files "
- f"({get_hermes_home()}); logging to files is disabled.",
- file=sys.stderr,
- )
+ # The ACTIVE home, not run_agent's import-time freeze: a Desktop serve backend builds agents
+ # for several profiles inside set_hermes_home_override(), and the frozen launch home made
+ # setup_logging() see a home it already served, so it never adopted the profile and every
+ # profile's records landed in the launch profile's agent.log (#125974).
+ setup_logging(hermes_home=get_hermes_home())
if agent.verbose_logging:
setup_verbose_logging()
diff --git a/tests/agent/test_setup_logging_profile_scope.py b/tests/agent/test_setup_logging_profile_scope.py
index 54b8e8b51c0..ebfd259639b 100644
--- a/tests/agent/test_setup_logging_profile_scope.py
+++ b/tests/agent/test_setup_logging_profile_scope.py
@@ -69,71 +69,6 @@ class TestSetupLoggingProfileScope:
text_a = log_a.read_text(encoding="utf-8-sig") if log_a.is_file() else ""
assert "scoped-witness-b" not in text_a, "record must not leak into the launch home"
- def test_without_override_uses_active_home(self, tmp_path: Path, monkeypatch) -> None:
- """L2: with no override, the active (env) home wins over the import-time freeze."""
- from agent.agent_init import _setup_logging
-
- home_a = tmp_path / "home-a"
- home_a.mkdir()
- monkeypatch.setenv("HERMES_HOME", str(home_a))
-
- _setup_logging(_agent_stub())
- _witness("agent.test_active_home_125974", "active-home-witness")
- hermes_logging.flush_log_queue()
-
- log_a = home_a / "logs" / "agent.log"
- assert log_a.is_file(), "records must follow the active home, not the import freeze"
- assert "active-home-witness" in log_a.read_text(encoding="utf-8-sig")
-
- def test_missing_named_profile_falls_back_to_launch_home(self, tmp_path: Path) -> None:
- """L4: a named-profile override that does not exist must not break agent setup.
-
- mkdir_under_hermes_home() refuses to materialize a missing/tombstoned named
- profile on purpose; _setup_logging must fall back to the launch home instead of
- taking agent construction down.
- """
- from agent.agent_init import _setup_logging
-
- home_a = tmp_path / "home-a"
- home_a.mkdir()
-
- token = set_hermes_home_override(str(tmp_path / ".hermes" / "profiles" / "ghost"))
- try:
- _setup_logging(_agent_stub()) # must not raise
- _witness("agent.test_ghost_profile_125974", "ghost-fallback-witness")
- finally:
- reset_hermes_home_override(token)
- hermes_logging.flush_log_queue()
-
- # The ghost profile dir must NOT have been materialized by logging setup.
- assert not (tmp_path / ".hermes" / "profiles" / "ghost").exists()
- # The record fell back to the process home (the isolated HERMES_HOME).
- from hermes_constants import get_process_hermes_home
-
- fallback_log = get_process_hermes_home() / "logs" / "agent.log"
- assert "ghost-fallback-witness" in fallback_log.read_text(encoding="utf-8-sig")
-
- def test_no_live_home_skips_file_logging_without_raising(self, tmp_path: Path, monkeypatch, capsys) -> None:
- """L4b: when not even the process home can host logs, construction still succeeds.
-
- The env home itself may point at a missing named profile (the scenario behind
- test_skip_background_review.py::test_persistence_failure_error_fallback...):
- no home is materialized, nothing raises, and the user is told file logging is off.
- """
- from agent.agent_init import _setup_logging
-
- monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes" / "profiles" / "research"))
-
- token = set_hermes_home_override(str(tmp_path / ".hermes" / "profiles" / "ghost"))
- try:
- _setup_logging(_agent_stub()) # must not raise
- finally:
- reset_hermes_home_override(token)
-
- assert not (tmp_path / ".hermes" / "profiles" / "research").exists()
- assert not (tmp_path / ".hermes" / "profiles" / "ghost").exists()
- assert "logging to files is disabled" in capsys.readouterr().err
-
def test_under_routing_adds_no_bare_handler(self, tmp_path: Path) -> None:
"""L3 guard: with routing already live, a scoped _setup_logging adds no bare handler.