Skip to content

fix(gateway): session key profile isolation + cron ticker cleanup + /new None guard#12108

Closed
zons-zhaozhy wants to merge 2 commits into
NousResearch:mainfrom
zons-zhaozhy:fix/session-key-profile-isolation
Closed

fix(gateway): session key profile isolation + cron ticker cleanup + /new None guard#12108
zons-zhaozhy wants to merge 2 commits into
NousResearch:mainfrom
zons-zhaozhy:fix/session-key-profile-isolation

Conversation

@zons-zhaozhy

@zons-zhaozhy zons-zhaozhy commented Apr 18, 2026

Copy link
Copy Markdown

Three small gateway bugfixes:

  1. Session key profile isolation (build_session_key() hardcodes 'agent:main', breaking multi-profile session isolation #12099)

build_session_key() hardcodes 'agent:main' in all session keys. When running
multiple Hermes profiles (HERMES_HOME=~/.hermes/profiles/), different
profiles share the same session keys, causing conversation leakage.

Fix: add profile parameter to build_session_key(). get_active_profile() returns
the active profile name for non-default profiles, or main for backward compat.

  1. Cron ticker and MCP cleanup on failure path (start_gateway() skips cron ticker cleanup on failure shutdown #12175)

When should_exit_with_failure is True, return False skipped both
cron_stop.set() and shutdown_mcp_servers(), leaking the cron ticker
thread and MCP connections. Wrapped in try/finally so cleanup always runs.

  1. Guard /new against None session in finalize hook (/new emits on_session_finalize(session_id=None) when no prior session exists #12176)

_handle_reset_command() called on_session_finalize(session_id=None)
when no prior session existed. Skip hook invocation when _old_sid is None.

Testing: 3233 passed, 0 new failures (13 pre-existing).

zzy-git added 2 commits April 18, 2026 18:27
…d 'main'

build_session_key() now accepts a 'profile' parameter (default 'main'
for backward compatibility). When a non-default profile is active
(HERMES_HOME points to ~/.hermes/profiles/<name>), session keys
include the profile name (e.g. agent:work:telegram:dm:123) instead
of always using 'agent:main:*', preventing session leakage between
profiles.

Closes NousResearch#12099
… finalize against None session

1. Cron ticker thread and MCP server connections were leaked when the
   gateway exited via should_exit_with_failure. The early return skipped
   cron_stop.set() and shutdown_mcp_servers(). Wrapped in try/finally
   so cleanup always runs. (Closes NousResearch#12175)

2. /new (session reset) called on_session_finalize with session_id=None
   when no prior session existed (old_entry is None). Added None guard
   to skip the hook invocation in that case. (Closes NousResearch#12176)
@zons-zhaozhy zons-zhaozhy changed the title fix(gateway): use dynamic profile in session keys fix(gateway): session key profile isolation + cron ticker cleanup + /new None guard Apr 18, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery comp/cron Cron scheduler and job management labels Apr 23, 2026
@zons-zhaozhy zons-zhaozhy deleted the fix/session-key-profile-isolation branch May 4, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants