Skip to content

fix(matrix): remove member-count fallback from DM detection#30842

Closed
arkyu2077 wants to merge 1 commit intoopenclaw:mainfrom
arkyu2077:fix/issue-30645-matrix-dm-heuristic
Closed

fix(matrix): remove member-count fallback from DM detection#30842
arkyu2077 wants to merge 1 commit intoopenclaw:mainfrom
arkyu2077:fix/issue-30645-matrix-dm-heuristic

Conversation

@arkyu2077
Copy link
Copy Markdown
Contributor

Problem

createDirectRoomTracker falls back to treating any 2-person room as a DM based solely on memberCount === 2. This conflicts with the Matrix spec, which designates DMs via explicit m.direct account data and is_direct member state.

When a user has multiple 2-person rooms with the same participants (e.g., a bot room and a topic-specific room), both are incorrectly classified as DMs, causing duplicate or out-of-context message routing.

Fix

Remove the memberCount === 2 fallback from isDirectMessage(). DM detection now relies only on:

  1. client.dms.isDm() — checks m.direct account data
  2. hasDirectFlag() — checks is_direct on m.room.member state events

This aligns with the Matrix spec and prevents false-positive DM classification of regular 2-person rooms.

Closes #30645

The DM heuristic treated any 2-person room as a direct message based
solely on member count. This conflicts with the Matrix spec which uses
explicit m.direct account data and is_direct member state to designate
DMs. When a user has multiple 2-person rooms with the same participants,
all were incorrectly classified as DMs, causing duplicate or
out-of-context message routing.

Remove the memberCount === 2 fallback and rely only on m.direct and
is_direct member state for DM detection.

Closes openclaw#30645
@openclaw-barnacle openclaw-barnacle bot added channel: matrix Channel integration: matrix size: XS labels Mar 1, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d029220ce7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +94 to 96
const memberCount = await resolveMemberCount(roomId);
log(`matrix: dm check room=${roomId} result=group members=${memberCount ?? "unknown"}`);
return false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep 2-member rooms classified as DM fallback

This change makes isDirectMessage return false for any room where both client.dms.isDm() and is_direct state checks fail, even when the room has exactly two joined members. That creates a regression for valid 1:1 rooms when m.direct is absent or stale (a case already expected elsewhere: extensions/matrix/src/matrix/send/targets.ts explicitly treats missing m.direct as common and falls back to 2-member room discovery), so inbound DMs in those rooms can now be treated as group traffic and blocked by default group policy.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 1, 2026

Greptile Summary

Removes the non-spec-compliant memberCount === 2 fallback from DM detection logic, ensuring rooms are only classified as DMs when they have proper Matrix spec markers (m.direct account data or is_direct member state flags).

Key changes:

  • DM detection now relies exclusively on spec-compliant methods: client.dms.isDm() and hasDirectFlag()
  • Member count fetching moved to end of function for logging purposes only
  • Prevents false-positive DM classification of regular 2-person rooms

Impact:

  • Fixes issue where multiple 2-person rooms with same participants were incorrectly treated as DMs
  • Aligns with Matrix specification for direct message designation
  • Minor performance improvement: member count API call now skipped when room matches via is_direct flags

Confidence Score: 5/5

Last reviewed commit: d029220

@steipete
Copy link
Copy Markdown
Contributor

steipete commented Mar 2, 2026

Thanks for the work here.

This is now superseded by #31023 (merged in commit 84d0a79), which shipped the Matrix Conduit compatibility/routing fixes in main.

Closing this PR to keep the queue clean.

@steipete steipete closed this Mar 2, 2026
@private-peter
Copy link
Copy Markdown
Contributor

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.

[Bug]: bug(matrix): 2-person rooms incorrectly classified as DMs, causing message routing confusion

3 participants