Skip to content

fix(matrix): 2-member group rooms misclassified as DMs#17987

Closed
camopel wants to merge 1 commit intoopenclaw:mainfrom
camopel:fix/matrix-dm-group-misclassification
Closed

fix(matrix): 2-member group rooms misclassified as DMs#17987
camopel wants to merge 1 commit intoopenclaw:mainfrom
camopel:fix/matrix-dm-group-misclassification

Conversation

@camopel
Copy link
Copy Markdown

@camopel camopel commented Feb 16, 2026

Fixes #17771

Problem

Matrix rooms with exactly 2 members that are explicitly configured in the groups allowlist get misclassified as DMs. This happens because createDirectRoomTracker uses a memberCount === 2 heuristic 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) into createDirectRoomTracker. If a room ID is in that set, skip the DM classification entirely and return false immediately.

Changes

  • extensions/matrix/src/matrix/monitor/direct.ts — accept optional configuredGroupRoomIds set in options; check it as the first guard in isDirectMessage()
  • extensions/matrix/src/matrix/monitor/index.ts — collect room IDs from roomsConfig (excluding the "*" wildcard) and pass them to the tracker

Testing

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.groups are incorrectly classified as DMs by the memberCount === 2 heuristic in createDirectRoomTracker. 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.

  • The approach is sound: checking room config before applying the member-count heuristic is the right fix
  • Partial coverage: The configuredGroupRoomIds set is built from Object.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 to isDirectMessage, alias-keyed rooms won't match and will still be misclassified
  • The fix works correctly for rooms configured by internal ID or by short name (which gets resolved to an internal ID via resolveMatrixTargets)

Confidence Score: 3/5

  • This PR is safe to merge but has a gap in coverage for alias-configured rooms
  • The fix correctly addresses the case where rooms are configured by internal room ID or by short name that gets resolved, but misses the case where rooms are configured by full alias (e.g., #room:server). The code changes are small and non-breaking — worst case, alias-configured rooms behave the same as before the patch.
  • extensions/matrix/src/matrix/monitor/index.ts — the configuredGroupRoomIds set construction needs to account for alias keys vs. internal room IDs

Last 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!

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.
@openclaw-barnacle openclaw-barnacle bot added channel: matrix Channel integration: matrix size: XS labels Feb 16, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +261 to +263
configuredGroupRoomIds: new Set(
roomsConfig ? Object.keys(roomsConfig).filter((k) => k !== "*") : [],
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Matrix: 2-member rooms in groups allowlist incorrectly classified as DMs

1 participant