fix(matrix): 2-member group rooms misclassified as DMs#17987
fix(matrix): 2-member group rooms misclassified as DMs#17987camopel wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Fixes #17771 Rooms explicitly listed in the groups allowlist config were still being classified as DMs when they had exactly 2 members, because the memberCount===2 heuristic in createDirectRoomTracker ran before checking the config. Pass the set of configured group room IDs into the direct room tracker and skip the DM check entirely for those rooms.
| configuredGroupRoomIds: new Set( | ||
| roomsConfig ? Object.keys(roomsConfig).filter((k) => k !== "*") : [], | ||
| ), |
There was a problem hiding this comment.
Alias-keyed rooms won't match at runtime
The roomsConfig keys can be room aliases (e.g., #openclaw:matrix.org) when the user configures them that way — these are kept as-is by the resolution logic at lines 155–157. However, isDirectMessage receives the internal room ID (!xxx:server) from the Matrix SDK, so configuredGroupRoomIds.has(roomId) will never match an alias-keyed entry.
This means the fix only works when the config contains !-prefixed internal room IDs or short names that get resolved via resolveMatrixTargets. Rooms configured by full alias (#name:server) will still be misclassified as DMs.
Consider filtering only !-prefixed keys, or resolving aliases to internal room IDs before building this set.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/matrix/src/matrix/monitor/index.ts
Line: 261:263
Comment:
**Alias-keyed rooms won't match at runtime**
The `roomsConfig` keys can be room aliases (e.g., `#openclaw:matrix.org`) when the user configures them that way — these are kept as-is by the resolution logic at lines 155–157. However, `isDirectMessage` receives the internal room ID (`!xxx:server`) from the Matrix SDK, so `configuredGroupRoomIds.has(roomId)` will never match an alias-keyed entry.
This means the fix only works when the config contains `!`-prefixed internal room IDs or short names that get resolved via `resolveMatrixTargets`. Rooms configured by full alias (`#name:server`) will still be misclassified as DMs.
Consider filtering only `!`-prefixed keys, or resolving aliases to internal room IDs before building this set.
How can I resolve this? If you propose a fix, please make it concise.
Fixes #17771
Problem
Matrix rooms with exactly 2 members that are explicitly configured in the
groupsallowlist get misclassified as DMs. This happens becausecreateDirectRoomTrackeruses amemberCount === 2heuristic that runs before any config awareness — so a 2-person group channel gets routed as a DM session instead of a group session.Fix
Pass the set of configured group room IDs (from
channels.matrix.groups) intocreateDirectRoomTracker. If a room ID is in that set, skip the DM classification entirely and returnfalseimmediately.Changes
extensions/matrix/src/matrix/monitor/direct.ts— accept optionalconfiguredGroupRoomIdsset in options; check it as the first guard inisDirectMessage()extensions/matrix/src/matrix/monitor/index.ts— collect room IDs fromroomsConfig(excluding the"*"wildcard) and pass them to the trackerTesting
Tested with a 2-member Matrix room (
#openclaw) in the groups config — correctly classified as group after the patch, was incorrectly classified as DM before.Greptile Summary
This PR fixes a bug where 2-member Matrix group rooms configured in
channels.matrix.groupsare incorrectly classified as DMs by thememberCount === 2heuristic increateDirectRoomTracker. The fix passes a set of configured group room IDs into the tracker so they can be excluded from DM classification as the first check.configuredGroupRoomIdsset is built fromObject.keys(roomsConfig), but after resolution these keys can be room aliases (#name:server) rather than internal room IDs (!xxx:server). Since the Matrix SDK always provides internal!-prefixed room IDs toisDirectMessage, alias-keyed rooms won't match and will still be misclassifiedresolveMatrixTargets)Confidence Score: 3/5
extensions/matrix/src/matrix/monitor/index.ts— theconfiguredGroupRoomIdsset construction needs to account for alias keys vs. internal room IDsLast reviewed commit: cb50d35
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!