Skip to content

[Bug] Telegram slash command handler writes bare session key (missing agent: prefix) causing duplicate message delivery #38648

@Akotz89

Description

@Akotz89

Summary

Every Telegram slash command (e.g. /new, /reset, /help) creates a session entry with the key telegram:slash:<user_id> instead of agent:<agentId>:telegram:slash:<user_id>. This bare key coexists with the real session key (agent:main:telegram:direct:<user_id>), and the gateway resolves both to the same chat — resulting in duplicate message delivery.

Root Cause

In pi-embedded-DgYXShcG.js (and pi-embedded-CtM2Mrrj.js), the ctxPayload for the slash handler hardcodes:

SessionKey: `telegram:slash:${senderId || chatId}`,

This is missing the agent:<agentId>: prefix that all other session keys use. The key is then passed to recordInboundSessionMetaSafe via ctxPayload.SessionKey ?? route.sessionKey, writing the malformed key to sessions.json.

Impact

  • Each slash command invocation writes a new bare telegram:slash:<user_id> entry to sessions.json
  • With multiple slash commands (e.g. /new used regularly), stale entries accumulate
  • Gateway routes delivery to both the real session and the bare session → duplicate Telegram messages
  • Race condition possible (messages arrive out of order)

Fix

Change line to include the agent prefix (note: route.agentId is already in scope):

SessionKey: `agent:${route.agentId}:telegram:slash:${senderId || chatId}`,

Applied this patch locally — duplicate messages stopped immediately.

Environment

  • OpenClaw (latest npm release as of 2026-03-07)
  • Telegram channel, direct chat
  • Slash commands used: /new, /reset
  • WSL2 / Ubuntu 22.04

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