#19304: fix(matrix): preserve room ID casing in directory resolution (#19278)
channel: matrix
size: S
experienced-contributor
Cluster:
Matrix Room Management Enhancements
## Summary
- **Bug**: Per-room Matrix config (requireMention, autoReply) silently ignored due to room ID case mismatch
- **Root cause**: `normalizeQuery()` in `directory-live.ts` lowercases room IDs/aliases before returning them, but `resolveChannelEntryMatch()` performs exact-case lookup at runtime
- **Fix**: Preserve original casing for `!`-prefixed room IDs and `#`-prefixed aliases; only lowercase for fuzzy name search
Fixes #19278
## Problem
When a user configures a Matrix room by its room ID (e.g. `!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org`), the directory resolution step in `listMatrixDirectoryGroupsLive()` passes the query through `normalizeQuery()` which calls `.toLowerCase()`. The lowercased ID becomes the key in the internal `roomsConfig` map.
At runtime, Matrix events arrive with the original-case room ID. `resolveMatrixRoomConfig()` builds lookup candidates using this original-case ID and calls `resolveChannelEntryMatch()`, which uses `Object.prototype.hasOwnProperty.call(entries, key)` — an exact-case match. The lookup fails because `!araqdbw5...` ≠ `!ArAQdbw5...`.
**Before fix:**
```
Input: "!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org"
Output: "!araqdbw5b42r5ubhuwz84xs6gi:matrix.org" (lowercased)
Config lookup: MISS → requireMention defaults to true
```
## Changes
- `extensions/matrix/src/directory-live.ts` — Use `trim()` instead of `normalizeQuery()` for the `!` and `#` code paths, preserving original casing. Only apply `toLowerCase()` for the fuzzy room-name search path where case-insensitive comparison is needed.
- `extensions/matrix/src/directory-live.test.ts` — Add regression tests for room ID case preservation, alias case preservation, and fuzzy search lowercasing.
- `CHANGELOG.md` — Add fix entry.
**After fix:**
```
Input: "!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org"
Output: "!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org" (preserved)
Config lookup: HIT → requireMention: false applied correctly
```
## Test plan
- [x] New test: preserves original casing for `!`-prefixed room ID
- [x] New test: preserves original casing for `#`-prefixed alias
- [x] New test: lowercases query for fuzzy room name search (existing behavior)
- [x] All 37 existing matrix tests pass
- [x] Lint passes
## Effect on User Experience
**Before:** Per-room settings like `requireMention: false` and `autoReply: true` are silently ignored for Matrix rooms configured by room ID. The bot requires a mention even when configured not to.
**After:** Per-room settings are applied correctly regardless of room ID casing.
Most Similar PRs
#19388: Fix #19278: Case-insensitive Matrix room ID matching
by cedillarack · 2026-02-17
85.9%
#19294: fix: normalize room ID case in Matrix config lookup
by MisterGuy420 · 2026-02-17
81.0%
#10606: fix(matrix): keep room IDs without :server suffix as-is during reso...
by majorminors · 2026-02-06
80.3%
#9106: fix(matrix): override DM detection for rooms in groups config
by robertcorreiro · 2026-02-04
72.6%
#13451: feat(matrix): add forceRoomRouting to bypass DM detection for allow...
by yamoroc · 2026-02-10
72.6%
#13057: feat(matrix): add sessionScope=room to route sessions by roomId
by spengrah · 2026-02-10
71.9%
#7842: Fix Matrix mention detection for Element client (formatted_body links)
by emadomedher · 2026-02-03
68.3%
#7845: Fix Matrix mention detection with URL-encoded user IDs
by emadomedher · 2026-02-03
68.3%
#13832: feat(matrix): add sessionScope and thread-scoped inbound sessions
by yamoroc · 2026-02-11
68.0%
#23333: fix(matrix): add accountId routing for multi-account message sending 🤖
by BadTurki · 2026-02-22
67.5%