openclaw - 💡(How to fix) Fix [Bug]: Delivery-mirror leaks messages across agents when multiple Telegram accounts bind to same peer [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#69576Fetched 2026-04-22 07:50:36
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

When multiple agents are bound to the same Telegram peer via different Telegram accounts (different bot tokens), the delivery-mirror mechanism incorrectly syncs outbound messages to all sessions bound to that peer, instead of only the session belonging to the agent that sent the message.

Root Cause

From sessions_list API response:

{
  "key": "agent:main:telegram:direct:8267898996",
  "deliveryContext": { "channel": "telegram", "to": "telegram:8267898996", "accountId": "default" }
}
{
  "key": "agent:dev:telegram:direct:8267898996",
  "deliveryContext": { "channel": "telegram", "to": "telegram:8267898996", "accountId": "dev" }
}

Both sessions have deliveryContext.to: "telegram:8267898996" without differentiating by accountId.

When the Gateway performs delivery-mirror sync:

  1. Agent sends message → deliveryContext contains { channel: "telegram", to: "telegram:8267898996" }
  2. Gateway syncs outbound message back to session transcript
  3. Gateway finds sessions by deliveryContext.to → finds both main and dev sessions
  4. Syncs to both sessions instead of only the originating agent's session

The bug: deliveryContext should include accountId to uniquely identify which agent/session sent the message. The current deliveryContext.to format telegram:peer_id is ambiguous when multiple agents bind to the same peer via different accounts.

Code Example

{
  "bindings": [
    { "agentId": "main", "match": { "channel": "telegram", "accountId": "default" } },
    { "agentId": "dev", "match": { "channel": "telegram", "accountId": "dev" } },
    { "agentId": "money", "match": { "channel": "telegram", "accountId": "money" } },
    { "agentId": "operations", "match": { "channel": "telegram", "accountId": "operations" } }
  ],
  "channels": {
    "telegram": {
      "accounts": {
        "default": { "botToken": "8596451837:..." },
        "dev": { "botToken": "8638828395:..." },
        "money": { "botToken": "8708397593:..." },
        "operations": { "botToken": "8605344542:..." }
      }
    }
  },
  "session": { "dmScope": "per-channel-peer" }
}

---

{"type":"message","id":"xxx","message":{"role":"assistant","content":[{"type":"text","text":"LingoTools.ipa"}],"model":"delivery-mirror"}}
{"type":"message","id":"xxx","message":{"role":"assistant","content":[{"type":"text","text":"lingostock_sim.png"}],"model":"delivery-mirror"}}
{"type":"message","id":"xxx","message":{"role":"assistant","content":[{"type":"text","text":"lingostock_home.png"}],"model":"delivery-mirror"}}

---

{
  "key": "agent:main:telegram:direct:8267898996",
  "deliveryContext": { "channel": "telegram", "to": "telegram:8267898996", "accountId": "default" }
}
{
  "key": "agent:dev:telegram:direct:8267898996",
  "deliveryContext": { "channel": "telegram", "to": "telegram:8267898996", "accountId": "dev" }
}
RAW_BUFFERClick to expand / collapse

Summary

When multiple agents are bound to the same Telegram peer via different Telegram accounts (different bot tokens), the delivery-mirror mechanism incorrectly syncs outbound messages to all sessions bound to that peer, instead of only the session belonging to the agent that sent the message.

Environment

  • OpenClaw version: 2026.4.15
  • Platform: macOS (Darwin 25.4.0 arm64)
  • Channel: Telegram
  • Configuration: 4 agents (main, dev, money, operations) each bound to separate Telegram accounts (4 different bot tokens) but all to the same peer (DM with user 8267898996)

Configuration

{
  "bindings": [
    { "agentId": "main", "match": { "channel": "telegram", "accountId": "default" } },
    { "agentId": "dev", "match": { "channel": "telegram", "accountId": "dev" } },
    { "agentId": "money", "match": { "channel": "telegram", "accountId": "money" } },
    { "agentId": "operations", "match": { "channel": "telegram", "accountId": "operations" } }
  ],
  "channels": {
    "telegram": {
      "accounts": {
        "default": { "botToken": "8596451837:..." },
        "dev": { "botToken": "8638828395:..." },
        "money": { "botToken": "8708397593:..." },
        "operations": { "botToken": "8605344542:..." }
      }
    }
  },
  "session": { "dmScope": "per-channel-peer" }
}

Reproduction Steps

  1. Configure multiple agents with separate Telegram accounts (different bot tokens)
  2. All agents bound to the same peer (same user DM)
  3. Send a message to one agent (e.g., via dev bot)
  4. That agent sends a reply with media attachments
  5. The delivery-mirror syncs the outbound message to multiple session transcripts

Expected Behavior

  • Agent dev sends message → delivery-mirror syncs to agent:dev:telegram:direct:8267898996 session only
  • Each agent's outbound messages should only appear in its own session transcript

Actual Behavior

From session transcript inspection:

main session (agent:main:telegram:direct:8267898996):

{"type":"message","id":"xxx","message":{"role":"assistant","content":[{"type":"text","text":"LingoTools.ipa"}],"model":"delivery-mirror"}}
{"type":"message","id":"xxx","message":{"role":"assistant","content":[{"type":"text","text":"lingostock_sim.png"}],"model":"delivery-mirror"}}
{"type":"message","id":"xxx","message":{"role":"assistant","content":[{"type":"text","text":"lingostock_home.png"}],"model":"delivery-mirror"}}

These delivery-mirror entries with "model":"delivery-mirror" are screenshots sent by dev agent, not main agent. They incorrectly appear in main's session transcript.

Root Cause Analysis

From sessions_list API response:

{
  "key": "agent:main:telegram:direct:8267898996",
  "deliveryContext": { "channel": "telegram", "to": "telegram:8267898996", "accountId": "default" }
}
{
  "key": "agent:dev:telegram:direct:8267898996",
  "deliveryContext": { "channel": "telegram", "to": "telegram:8267898996", "accountId": "dev" }
}

Both sessions have deliveryContext.to: "telegram:8267898996" without differentiating by accountId.

When the Gateway performs delivery-mirror sync:

  1. Agent sends message → deliveryContext contains { channel: "telegram", to: "telegram:8267898996" }
  2. Gateway syncs outbound message back to session transcript
  3. Gateway finds sessions by deliveryContext.to → finds both main and dev sessions
  4. Syncs to both sessions instead of only the originating agent's session

The bug: deliveryContext should include accountId to uniquely identify which agent/session sent the message. The current deliveryContext.to format telegram:peer_id is ambiguous when multiple agents bind to the same peer via different accounts.

Proposed Fix

  1. Include accountId in deliveryContext: Change format from telegram:8267898996 to telegram:default:8267898996 or similar, including the accountId
  2. Or: delivery-mirror should use the session's origin.accountId instead of just deliveryContext.to when determining which session to sync to
  3. Or: Add explicit accountId field to deliveryContext alongside channel and to

Related Issues

  • #69443: Subagent RPC callback routed to wrong session
  • #63116: Delivery-mirror session token overflow
  • #51628: Telegram delivery queue recovery duplicates delivery-mirror entries

Impact

  • Users with multiple agents bound to the same peer experience session transcript contamination
  • Makes debugging harder (wrong messages in transcript)
  • May affect memory/corpus generation if delivery-mirror entries are included

extent analysis

TL;DR

Include the accountId in the deliveryContext to uniquely identify the agent/session that sent the message, ensuring the delivery-mirror mechanism syncs outbound messages to the correct session transcript.

Guidance

  • Modify the deliveryContext.to format to include the accountId, such as telegram:default:8267898996, to differentiate between sessions bound to the same peer via different accounts.
  • Alternatively, update the delivery-mirror logic to use the session's origin.accountId instead of just deliveryContext.to when determining which session to sync to.
  • Consider adding an explicit accountId field to deliveryContext alongside channel and to for clarity and flexibility.

Example

No code snippet is provided as the issue is more related to the design and logic of the delivery-mirror mechanism rather than a specific code implementation.

Notes

The proposed fix assumes that including the accountId in the deliveryContext or using the session's origin.accountId will correctly identify the intended session for delivery-mirror sync. This solution may need to be adapted based on the actual implementation details of the delivery-mirror mechanism and the session management system.

Recommendation

Apply the workaround by including the accountId in the deliveryContext to ensure correct delivery-mirror syncing, as this directly addresses the identified root cause of the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug]: Delivery-mirror leaks messages across agents when multiple Telegram accounts bind to same peer [1 participants]