← Back to PRs

#19141: fix(telegram): serialize per-chat sends and await block reply flush before tools

by botverse open 2026-02-17 12:37 View on GitHub →
channel: telegram agents size: XS
## Problem When an agent sends text (block reply) followed by a tool-initiated send (e.g., message tool sending a PDF), messages can arrive out of order on Telegram. ## Root Cause 1. **No per-chat send ordering**: sendMessageTelegram calls from block replies and the message tool fire concurrently 2. **Block reply buffer not flushed before tools**: The coalescer holds buffered text when a tool starts ## Fix ### Per-chat send serializer (src/telegram/send.ts) - chatSendChains Map keyed by accountId:chatId - serializeChatSend chains concurrent sends via promise chaining - Wraps sendMessageTelegram for FIFO ordering per chat ### Await block reply flush (src/agents/pi-embedded-subscribe.handlers.tools.ts) - flushBlockReplyBuffer() + await onBlockReplyFlush() before tool execution - Ensures pending text is delivered before tool-initiated sends ## Changes - src/telegram/send.ts — per-chat send serializer (37 lines) - src/agents/pi-embedded-subscribe.handlers.tools.ts — flush + await (3 lines)

Most Similar PRs