Skip to content

[Bug]: MSTeams DM replies leak to team channel — lastChannel routing race + reply_to_current fragility #54520

@staroscott

Description

@staroscott

Summary

When an OpenClaw agent is connected to Microsoft Teams with both DM and channel conversations active, DM replies intermittently leak to a team channel instead of routing back to the originating DM. This appears to be the same lastChannel routing race documented in #45514 and #13332, but specific to the MSTeams plugin.

Additionally, the [[reply_to_current]] tag is fragile for DMs — if the agent produces any text on a separate line after the tag, that trailing content has no routing context and falls through to the default (public) channel.

Steps to Reproduce

  1. Configure MSTeams with an agent that has both DM and team channel conversations active
  2. User sends a DM to the agent
  3. Agent processes and replies
  4. Reply sometimes appears in the team channel instead of the DM

This is intermittent — it correlates with the team channel being the most recently active surface.

Expected Behavior

DM replies should always route back to the originating DM conversation, regardless of which surface was most recently active.

Actual Behavior

  • Gateway-level: Reply routes to lastChannel (the team channel) instead of the per-message origin (the DM). Same root cause as [Bug] Multi-channel session routing - replies go to wrong channel #45514.
  • Agent-level: When using [[reply_to_current]], any multi-line response where text appears after the tag on a separate line causes that text to leak to the default channel. The tag only covers the first line.

Workaround Attempted

Instructed the agent (via system prompt) to stop using [[reply_to_current]] entirely for DMs and instead use the message tool with explicit conversation targeting + NO_REPLY. This fixes the agent-level leak but does not fix the gateway-level lastChannel race — the gateway can still misroute even when the agent does everything right.

Environment

  • OpenClaw: 2026.3.x (latest)
  • Channel: MSTeams (single-tenant Azure Bot)
  • OS: macOS (arm64)
  • Multiple surfaces active: Teams DMs + Teams channel

Related Issues

Suggested Fix

Reply routing should be pinned to the inbound message's channel/conversation origin at dispatch time, not derived from lastChannel on the session. The [[reply_to_current]] tag should also handle multi-line agent output gracefully (route the entire response, not just the first line).

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