fix(matrix): propagate room name from room state to session source#38807
Open
adaofeliz wants to merge 4 commits into
Open
fix(matrix): propagate room name from room state to session source#38807adaofeliz wants to merge 4 commits into
adaofeliz wants to merge 4 commits into
Conversation
_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
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>
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.
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.
Summary
Two one-line fixes in
gateway/platforms/matrix.pyto ensure Matrix rooms are identifiable in session context:Fix 1 (first commit):
_resolve_message_context()now callsget_chat_info()to resolve the Matrix room name fromm.room.namestate and passeschat_name+chat_typetobuild_source(). Previously these were omitted — every room showed as the sender display name.Fix 2 (second commit):
get_chat_info()now overrideschat_typeto"group"when a room hasm.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_namewhen building session sources. Even after fix 1 propagated the room name,session.pyignoredchat_nameforchat_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)
"dm""DM with AVP"(unchanged)"group""group: Development""group""group: Homeassistant"Design consistency
chat_namesourcedata.get("chatName")chat.titleget_chat_info()→m.room.nameSession migration
chat_typeis"group"for named rooms.chat_type="dm"baked into the session key and data. They must be deleted for the fix to take effect.sessions.jsonandchannel_directory.jsonwill auto-rebuild on next messages.To apply on an existing deployment:
Verification
~/.hermes/sessions/sessions.json— origin should showchat_type: "group"and correctdisplay_name"Source: Matrix (group: Development)"instead of"Source: Matrix (DM with AVP)"Closes #38805