Skip to content

Telegram: delivery routed through wrong bot account after gateway restart (multi-account race condition) #6402

@mr-claudius-maximus

Description

@mr-claudius-maximus

Description

When multiple Telegram bot accounts are configured under channels.telegram.accounts, message delivery after a gateway restart is routed through whichever bot connects first, not the bot associated with the originating session.

Steps to Reproduce

  1. Configure 3+ Telegram bot accounts (e.g., agent_a, agent_b, agent_c) each bound to a different agent via bindings
  2. Have an active session on one account (e.g., agent_a → agent main)
  3. Apply a config patch that triggers a gateway restart (config.patch)
  4. The queued/pending response from the main agent is delivered through the wrong bot (e.g., agent_b)

Expected Behavior

After restart, message delivery should wait until the correct Telegram bot account is connected before delivering. The delivery context (session → agent → binding → account) should be fully resolved before any message is sent.

Actual Behavior

  • Bots appear to start in alphabetical order by account key
  • During startup, sessionKey=unknown is logged, indicating the session-to-account mapping is not yet resolved
  • The pending response is delivered through whichever bot connects first
  • This causes messages from Agent A to appear in Agent B's Telegram chat with the user

Evidence from Logs

16:35:14.081 [agent_b] starting provider (@agent_b_bot)
16:35:14.191 session state: sessionId=<redacted> sessionKey=unknown  ← key not resolved
16:35:14.511 [agent_a] starting provider (@agent_a_bot)
16:35:23.100 [message delivered — went through agent_b instead of agent_a]

Impact

This is a data isolation / privacy issue in multi-agent setups. If agents have different access levels or serve different purposes, messages from one agent appearing in another agent's channel is a trust and privacy breach.

Root Cause & Fix

See comment below.

Environment

  • OpenClaw version: 2026.1.24-3
  • OS: macOS 26.2 (arm64)
  • Node: v25.5.0
  • Telegram accounts: 3
  • Agents: 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions