openclaw/extensions
Bronko d4a960fcca
fix(matrix): restore robust DM routing without the memberCount heuristic (#19736)
* fix(matrix): remove memberCount heuristic from DM detection

The memberCount === 2 check in isDirectMessage() misclassifies 2-person
group rooms (admin channels, monitoring rooms) as DMs, routing them to
the main session instead of their room-specific session.

Matrix already distinguishes DMs from groups at the protocol level via
m.direct account data and is_direct member state flags. Both are already
checked by client.dms.isDm() and hasDirectFlag(). The memberCount
heuristic only adds false positives for 2-person groups.

Move resolveMemberCount() below the protocol-level checks so it is only
reached for rooms not matched by m.direct or is_direct. This narrows its
role to diagnostic logging for confirmed group rooms.

Refs: #19739

* fix(matrix): add conservative fallback for broken DM flags

Some homeservers (notably Continuwuity) have broken m.direct account
data or never set is_direct on invite events. With the memberCount
heuristic removed, these DMs are no longer detected.

Add a conservative fallback that requires two signals before classifying
as DM: memberCount === 2 AND no explicit m.room.name. Group rooms almost
always have explicit names; DMs almost never do.

Error handling distinguishes M_NOT_FOUND (missing state event, expected
for unnamed rooms) from network/auth errors. Non-404 errors fall through
to group classification rather than guessing.

This is independently revertable — removing this commit restores pure
protocol-based detection without any heuristic fallback.

* fix(matrix): add parentPeer for DM room binding support

Add parentPeer to DM routes so conversations are bindable by room ID
while preserving DM trust semantics (secure 1:1, no group restrictions).

Suggested by @KirillShchetinin.

* fix(matrix): override DM detection for explicitly configured rooms

Builds on @robertcorreiro's config-driven approach from #9106.

Move resolveMatrixRoomConfig() before the DM check. If a room matches
a non-wildcard config entry (matchSource === "direct") and was
classified as DM, override the classification to group. This gives users
a deterministic escape hatch for misclassified rooms.

Wildcards are excluded from the override to avoid breaking DM routing
when a "*" catch-all exists. roomConfig is gated behind isRoom so DMs
never inherit group settings (skills, systemPrompt, autoReply).

This commit is independently droppable if the scope is too broad.

* test(matrix): add DM detection and config override tests

- 15 unit tests for direct.ts: all detection paths, priority order,
  M_NOT_FOUND vs network error handling, edge cases (whitespace names,
  API failures)
- 8 unit tests for rooms.ts: matchSource classification, wildcard
  safety for DM override, direct match priority over wildcard

* Changelog: note matrix DM routing follow-up

* fix(matrix): preserve DM fallback and room bindings

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
2026-03-08 23:26:48 -05:00
..
acpx chore(acpx): move runtime test fixtures to test-utils (openclaw#40548) 2026-03-08 22:47:04 -05:00
bluebubbles fix(plugin-sdk): remove remaining bundled plugin src imports (openclaw#39638) 2026-03-08 22:32:45 -05:00
copilot-proxy build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
device-pair Plugins/device-pair: migrate to scoped plugin-sdk imports 2026-03-04 02:35:12 -05:00
diagnostics-otel build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
diffs build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
discord refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
feishu refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
google-gemini-cli-auth build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
googlechat refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
imessage refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
irc refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
line refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
llm-task build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
lobster build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
matrix fix(matrix): restore robust DM routing without the memberCount heuristic (#19736) 2026-03-08 23:26:48 -05:00
mattermost fix(plugin-sdk): remove remaining bundled plugin src imports (openclaw#39638) 2026-03-08 22:32:45 -05:00
memory-core build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
memory-lancedb build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
minimax-portal-auth build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
msteams refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
nextcloud-talk fix(plugin-sdk): remove remaining bundled plugin src imports (openclaw#39638) 2026-03-08 22:32:45 -05:00
nostr refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
open-prose build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
phone-control feature(context): extend plugin system to support custom context management (#22201) 2026-03-06 05:31:59 -08:00
qwen-portal-auth refactor(extensions): reuse shared helper primitives 2026-03-07 10:41:05 +00:00
shared fix(acpx): share windows wrapper resolver and add strict hardening mode 2026-03-01 23:57:06 +00:00
signal refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
slack refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
synology-chat refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
talk-voice fix(discord): avoid native plugin command collisions 2026-03-07 21:59:44 +00:00
telegram refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
test-utils fix: land #33992 from @darkamenosa 2026-03-08 04:49:04 +00:00
thread-ownership Plugins/thread-ownership: migrate to scoped plugin-sdk imports 2026-03-04 02:35:13 -05:00
tlon refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
twitch fix(plugin-sdk): remove remaining bundled plugin src imports (openclaw#39638) 2026-03-08 22:32:45 -05:00
voice-call build: bump version to 2026.3.8 2026-03-08 05:59:04 +00:00
whatsapp refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
zalo refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00
zalouser refactor: harden browser runtime profile handling 2026-03-09 00:25:43 +00:00