Skip to content

fix(telegram): auto-restart polling on post-startup 409 conflicts#1

Merged
Tyone88 merged 1 commit into
devfrom
claude/fix-archin-409-telegram-iB5Dh
May 10, 2026
Merged

fix(telegram): auto-restart polling on post-startup 409 conflicts#1
Tyone88 merged 1 commit into
devfrom
claude/fix-archin-409-telegram-iB5Dh

Conversation

@Tyone88

@Tyone88 Tyone88 commented May 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Telegram bot was replying once then dying silently. Cause: start()'s .catch only handled 409s during initial connect. After onStart fired, any post-startup 409 hit a no-op reject() (wrapper promise already resolved) and polling crashed with no restart.
  • Calls deleteWebhook({ drop_pending_updates: true }) before polling — forcibly bumps any stale getUpdates consumer holding the conflict.
  • Tracks started state and auto-restarts polling on post-startup runtime errors with a 60s delay (outlasts Telegram's ~50s long-poll). stop() sets a guard so intentional shutdown doesn't loop.

Test plan

  • Deploy and verify bot responds to multiple consecutive Telegram messages
  • Confirm telegram.bot_started log on boot
  • If 409 persists, check for a second process using the same TELEGRAM_BOT_TOKEN — fix logs telegram.restart_scheduled so it's observable
  • Confirm stop() on SIGTERM does not trigger a restart loop

https://claude.ai/code/session_01X7wX5mMrbR83iWEv4mg8aq


Generated by Claude Code

The previous start() only retried 409s during the initial connect. Once
onStart fired, any subsequent 409 (stale getUpdates from another process,
old deployment, or webhook still set) crashed polling silently — the
.catch's reject() was a no-op because the wrapper promise had already
resolved. Result: bot replies once, then dies.

- deleteWebhook({ drop_pending_updates: true }) before polling so any
  conflicting consumer is bumped instead of holding 409 forever.
- Track started state and schedule an auto-restart on post-startup
  failures, with delay tuned to outlast Telegram's ~50s long-poll.
- Suppress restart when stop() is called.
@Tyone88 Tyone88 merged commit 348f9fa into dev May 10, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants