fix(telegramSafe): exempt getUpdates and lifecycle calls from 15s tim… - #128
Conversation
…eout Telegraf's long-polling uses getUpdates with timeout=50 (Telegram holds the connection for up to 50 seconds waiting for new updates). The callApi patch was wrapping ALL methods — including getUpdates — with globalThrottle, which has a hard 15-second race. This fired on every poll cycle, throwing 'rateLimiter: API call timed out after 15000ms', causing bot.launch() to reject and systemd to enter an infinite restart loop. Fix: add getUpdates (and Telegraf startup/lifecycle calls: getMe, deleteWebhook, setWebhook, getWebhookInfo, close, logOut) to the _MANAGED bypass set so they call the original callApi directly without the timeout wrapper. All 60 unit tests pass. Bot loads cleanly in CI mode. https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the Telegraf telegramSafe callApi wrapper to bypass global throttling/timeout for getUpdates and specific lifecycle methods so long-polling and startup calls are not subject to the 15s timeout race. Sequence diagram for telegramSafe callApi wrapping and managed method bypasssequenceDiagram
actor Operator
participant Bot as TelegrafBot
participant TelegramSafe as telegramSafe_init
participant Tg as Telegraf_tg
participant Throttle as globalThrottle
participant TelegramAPI
Operator->>Bot: bot.launch()
Bot->>TelegramSafe: init(bot)
TelegramSafe->>Tg: wrap tg.callApi(method, data, signal)
Note over Bot,Tg: Case 1: managed method (e.g. getUpdates, getMe)
Bot->>Tg: callApi(getUpdates, data, signal)
Tg->>Tg: _MANAGED has getUpdates
Tg->>TelegramAPI: callApi_original(getUpdates, data, signal)
TelegramAPI-->>Tg: long-poll response (up to 50s)
Note over Bot,Tg: Case 2: non-managed method
Bot->>Tg: callApi(sendChatAction, data, signal)
Tg->>Throttle: globalThrottle(sendChatAction, data, signal)
Throttle->>TelegramAPI: callApi_original(sendChatAction, data, signal)
TelegramAPI-->>Throttle: response
Throttle-->>Tg: response
Tg-->>Bot: response
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded seven methods (getUpdates, getMe, deleteWebhook, setWebhook, getWebhookInfo, close, logOut) to the _MANAGED set in telegramSafe.js to bypass the global retry and throttle wrapper layer, preventing double-wrapping and enabling direct API calls for these specific methods. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider moving the
_MANAGEDset to a shared constant or helper so the list of bypassed methods is defined in one place and can be reused or tested independently frominit(). - Since the bypass list is now coupling to Telegraf’s lifecycle usage, it may be safer to group these methods (e.g.,
LIFECYCLE_METHODS,LONG_POLL_METHODS) or document the selection criteria in code so future additions/changes to lifecycle calls are easier to spot and update correctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider moving the `_MANAGED` set to a shared constant or helper so the list of bypassed methods is defined in one place and can be reused or tested independently from `init()`.
- Since the bypass list is now coupling to Telegraf’s lifecycle usage, it may be safer to group these methods (e.g., `LIFECYCLE_METHODS`, `LONG_POLL_METHODS`) or document the selection criteria in code so future additions/changes to lifecycle calls are easier to spot and update correctly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Nitpicks 🔍
|
|
CodeAnt AI finished reviewing your PR. |
User description
…eout
Telegraf's long-polling uses getUpdates with timeout=50 (Telegram holds the connection for up to 50 seconds waiting for new updates). The callApi patch was wrapping ALL methods — including getUpdates — with globalThrottle, which has a hard 15-second race. This fired on every poll cycle, throwing 'rateLimiter: API call timed out after 15000ms', causing bot.launch() to reject and systemd to enter an infinite restart loop.
Fix: add getUpdates (and Telegraf startup/lifecycle calls: getMe, deleteWebhook, setWebhook, getWebhookInfo, close, logOut) to the _MANAGED bypass set so they call the original callApi directly without the timeout wrapper.
All 60 unit tests pass. Bot loads cleanly in CI mode.
https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
Summary by Sourcery
Bug Fixes:
CodeAnt-AI Description
Exempt long-polling and lifecycle Telegram calls from the 15s API timeout wrapper
What Changed
Impact
✅ Bot no longer crashes or fails to launch due to getUpdates timing out✅ Fewer unexpected restarts under systemd when using long-polling✅ Startup/lifecycle operations complete without being delayed by long-poll requests💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
Release Notes