Skip to content

fix: use runtime Hermes home for agent logging - #27336

Draft
EKKOLearnAI wants to merge 1 commit into
NousResearch:mainfrom
EKKOLearnAI:codex/runtime-hermes-home-logging
Draft

fix: use runtime Hermes home for agent logging#27336
EKKOLearnAI wants to merge 1 commit into
NousResearch:mainfrom
EKKOLearnAI:codex/runtime-hermes-home-logging

Conversation

@EKKOLearnAI

Copy link
Copy Markdown
Contributor

Summary

  • Initialize AIAgent file logging with the current runtime HERMES_HOME instead of the import-time cached run_agent._hermes_home.
  • Add a regression test for long-lived hosts that import run_agent under one home and create an agent after switching to a profile home.

Root Cause

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 temporarily set HERMES_HOME to a named profile before creating AIAgent. Because logging setup used the cached value, agent.log and errors.log continued writing to the default profile even though runtime profile state had changed.

Validation

  • pytest -o addopts="" tests/run_agent/test_run_agent.py -k "logging_uses_runtime_hermes_home or reuses_existing_errors_log_handler"

Note: -o addopts="" was used locally because this environment does not have the xdist plugin required by the repository default -n pytest option.

@EKKOLearnAI EKKOLearnAI changed the title [codex] Use runtime Hermes home for agent logging fix: use runtime Hermes home for agent logging May 17, 2026
@cardtest15-coder

This comment was marked as spam.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard labels May 17, 2026
@teknium1

teknium1 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the focused fix — I verified the premise still holds on current main.

Current main assigns run_agent._hermes_home at import time in run_agent.py:112, and AIAgent later passes that cached value into logging setup at agent/agent_init.py:553. get_hermes_home() is the runtime/profile-aware source of truth (hermes_constants.py:69-75), so the PR's one-line change points the agent logging call at the right layer.

Suggested changes

  • Consider extending the regression test to cover set_hermes_home_override(...) as well as HERMES_HOME, since current main checks the context-local override first in hermes_constants.py:69-71 and TUI gateway paths use that mechanism.
  • If you want to cover hosts that already called setup_logging() before agent construction, add a test for pre-existing wrong-home RotatingFileHandlers. setup_logging() adds requested file handlers at hermes_logging.py:263-281, while _add_rotating_handler() only deduplicates exact same resolved paths at hermes_logging.py:496-502.

Automated hermes-sweeper review; humans decide final salvage/merge.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the focused runtime-home fix. The cached-home premise remains valid on current main: run_agent.py:125 captures _hermes_home, and agent/agent_init.py:700 passes it into setup_logging().

Problems

  • The changed call at PR agent/agent_init.py:454 adds handlers for the runtime profile but does not replace the existing default-home handlers. setup_logging() registers agent.log and errors.log handlers at hermes_logging.py:321-338; _add_rotating_handler() deduplicates only the same resolved path at hermes_logging.py:741-746. The queue listener then dispatches root records to every registered target (hermes_logging.py:615-639). Default-home logging therefore continues, and concurrent profile sessions can cross-copy logs.

Suggested changes

  • Make handler routing profile-aware (or otherwise isolate existing handlers) and add an unmocked regression test that initializes default-home logging before constructing an agent under the context-local profile override used by tui_gateway/server.py:1349.

Automated hermes-sweeper review.

Comment thread agent/agent_init.py
# (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
Contributor

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().

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants