Skip to content

fix(matrix): propagate room name from room state to session source#38807

Open
adaofeliz wants to merge 4 commits into
NousResearch:mainfrom
adaofeliz:fix/matrix-room-name-session-source
Open

fix(matrix): propagate room name from room state to session source#38807
adaofeliz wants to merge 4 commits into
NousResearch:mainfrom
adaofeliz:fix/matrix-room-name-session-source

Conversation

@adaofeliz

@adaofeliz adaofeliz commented Jun 4, 2026

Copy link
Copy Markdown

Summary

Two one-line fixes in gateway/platforms/matrix.py to ensure Matrix rooms are identifiable in session context:

Fix 1 (first commit): _resolve_message_context() now calls get_chat_info() to resolve the Matrix room name from m.room.name state and passes chat_name + chat_type to build_source(). Previously these were omitted — every room showed as the sender display name.

Fix 2 (second commit): get_chat_info() now overrides chat_type to "group" when a room has m.room.name. A named Matrix room is semantically a workspace, not a personal DM, regardless of member count.

Together these ensure named rooms appear as "group: RoomName" in session source descriptions instead of the generic "DM with AVP".

Problem

The Matrix adapter was omitting chat_name when building session sources. Even after fix 1 propagated the room name, session.py ignored chat_name for chat_type="dm" rooms. Since all self-hosted Matrix rooms are 2-person (user + bot), _is_dm_room() returned True for every room — making all rooms appear identical in the system prompt.

Data flow (after both fixes)

Matrix message arrives in "Development" room
  → _resolve_message_context()
    → get_chat_info(room_id)
      → _is_dm_room() → True → chat_type = "dm"
      → get_state_event(m.room.name) → "Development"
      → name = "Development"
      → chat_type = "group"  ← FIX 2: named room = workspace
    → build_source(chat_name="Development", chat_type="group")
  → SessionSource.description → "group: Development"
  → Agent prompt: "Source: Matrix (group: Development)"
Room Members Has m.room.name? chat_type Prompt shows
Actual DM with user 2 No "dm" "DM with AVP" (unchanged)
Development 2 Yes "group" "group: Development"
Homeassistant 2 Yes "group" "group: Homeassistant"

Design consistency

Adapter chat_name source
WhatsApp data.get("chatName")
Telegram chat.title
Matrix (before) (omitted)
Matrix (after) get_chat_info()m.room.name

Session migration

  • New sessions: Immediately correct — chat_type is "group" for named rooms.
  • Existing sessions: Have chat_type="dm" baked into the session key and data. They must be deleted for the fix to take effect. sessions.json and channel_directory.json will auto-rebuild on next messages.
  • No data loss: Honcho memory, local memory, skills, config, and cron jobs are untouched.

To apply on an existing deployment:

systemctl --user stop hermes-gateway
rm ~/.hermes/sessions/sessions.json
rm ~/.hermes/sessions/session_*.json    # optional: individual session traces
rm ~/.hermes/channel_directory.json
systemctl --user start hermes-gateway

Verification

  1. Send a message from a named Matrix room (Development, Homeassistant, etc.)
  2. Check ~/.hermes/sessions/sessions.json — origin should show chat_type: "group" and correct display_name
  3. Agent system prompt should show "Source: Matrix (group: Development)" instead of "Source: Matrix (DM with AVP)"

Closes #38805

_match_message_context() now calls get_chat_info() to resolve the
Matrix room name from m.room.name state and passes it to build_source().
Previously chat_name was omitted, causing all rooms to show as the
sender display name (e.g., "AVP") in channel_directory.json.

Matches the pattern already used by WhatsApp (data.get("chatName"))
and Telegram (chat.title) adapters.

Fixes NousResearch#38805
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/matrix Matrix adapter (E2EE) comp/gateway Gateway runner, session dispatch, delivery labels Jun 4, 2026
When a Matrix room has a m.room.name state event, it is semantically a
workspace — not a personal DM — regardless of member count. This causes
get_chat_info() to return chat_type="group" for named rooms.

Together with the previous commit (propagating chat_name to build_source),
this ensures named Matrix rooms appear as "group: RoomName" in the
session source description instead of "DM with AVP" — enabling the agent
to immediately identify which room it is operating in at session start.

Named rooms (Development, Homeassistant, Clipping, etc.) → "group"
Actual personal DMs (no m.room.name) → stay "dm" (unchanged)

Refs NousResearch#38805
Two test locations needed the get_chat_info mock after the production
code was updated to call it in _resolve_message_context():

- TestMatrixReadReceipts.test_accepted_message_schedules_read_receipt
- TestMatrixDmAutoThread.setup_method

Co-authored-by: alaamohanad169-ship-it <alaamohanad169@example.com>
Signed-off-by: Adão <avp@powerdot.pt>
@adaofeliz

Copy link
Copy Markdown
Author

This PR is Ready for review.

Switch from direct key access to .get() with defaults when
reading chat_info from get_chat_info(). The method always
returns both keys, but .get() protects against a future
refactor that might omit one.
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 P2 Medium — degraded but workaround exists platform/matrix Matrix adapter (E2EE) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Matrix adapter: room name not propagated to session source (shows generic user_name for all rooms)

3 participants