Skip to content

fix(matrix): preserve room ID casing in directory resolution (#19278)#19304

Closed
lailoo wants to merge 1 commit intoopenclaw:mainfrom
lailoo:fix/matrix-room-id-case-19278
Closed

fix(matrix): preserve room ID casing in directory resolution (#19278)#19304
lailoo wants to merge 1 commit intoopenclaw:mainfrom
lailoo:fix/matrix-room-id-case-19278

Conversation

@lailoo
Copy link
Copy Markdown
Contributor

@lailoo lailoo commented Feb 17, 2026

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

  • New test: preserves original casing for !-prefixed room ID
  • New test: preserves original casing for #-prefixed alias
  • New test: lowercases query for fuzzy room name search (existing behavior)
  • All 37 existing matrix tests pass
  • 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.

Copy link
Copy Markdown

@nikolasdehor nikolasdehor left a comment

Choose a reason for hiding this comment

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

Well-scoped fix for a real bug. Matrix room IDs (!AbCdEf:server) and aliases (#Room:server) are case-sensitive, but normalizeQuery() was lowercasing them, breaking per-room config lookups.

Review

  • Correct fix — Uses trim() instead of normalizeQuery() for structured identifiers (!-prefixed room IDs and #-prefixed aliases). Lowercasing is only applied for the fuzzy room-name search path where case-insensitive matching is appropriate.
  • Minimal change — The logic change is narrow: structured ID lookup preserves casing, fuzzy name search normalizes casing. This matches how Matrix identifiers actually work.
  • Good test coverage — Three regression tests covering room ID, alias, and mixed-case scenarios. All 37 existing matrix tests pass.
  • Changelog entry included — Good practice.

LGTM, merge-ready. Fixes #19278.

@Glucksberg
Copy link
Copy Markdown
Contributor

This could be relevant to what you're working on.

Several other PRs seem to address the same problem:

Both PRs fix issue #19278: Matrix per-room config (requireMention, autoReply) is silently ignored because room IDs are lowercased during config resolution but compared in original case at runtime, causing lookup failures.

Both approaches have merit — might be worth coordinating.

If any of these links don't look right, let me know and I'll correct them.

@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 28, 2026
@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
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: S stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Matrix: per-room requireMention/autoReply config ignored due to room ID case mismatch

4 participants