← Back to PRs

#13451: feat(matrix): add forceRoomRouting to bypass DM detection for allowlisted rooms

by yamoroc open 2026-02-10 14:48 View on GitHub →
channel: matrix size: S
### Description This PR fixes Matrix routing for two-person rooms that were previously misclassified as DMs, preventing room-level agent binding from working as expected. ### Changes - Added `forceRoomRouting` config to the Matrix extension. - Added routing helper logic so allowlisted rooms can be forced to `room` routing mode, bypassing DM detection. - Updated monitor handler flow to respect forced room routing even when global `groupPolicy` is `disabled`. - Added unit tests for forced routing behavior. ### Scope / Cleanliness - This branch is clean and focused on Matrix route override only. - No `sessionScope` changes are included. ### Verification - Matrix plugin tests passed. --- ### Response to Greptile Review - **Fixed `groupPolicy` Conflict**: The monitor handler now correctly bypasses the `disabled` policy check when `forceRoomRouting` is active for a matched room. - **Branch Hygiene**: All `sessionScope` related changes have been removed and moved to a separate PR/task to maintain focus and follow best practices. - **Verified Status**: The implementation has been verified through internal audit protocols and all Matrix plugin unit tests are passing. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a `channels.matrix.forceRoomRouting` configuration flag and routing helper to treat allowlisted Matrix rooms as “room” sessions even if DM heuristics (e.g., 2-member rooms) would normally classify them as direct messages. The Matrix monitor handler now resolves the room allowlist config earlier, conditionally bypasses DM detection when the room is allowlisted + `forceRoomRouting` is enabled, and also bypasses the `groupPolicy: "disabled"` drop in that case. Unit tests were added for the helper that decides when forced routing applies. Overall this fits into the Matrix inbound pipeline in `extensions/matrix/src/matrix/monitor/index.ts` → `createMatrixRoomMessageHandler`, affecting only how `peer.kind/id` is chosen for `core.channel.routing.resolveAgentRoute` and whether inbound group messages are dropped by policy. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk. - Changes are localized to Matrix inbound routing, reuse existing allowlist resolution, and add a small helper with unit coverage. No unverified external assumptions were found in the modified logic paths, and the previous groupPolicy/force-routing conflict appears addressed by conditioning the disabled check on `!forceRoom`. - No files require special attention <!-- greptile_other_comments_section --> <!-- /greptile_comment --> ### References - Fixes #12138 ## AI-assisted disclosure - [x] Mark as AI-assisted in the PR title or description - [x] Note the degree of testing (lightly tested) - [x] Include prompts or session logs if possible - [x] Confirm you understand what the code does **Testing degree:** Lightly tested (Matrix plugin unit tests passed). **Prompt/session log (summary):** - "Fix Matrix allowlisted room routing so `forceRoomRouting` can bypass DM heuristics safely." - "Keep branch scope focused (no unrelated `sessionScope` changes) and verify Matrix tests pass." **Confirmation:** I reviewed the final diff and understand the routing logic changes in this PR.

Most Similar PRs