Skip to content

gateway.log is never attached when logging is initialized in CLI mode before gateway startup #8404

@Tony-ooo

Description

@Tony-ooo

Summary

gateway.log is not attached on the normal hermes gateway run startup path because logging is initialized in CLI mode first, and the later gateway-mode initialization is skipped by the global idempotency guard.

Affected version

Observed on commit 4eecaf06.

Reproduction

  1. Start Hermes through the normal CLI entrypoint:
    hermes gateway run
  2. Generate some gateway activity.
  3. Inspect ~/.hermes/logs/.

Actual behavior

  • agent.log and errors.log are active.
  • gateway.log exists but remains empty, or is never attached as an active handler.
  • Gateway logger output still lands in agent.log.

Expected behavior

gateway.log should be attached and should receive records from gateway.* loggers during hermes gateway run.

Root cause

The CLI entrypoint initializes logging in CLI mode very early:

  • hermes_cli/main.py calls setup_logging(mode="cli")

Later, gateway startup tries to initialize gateway logging:

  • gateway/run.py calls setup_logging(..., mode="gateway")

But hermes_logging.setup_logging() returns early once _logging_initialized is already True, so the gateway-specific handler is never added.

That means the code path that creates the filtered gateway.log handler is skipped on the normal CLI -> gateway startup flow.

Minimal reproduction at the Python level

import hermes_logging

hermes_logging.setup_logging(mode="cli")
hermes_logging.setup_logging(mode="gateway")

Result: only agent.log and errors.log are attached.

If setup_logging(mode="gateway") is called first, gateway.log is created correctly.

Suggested fix

When setup_logging() is called again with mode="gateway", it should still ensure that the gateway.log handler exists instead of returning immediately.

One approach would be:

  • keep the function idempotent for existing handlers
  • but on a later mode="gateway" call, add the missing gateway.log handler if it has not been attached yet

Regression test suggestion

Add a test that covers this exact sequence:

  1. setup_logging(mode="cli")
  2. setup_logging(mode="gateway")
  3. assert that gateway.log handler exists and receives gateway.* records

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/configConfig system, migrations, profilescomp/cliCLI entry point, hermes_cli/, setup wizardcomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions