feat(gateway): expose normalized channel identity#17711
Open
nepenth wants to merge 3 commits into
Open
Conversation
2 tasks
This was referenced Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a normalized gateway channel identity block so agents can reliably distinguish the active channel/thread without relying on platform-specific wording in the source description.
This is intentionally scoped after #17702, which preserves named Matrix room identity. This PR adds a cross-platform normalized identity surface.
Related Issue
Related PR: #17702
No issue found for the narrower channel identity follow-up. Related search terms returned mostly unrelated i18n/gateway items.
Type of Change
Security hardening benefit: the prompt explicitly labels channel identity as untrusted transport metadata for routing, not user instructions.
Changes Made
gateway/session.py: adds compact deterministicSessionContext.channel_identity_jsonand renders it as JSON in the session context prompt.gateway/session.py: honors existing prompt PII redaction by hashing channel/thread/parent IDs whenredact_pii=True, and omitschannel_namewhen prompt PII redaction is active.gateway/session_context.py/gateway/run.py: exposesHERMES_SESSION_CHANNEL_IDENTITYthrough the existing contextvar-based session env path.tests/gateway/test_channel_identity.pyandtests/gateway/test_session_env.py: add regression coverage for prompt identity, redaction/escaping, deterministic JSON, untrusted-metadata wording, and contextvar exposure.How to Test
RED observed before implementation:
python -m pytest tests/gateway/test_channel_identity.py tests/gateway/test_session_env.py::test_set_session_env_includes_normalized_channel_identity -q -o 'addopts=' --tb=shortchannel_identity_json, and missingHERMES_SESSION_CHANNEL_IDENTITY.Targeted tests:
python -m pytest tests/gateway/test_session.py tests/gateway/test_session_env.py tests/gateway/test_channel_identity.py -q -o 'addopts=' --tb=short→ 93 passedpython -m pytest tests/gateway/test_channel_identity.py tests/gateway/test_session_env.py -q -o 'addopts='→ 16 passedStatic/syntax checks:
python -m py_compile gateway/session.py gateway/session_context.py gateway/run.py tests/gateway/test_channel_identity.py tests/gateway/test_session_env.pygit diff --checkFull-suite status:
Independent review:
Security / Platform Notes
redact_piiprompt redaction gate for raw channel/thread/parent IDs.channel_nameis omitted from the normalized channel identity block whenever prompt PII redaction is active.HERMES_SESSION_CHANNEL_IDENTITYis session-local viacontextvars, matching existing gateway session env behavior and avoiding concurrent-message cross-talk.example.org,channel-123,thread-456,parent-789).Checklist
Code
pytest tests/ -q.Documentation & Housekeeping
Review feedback remediation (2026-04-30)
pytest tests/ -qis explicitly not claimed.redact_pii=Truehashes stable channel/thread/parent IDs and omits human-readablechannel_name.Relationship to adjacent PRs
Builds on the room-identity behavior fixed in #17702 and adds the generic gateway/session layer: normalized channel identity is rendered in session context and exposed through session contextvars.
This PR does NOT resolve project/repo bindings and does NOT block tools. #17938 is the enforcement layer.