← Back to PRs

#22694: telegram: stabilize multi-account webhook mode

by Dongik open 2026-02-21 14:34 View on GitHub →
channel: telegram size: M
## Summary - keep `monitorTelegramProvider` alive in webhook mode until abort, so channel manager does not auto-restart a healthy webhook worker - support multi-account webhook mode on one listener by routing per-path and sharing the HTTP server - derive account-specific default webhook paths (`/telegram-webhook/<accountId>`) for non-default accounts and fail fast on path conflicts ## Why - in webhook mode, the provider task returned immediately after startup, which made gateway think the channel exited and trigger restart loops - repeated restarts in multi-account setups caused `listen EADDRINUSE 127.0.0.1:8787` ## Testing - `corepack pnpm vitest src/telegram/webhook.test.ts src/telegram/monitor.test.ts` Fixes #22672 <!-- greptile_comment --> <h3>Greptile Summary</h3> Refactored Telegram webhook mode to fix restart loops and enable multi-account support on a shared HTTP server. The key changes prevent the gateway manager from treating successful webhook startup as an exit (which triggered restarts) and eliminate `EADDRINUSE` errors when multiple accounts try to bind to the same port. - **monitor.ts**: Added await on abort signal to keep the webhook provider task alive until explicitly stopped - **webhook.ts**: Introduced shared server pool with per-path routing, auto-generated account-specific default paths (`/telegram-webhook/<accountId>`), and fail-fast validation for path conflicts - **Tests**: Added coverage for webhook task lifecycle, multi-account server sharing, and conflict detection <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with one edge case fix needed - The implementation correctly addresses the restart loop issue and multi-account webhook support with good test coverage. However, there's a logical gap when `abortSignal` is not provided - the webhook task will return immediately instead of staying alive, which could cause the same restart loop the PR aims to fix. This edge case needs to be handled. - Pay attention to src/telegram/monitor.ts lines 170-178 for the abortSignal edge case <sub>Last reviewed commit: c203a02</sub> <!-- 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