← Back to PRs

#10865: telegram: fast-ACK webhook and retry bind on EADDRINUSE

by u9733037 open 2026-02-07 03:39 View on GitHub →
channel: telegram stale
### Problem Telegram webhook requests can time out when agent/tool processing is slow (10–60s+), leading to delayed updates, retries, and user-facing “Telegram Web not updating / bot not responding”. Observed errors: - webhook handler timeout at 60s - “Bot not initialized!” when handling updates manually - crash loop on restart due to port reuse: listen EADDRINUSE 0.0.0.0:8787 ### Changes - Fast-ACK Telegram webhook: read request body, respond 200 OK immediately, then process update asynchronously via bot.handleUpdate(update). - Call await bot.init() to ensure bot info is available when handling updates manually. - Add retry/backoff for server.listen when EADDRINUSE occurs (reduces crash loops during rapid restarts / port not released yet). ### Tests - Updated src/telegram/webhook.test.ts to assert: - HTTP POST returns 200 - bot.init() called - bot.handleUpdate() invoked asynchronously <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> - Reworks Telegram webhook handling to “fast-ACK”: read request body, respond 200, then process updates asynchronously via `bot.handleUpdate()`. - Ensures bot metadata is available for manual update processing by calling `await bot.init()`. - Adds `listenWithRetry` retry/backoff logic when binding the webhook HTTP server fails with `EADDRINUSE`. - Updates webhook tests to assert immediate 200 response and that `init()`/`handleUpdate()` are invoked. <h3>Confidence Score: 3/5</h3> - Reasonably safe, but has a couple of correctness issues that can break webhook behavior in common configurations. - Fast-ACK + async handling is a good direction, but the current response-writing flow can race into double responses, and the webhook URL can be incorrect when `port=0`/`host=0.0.0.0` because it’s computed before binding. Both should be addressed before merge. - src/telegram/webhook.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs