#19736: fix(matrix): remove memberCount heuristic from DM detection
channel: matrix
size: XS
Cluster:
Matrix Room Management Enhancements
## What
Removes the `memberCount === 2` early-return in `isDirectMessage()` that misclassifies 2-person group rooms as DMs. Moves `resolveMemberCount()` to after the DM checks (diagnostic logging only).
## Why
Matrix already distinguishes DMs from groups at the protocol level:
- [`m.direct` account data](https://spec.matrix.org/v1.12/client-server-api/#mdirect) — set when creating a DM
- [`is_direct` on `m.room.member`](https://spec.matrix.org/v1.12/client-server-api/#mroommember) — set on the invite event
Both are already checked by `client.dms.isDm()` and `hasDirectFlag()`. The `memberCount === 2` heuristic fires between these proper checks and short-circuits with false positives for any 2-person group room (admin channels, monitoring rooms, etc.).
## Change
**File:** `extensions/matrix/src/matrix/monitor/direct.ts`
1. Remove the `memberCount === 2` block (lines 86-90)
2. Move `resolveMemberCount()` to after the DM checks — now only runs for confirmed group rooms (diagnostic logging), avoiding an unnecessary API call for every DM
## Edge Cases
| Scenario | m.direct | is_direct | Caught by | Still works? |
|----------|----------|-----------|-----------|:---:|
| Normal DM | ✅ | ✅ | `client.dms.isDm()` | ✅ |
| DM without m.direct | ❌ | ✅ | `hasDirectFlag()` | ✅ |
| DM without is_direct | ✅ | ❌ | `client.dms.isDm()` | ✅ |
| **2-person group** | **❌** | **❌** | **None (correct!)** | **✅ fixed** |
No DM detection is lost. Only false positives are removed.
Fixes #7718
Most Similar PRs
#9106: fix(matrix): override DM detection for rooms in groups config
by robertcorreiro · 2026-02-04
79.8%
#13451: feat(matrix): add forceRoomRouting to bypass DM detection for allow...
by yamoroc · 2026-02-10
67.9%
#19304: fix(matrix): preserve room ID casing in directory resolution (#19278)
by lailoo · 2026-02-17
63.9%
#10606: fix(matrix): keep room IDs without :server suffix as-is during reso...
by majorminors · 2026-02-06
63.4%
#19435: fix(slack): properly handle group DM (MPIM) events
by Utkarshbhimte · 2026-02-17
60.7%
#19388: Fix #19278: Case-insensitive Matrix room ID matching
by cedillarack · 2026-02-17
59.6%
#13057: feat(matrix): add sessionScope=room to route sessions by roomId
by spengrah · 2026-02-10
59.5%
#17276: docs(matrix): add warning about dm.allowFrom requirement for commands
by norci · 2026-02-15
59.0%
#19294: fix: normalize room ID case in Matrix config lookup
by MisterGuy420 · 2026-02-17
57.8%
#6518: feat(matrix): add inbound message debouncing
by Klowalski · 2026-02-01
57.7%