Skip to content

Matrix: 2-member rooms incorrectly routed as DMs to main session #7718

@andrewmurphyio

Description

@andrewmurphyio

Description

Matrix rooms with exactly 2 members (user + bot) are being classified as DMs and routed to the main session instead of getting their own isolated group session.

Expected Behavior

A Matrix room (not a DM) should always route to its own session with key agent:main:matrix:channel:<roomId>, regardless of member count.

Actual Behavior

The isDirectMessage check in extensions/matrix/src/matrix/monitor/direct.ts has an aggressive heuristic:

const memberCount = await resolveMemberCount(roomId);
if (memberCount === 2) {
  log(`matrix: dm detected via member count room=${roomId} members=${memberCount}`);
  return true;
}

This causes 2-member rooms to be treated as DMs, routing them to the main session (agent:main:main) instead of creating a separate room session.

Reproduction

  1. Create a Matrix room (not a DM)
  2. Invite only the bot (2 total members: you + bot)
  3. Send a message in the room
  4. Observe it arrives in the main session (shared with DMs, WhatsApp, etc.) instead of an isolated room session

Impact

  • Context bleeds between Matrix rooms and DMs
  • Private room conversations visible in main session history
  • No isolation for 2-member rooms

Suggested Fix

The member count heuristic should be removed or made opt-in. Rooms should be distinguished from DMs using Matrix's actual DM indicators (m.direct account data, is_direct state) rather than member count.

Alternatively, add a config option like channels.matrix.strictDmDetection: true to disable the member count heuristic.

Environment

  • OpenClaw version: 2026.1.29
  • Matrix plugin: bundled (extensions/matrix)
  • Homeserver: Synapse (self-hosted)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions