Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/agent_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def init_agent(
# both live under ~/.hermes/logs/. Idempotent, so gateway mode
# (which creates a new AIAgent per message) won't duplicate handlers.
from hermes_logging import setup_logging, setup_verbose_logging
setup_logging(hermes_home=_ra()._hermes_home)
setup_logging(hermes_home=get_hermes_home())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This selects the new profile path but leaves existing default-home handlers active: _add_rotating_handler() only deduplicates identical resolved paths (hermes_logging.py:741-746), and the shared QueueListener sends every root record to all registered targets (hermes_logging.py:615-639). Please add profile-aware routing or retire/filter the old handlers, then cover the pre-initialized default-home case without mocking setup_logging().


if agent.verbose_logging:
setup_verbose_logging()
Expand Down
38 changes: 38 additions & 0 deletions tests/run_agent/test_run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,44 @@ def test_aiagent_reuses_existing_errors_log_handler():
root_logger.addHandler(handler)


def test_aiagent_logging_uses_runtime_hermes_home_not_import_cache(monkeypatch, tmp_path):
"""AIAgent logging must follow the active profile at init time.

run_agent._hermes_home is captured when run_agent is imported. Long-lived
hosts such as the Web UI bridge can import run_agent while the default
profile is active, then switch HERMES_HOME before creating an AIAgent for a
named profile. Logging setup must use the current HERMES_HOME, otherwise
agent.log/errors.log continue landing in the default profile.
"""
import_home = tmp_path / "default-home"
runtime_home = tmp_path / "profiles" / "work"
import_home.mkdir(parents=True)
runtime_home.mkdir(parents=True)
monkeypatch.setattr(run_agent, "_hermes_home", import_home)
monkeypatch.setenv("HERMES_HOME", str(runtime_home))

with (
patch("hermes_logging.setup_logging") as setup_logging,
patch(
"run_agent.get_tool_definitions",
return_value=_make_tool_defs("web_search"),
),
patch("run_agent.check_toolset_requirements", return_value={}),
patch("run_agent.OpenAI"),
):
AIAgent(
api_key="test-k...7890",
base_url="https://openrouter.ai/api/v1",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)

setup_logging.assert_called()
assert setup_logging.call_args.kwargs["hermes_home"] == runtime_home
assert setup_logging.call_args.kwargs["hermes_home"] != import_home


class TestProviderModelNormalization:
def test_aiagent_strips_matching_native_provider_prefix(self):
with (
Expand Down
Loading