Skip to content

fix: throttle project-thread sync telegram api bursts#84

Merged
RichardAtCT merged 2 commits intoRichardAtCT:mainfrom
drugoi:codex/issue-73-thread-sync-throttle
Feb 21, 2026
Merged

fix: throttle project-thread sync telegram api bursts#84
RichardAtCT merged 2 commits intoRichardAtCT:mainfrom
drugoi:codex/issue-73-thread-sync-throttle

Conversation

@drugoi
Copy link
Copy Markdown
Contributor

@drugoi drugoi commented Feb 21, 2026

Summary

  • keep issue Telegram Bot banned after a few hours #73 private-chat mitigation by pacing all Telegram API calls in ProjectThreadManager.sync_topics
  • add global outbound PTB limiter via AIORateLimiter(max_retries=1) during bot initialization
  • move flood-retry ownership to PTB limiter and remove manager-local RetryAfter retry logic to avoid duplicate retries/sleeps
  • use python-telegram-bot[rate-limiter] dependency wiring (lockfile updated)
  • keep safe default PROJECT_THREADS_SYNC_ACTION_INTERVAL_SECONDS=1.1 when env is absent
  • update unit tests for sync pacing/no-local-retry and bot-core limiter configuration

Why Keep Sync Interval Setting

  • AIORateLimiter group throttling is keyed for negative chat_id (groups/channels); private chats (positive IDs) fall back to global limiting.
  • issue Telegram Bot banned after a few hours #73 is caused by bursty private-chat topic bootstrap traffic, so sync-specific pacing is still needed as a targeted safeguard.
  • removing the sync interval would require stricter global limits and could slow unrelated bot traffic.

Testing

  • poetry run pytest -q tests/unit/test_projects/test_thread_manager.py tests/unit/test_bot/test_thread_mode_handlers.py tests/unit/test_bot/test_core_rate_limiter.py tests/unit/test_config.py

Closes #73

@RichardAtCT
Copy link
Copy Markdown
Owner

Did you consider using PTBs built in rate limiter? https://docs.python-telegram-bot.org/en/stable/telegram.ext.aioratelimiter.html

@drugoi
Copy link
Copy Markdown
Contributor Author

drugoi commented Feb 21, 2026

@RichardAtCT if I understood right, AIORateLimiter works only in group/supergroup/channels(?), not in personal chats. So part of the solution is still required custom rate-limiter.

@RichardAtCT RichardAtCT merged commit 24ba56c into RichardAtCT:main Feb 21, 2026
1 check 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.

Telegram Bot banned after a few hours

2 participants