Skip to content

[codex] fix gateway session key isolation for named profiles#12102

Open
cola-runner wants to merge 2 commits into
NousResearch:mainfrom
cola-runner:codex/fix-12099-session-key-profile
Open

[codex] fix gateway session key isolation for named profiles#12102
cola-runner wants to merge 2 commits into
NousResearch:mainfrom
cola-runner:codex/fix-12099-session-key-profile

Conversation

@cola-runner

Copy link
Copy Markdown
Contributor

Summary

  • scope gateway session keys by the active Hermes profile instead of hardcoding agent:main
  • preserve agent:main for the default/custom-root deployment so existing session keys remain stable
  • teach _parse_session_key() to understand named-profile session keys and add regression coverage

Root Cause

build_session_key() always emitted the agent:main prefix, so named profiles shared the same gateway session namespace. That let different profiles generate colliding session keys for the same platform/chat identifiers.

Testing

  • python -m pytest tests/gateway/test_session.py -q
  • python -m pytest tests/gateway/test_background_process_notifications.py -q
  • python -m pytest tests/gateway/test_interrupt_key_match.py -q tests/gateway/test_resume_command.py -q tests/gateway/test_session_model_reset.py -q tests/gateway/test_session_race_guard.py -q

Fixes #12099

@cola-runner cola-runner force-pushed the codex/fix-12099-session-key-profile branch from b6448bf to 0d3a2f7 Compare April 18, 2026 16:46
@cola-runner cola-runner marked this pull request as ready for review April 20, 2026 01:51
@cola-runner cola-runner force-pushed the codex/fix-12099-session-key-profile branch from 0d3a2f7 to cd8a9f0 Compare April 21, 2026 03:02
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #12103 — same root cause in build_session_key() hardcoding agent:main. Also see #12266, #12108.

@cola-runner cola-runner force-pushed the codex/fix-12099-session-key-profile branch from cd8a9f0 to 3d92475 Compare April 24, 2026 09:58
@cola-runner

Copy link
Copy Markdown
Contributor Author

Thanks @alt-glitch — rebased on main and stripped this down to just the session-key fix (6 files, +189/-9) so the scope now matches #12103. Approach is the same (new hermes_constants.get_profile_name(), build_session_key() emits agent:<profile>:… and keeps agent:main:… for the default deployment).

One thing this PR adds on top of #12103: _parse_session_key() in gateway/run.py also needs to accept non-main profile segments — otherwise keys built under a named profile round-trip to None and the gateway loses routing. Covered by tests/gateway/test_session.py::TestBuildSessionKeyProfileScoping::test_build_and_parse_roundtrip_named_profile.

Happy to defer to #12103 if maintainers prefer it; in that case the _parse_session_key change + round-trip test should be ported over.

cola-runner and others added 2 commits April 25, 2026 19:59
build_session_key() and _parse_session_key() hardcoded `agent:main`
as the prefix, so concurrent profiles (e.g. `profiles/wechat` and
`profiles/feishu`) collided in the gateway session namespace for the
same platform/chat identifiers.

Derive the prefix from `HERMES_HOME` via a new
`hermes_constants.get_profile_name()` helper that reuses the existing
`parent.name == "profiles"` detection (standard and Docker layouts).
The default deployment still emits `agent:main:…`, so existing session
keys are unchanged. Named profiles now emit `agent:<name>:…` and are
isolated.

`_parse_session_key()` is loosened to accept any non-empty profile
segment in position 1 — without this, keys built under a named profile
would round-trip to `None` and break gateway routing.

Fixes NousResearch#12099
Unblocks the check-attribution CI for this PR. The author is the
PR submitter (cola-runner), confirmed via the GitHub email lookup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cola-runner cola-runner force-pushed the codex/fix-12099-session-key-profile branch from 0784343 to 59d28e6 Compare April 25, 2026 11:59
@cola-runner

Copy link
Copy Markdown
Contributor Author

Quick CI update after rebase onto current main (head 59d28e69):

  • check-attribution, check, nix, supply-chain scan all green. mergeable: MERGEABLE.
  • test / e2e red, but the failure set is identical to main's most recent CI run (53 vs 53, full intersection — zero new failures introduced by this PR). Most are the 'types.SimpleNamespace' object has no attribute 'guild' regression from the recent Discord guild_id work on main.
  • Local run of the touched tests passes: pytest tests/test_hermes_constants.py tests/gateway/test_session.py tests/gateway/test_background_process_notifications.py → 126 passed.

Ready for review whenever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build_session_key() hardcodes 'agent:main', breaking multi-profile session isolation

2 participants