Skip to content

[Bug]: Matrix group chat resolves 'me/I' to wrong sender due to shared session displayName contamination #27355

@gucasbrg

Description

@gucasbrg

Describe the bug

In a Matrix group chat with multiple users, when User A sends a message containing a first-person pronoun ("me", "I"), the agent incorrectly resolves it to User B — the previous message sender in the same shared session.

To reproduce

  1. Configure Matrix channel with groupPolicy: "allowlist" and requireMention: true
  2. In a Matrix group room, Zhang sends: @bot review my recent code commits
  3. Bot correctly looks up Zhang's commits (session displayName is now set to Zhang)
  4. Bu sends: @bot show me my recent code commits
  5. Expected: Bot looks up Bu's commits
  6. Actual: Bot looks up Zhang's commits again

Root cause

Group chat sessions use a single shared key: agent:<agentId>:matrix:group:<roomId>. All users in the room share the same session context.

The Matrix plugin correctly includes sender identity in the message envelope (e.g., "Matrix message from Bu: ..."), but the session's displayName field gets overwritten by the last sender. The LLM then resolves first-person pronouns using the accumulated session context dominated by the previous user's conversation, rather than the current message's from field.

Difference from #4683

Issue #4683 (fixed in PR #4697) addressed displayName overwrite on outbound sends (when the bot uses the message tool). This bug is about inbound group messages where different senders contaminate the shared session's identity context.

Related issues

Suggested fix

One or more of:

  1. Implement per-user session isolation in group chats (groupScope: "per-sender" as requested in Feature: groupScope option to consolidate group sessions into main #7524)
  2. Pin the session's displayName to the current inbound message sender rather than persisting from the previous message
  3. Add stronger system prompt context that forces the LLM to use the from field of each message for identity resolution

Environment

  • Version: 2026.2.24
  • Channel: Matrix (built-in plugin)
  • OS: macOS (OrbStack Docker)
  • Model provider: Alibaba Bailian (Qwen3.5 Plus) — but this is model-agnostic, the issue is in session metadata
  • Group config: groupPolicy: "allowlist", requireMention: true
  • Session config: default (no dmScope or custom session settings)

Logs / screenshots

Session messages showing the contamination:

System: [2026-02-26 05:47:50 UTC] Matrix message from Zhang: review my recent code commits
-> Bot correctly reviews Zhang's commits

[Later, same session]
System: [2026-02-26 08:25:xx UTC] Matrix message from Bu: show me my recent code commits
-> Bot incorrectly shows: "Zhang's recent commits" (should be Bu's commits)

The from field correctly identifies each sender, but the LLM resolves "me" to the wrong user due to session context contamination.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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