Skip to content

fix(matrix): preserve named room identity#17702

Closed
nepenth wants to merge 4 commits into
NousResearch:mainfrom
nepenth:fix/matrix-room-identity
Closed

fix(matrix): preserve named room identity#17702
nepenth wants to merge 4 commits into
NousResearch:mainfrom
nepenth:fix/matrix-room-identity

Conversation

@nepenth

@nepenth nepenth commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

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.direct account 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

  • Bug fix
  • Tests

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 on m.direct account 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 sanitized example.org regression coverage for named rooms, m.direct rooms, conflict handling, negative DM-cache reuse, empty-name fallback, dict state events, canonical aliases, non-string m.direct entries, 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 passed
  • python -m py_compile gateway/platforms/matrix.py gateway/session.py → passed
  • git diff --check → passed

Earlier 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

  • No credentials, subprocess execution, filesystem migrations, or storage schema changes.
  • Tests use sanitized example.org Matrix-style fixtures only.
  • Newly added runtime warning/debug logs avoid printing Matrix room IDs or room names.
  • This PR intentionally does not expose expanded channel metadata; normalized channel identity is deferred to a follow-up PR.

Deferred Follow-ups / Non-goals

  • Exposing normalized channel identity in gateway session context.
  • Workspace registry for channel-to-project bindings.
  • Guarding repo side effects with workspace bindings.

Review feedback remediation (2026-04-30)

  • Confirmed _dm_cache_loaded is used so non-DM rooms do not repeatedly refresh m.direct account data on every message.
  • Hardened m.direct cache parsing to ignore non-string room IDs instead of coercing unexpected values into strings.
  • Added regression coverage for non-string m.direct entries.
  • Added DM cache refresh hardening for newly joined/invalidated rooms so long-running Matrix adapters do not keep stale DM classification forever.
  • Updated the test plan to remove stale/malformed counts and show the latest fresh 12-test identity/cache verification.

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.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround platform/matrix Matrix adapter (E2EE) comp/gateway Gateway runner, session dispatch, delivery labels Apr 30, 2026
@nepenth

nepenth commented May 1, 2026

Copy link
Copy Markdown
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.

@nepenth nepenth closed this May 1, 2026
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 platform/matrix Matrix adapter (E2EE) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants