#9106: fix(matrix): override DM detection for rooms in groups config
channel: matrix
stale
Cluster:
Matrix Room Management Enhancements
## Summary
Rooms with exactly 2 members (user + bot) are incorrectly classified as DMs by the member-count heuristic in `direct.ts`, even when explicitly configured in `channels.matrix.groups`. This causes them to route to the user's DM session instead of the intended room-specific agent.
Fixes #7718
## Changes
**`extensions/matrix/src/matrix/monitor/handler.ts`**
- Move `resolveMatrixRoomConfig()` before the DM classification check
- If the room is present in the groups config, override `isDirectMessage` to `false`
- This ensures rooms in the config always receive group treatment regardless of member count
## Testing
Deployed to production with 3 private rooms (2 members each: user + bot) configured in `channels.matrix.groups`. Confirmed:
- Rooms route to their configured agents via `bindings` (not the DM agent)
- `requireMention: false` works correctly on group-overridden rooms
- Standard DMs still route correctly to per-user agents
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change moves `resolveMatrixRoomConfig()` earlier in the Matrix inbound handler and uses it to override direct-message detection so that rooms explicitly configured under `channels.matrix.groups` are always treated as group rooms, avoiding the 2-member heuristic in `direct.ts`.
One issue to fix before merge: the override currently triggers for any resolved config, including `"*"` wildcard matches. Because wildcard configs can be used to disable/deny rooms by default, this can cause true DMs to be reclassified as rooms and dropped by the room allowlist/disabled checks, breaking DM routing when a wildcard entry exists.
<h3>Confidence Score: 2/5</h3>
- This PR should not merge until the DM override condition is narrowed to avoid wildcard group configs breaking DM routing.
- The change correctly addresses misclassification of configured 2-member rooms, but the new override (`roomConfigInfo?.config`) also applies to wildcard matches, which can reclassify real DMs as rooms and then drop them via the room allowlist/disabled logic.
- extensions/matrix/src/matrix/monitor/handler.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13451: feat(matrix): add forceRoomRouting to bypass DM detection for allow...
by yamoroc · 2026-02-10
83.2%
#19736: fix(matrix): remove memberCount heuristic from DM detection
by derbronko · 2026-02-18
79.8%
#10606: fix(matrix): keep room IDs without :server suffix as-is during reso...
by majorminors · 2026-02-06
78.2%
#13057: feat(matrix): add sessionScope=room to route sessions by roomId
by spengrah · 2026-02-10
77.8%
#19388: Fix #19278: Case-insensitive Matrix room ID matching
by cedillarack · 2026-02-17
76.4%
#19294: fix: normalize room ID case in Matrix config lookup
by MisterGuy420 · 2026-02-17
75.0%
#19435: fix(slack): properly handle group DM (MPIM) events
by Utkarshbhimte · 2026-02-17
72.9%
#19304: fix(matrix): preserve room ID casing in directory resolution (#19278)
by lailoo · 2026-02-17
72.6%
#17276: docs(matrix): add warning about dm.allowFrom requirement for commands
by norci · 2026-02-15
72.0%
#13832: feat(matrix): add sessionScope and thread-scoped inbound sessions
by yamoroc · 2026-02-11
71.0%