Telegram plugin drops first inbound message (race condition in startup)
Bug Description
The Telegram channel plugin consistently drops the first message sent by a user after the plugin starts. The second and subsequent messages are delivered fine. This is a reproducible pattern, not intermittent.
Root Cause
Race condition in server.ts between MCP readiness and Grammy bot polling initialization.
Current flow (lines 614 + 959):
await mcp.connect(new StdioServerTransport())— Claude Code considers the channel readyvoid (async () => { await bot.start(...) })()— bot polling starts as a fire-and-forget IIFE- User sends first message → arrives at Telegram API while
bot.start()is still initializing → dropped - By the time the second message arrives, polling is stable → delivered
The void keyword on line 959 discards the startup promise. Nothing gates MCP readiness on Grammy actually polling.
Fix
Move the bot startup before mcp.connect() and await the onStart callback:
let botPollingReady: () => void
const botPollingReadyPromise = new Promise<void>(resolve => { botPollingReady = resolve })
void (async () => {
// ... existing retry loop ...
await bot.start({
onStart: info => {
// ... existing onStart logic ...
botPollingReady!() // Signal polling is active
},
})
})()
await Promise.race([
botPollingReadyPromise,
new Promise<void>(resolve => setTimeout(() => {
process.stderr.write('telegram channel: bot startup timed out after 30s\n')
resolve()
}, 30000)),
])
await mcp.connect(new StdioServerTransport()) // Now safe — Grammy is polling
This ensures MCP doesn't declare readiness until Grammy is actively processing updates. The 30s timeout prevents hanging if the bot can't connect.
Reproduction
- Start a Claude Code session with the Telegram plugin enabled
- Send a message via Telegram immediately
- Observe: message is not delivered to the session
- Send a second message
- Observe: second message arrives normally
Environment
- Plugin version: 0.0.4
- Grammy: v1.41.1
- Runtime: Bun
- OS: macOS (Darwin)
Affected File
plugins/cache/claude-plugins-official/telegram/0.0.4/server.ts, lines 614 and 959
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗