Skip to content

fix(telegram): drain pending updates before polling to prevent 409 Conflict#425

Open
chenhg5 wants to merge 1 commit intomainfrom
fix/telegram-409-conflict
Open

fix(telegram): drain pending updates before polling to prevent 409 Conflict#425
chenhg5 wants to merge 1 commit intomainfrom
fix/telegram-409-conflict

Conversation

@chenhg5
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 commented Apr 2, 2026

Summary

  • Added drainPendingUpdates() function that calls getUpdates?offset=-1&timeout=0 before starting the polling loop
  • This clears any outstanding long-poll request from a previous bot instance, preventing 409 Conflict errors on restart
  • Root cause: migration to go-telegram/bot library (commit 1104739) removed the drain step that was present in the old go-telegram-bot-api/v5 implementation

Test plan

  • Build passes: go build ./...
  • Tests pass: go test ./...
  • Manual test: restart cc-connect with Telegram platform multiple times, verify no 409 Conflict errors

Fixes #422

🤖 Generated with Claude Code

…nflict

When migrating to go-telegram/bot library (commit 1104739), the drain
step that clears pending updates was removed. This causes 409 Conflict
errors on restart because Telegram still considers the previous instance's
long-poll request as active.

The fix adds drainPendingUpdates() which calls getUpdates with offset=-1
before starting the polling loop. This terminates any outstanding
long-poll request from a previous instance.

Fixes #422

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chenhg5
Copy link
Copy Markdown
Owner Author

chenhg5 commented Apr 2, 2026

LGTM! Clean fix for the 409 Conflict issue on Telegram bot restart.

✅ Correctness: The function correctly calls to clear any outstanding long-poll request from a previous instance.

✅ Implementation: Good error handling with debug logging, proper context timeout, and response body cleanup.

✅ CI: All checks pass.

✅ Scope: Focused single-purpose fix, references the root cause (migration to go-telegram/bot library).

Ready for merge.

Copy link
Copy Markdown
Owner Author

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review passed. Clean fix for 409 Conflict on Telegram bot restart.

Review summary:

  • drainPendingUpdates() calls getUpdates with offset=-1 before polling
  • ✅ Terminates outstanding long-poll from previous instance
  • ✅ Proper timeout and error handling
  • ✅ CI passes

Ready to merge (owner PR).

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.

[Bug] Telegram always enters recovery loop and causes getUpdates 409 Conflict (v1.2.2-beta.5)

2 participants