fix(matrix): preserve named room identity#17702
Closed
nepenth wants to merge 4 commits into
Closed
Conversation
This was referenced Apr 30, 2026
Contributor
Author
|
Superseded by #18505. The new Matrix foundation PR incorporates named-room identity preservation into a broader current-main branch with inbound dispatch reliability, DM vs named-room classification, room/session metadata, Matrix session-scope modes, project-room isolation tests, and /resume-/status-scope hardening. Closing this narrower branch to keep review focused on the updated foundation PR. |
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?
Fixes Matrix room identity resolution so Hermes preserves explicit room names before session routing. A room with two joined members is no longer treated as a DM unless Matrix
m.directaccount data identifies it as direct, and explicitly named rooms keep group context even if account data is stale or conflicting.Related Issue
No directly related issue/PR found in upstream search for Matrix room identity/session routing terms.
Type of Change
Changes Made
gateway/platforms/matrix.py: add internal Matrix room identity resolution before DM/group routing.gateway/platforms/matrix.py: remove the two-member-room DM heuristic and rely onm.directaccount data plus explicit room names.gateway/platforms/matrix.py: harden long-running adapter behavior by invalidating/reloading joined-room and DM cache state when needed, including newly joined rooms.tests/gateway/test_matrix_room_identity.py: add sanitizedexample.orgregression coverage for named rooms,m.directrooms, conflict handling, negative DM-cache reuse, empty-name fallback, dict state events, canonical aliases, non-stringm.directentries, and DM cache refresh after room joins.tests/gateway/test_matrix.py: update existing DM classification expectations for the corrected routing behavior.How to Test
Latest follow-up verification after DM cache refresh hardening:
python -m pytest tests/gateway/test_matrix_room_identity.py -q -o 'addopts='→ 12 passedpython -m py_compile gateway/platforms/matrix.py gateway/session.py→ passedgit diff --check→ passedEarlier broader targeted run on this PR line:
python -m pytest tests/gateway/test_matrix_room_identity.py tests/gateway/test_matrix.py -q -o 'addopts='previously covered the combined Matrix adapter regressions. I am not re-claiming a fresh all-green full-suite run here; the latest fresh verification above is the scoped identity/cache hardening test file.Security / Privacy Notes
example.orgMatrix-style fixtures only.Deferred Follow-ups / Non-goals
Review feedback remediation (2026-04-30)
_dm_cache_loadedis used so non-DM rooms do not repeatedly refreshm.directaccount data on every message.m.directcache parsing to ignore non-string room IDs instead of coercing unexpected values into strings.m.directentries.Relationship to follow-ups
This is the Matrix-specific foundation fix. It ensures named two-person Matrix project rooms are exposed as named rooms, not inferred DMs, before the model sees session context.
Follow-ups:
This PR intentionally does NOT add workspace binding or repo side-effect guards.