← Back to PRs

#7141: fix(telegram): unify network error detection to prevent poll crashes

by hclsys open 2026-02-02 12:53 View on GitHub →
channel: telegram
## Summary - Unify network error detection by expanding `RECOVERABLE_MESSAGE_SNIPPETS` and removing duplicate `isNetworkRelatedError` function - Prevents Telegram monitor crashes when fetch errors are wrapped in cause chains - Added test coverage for the new message snippets ## Problem The Telegram monitor had two separate network error detection mechanisms: 1. `isRecoverableTelegramNetworkError` (in `network-errors.ts`) - walks error cause chains 2. `isNetworkRelatedError` (in `monitor.ts`) - only checks top-level message When fetch errors were wrapped (e.g., `{ cause: TypeError }`), `isNetworkRelatedError` missed them because it didn't walk the cause chain, causing the monitor to crash. ## Solution 1. **Expand `RECOVERABLE_MESSAGE_SNIPPETS`** to include snippets from the old `isNetworkRelatedError`: "network", "timeout", "socket", "econnreset", "econnrefused" 2. **Remove `isNetworkRelatedError`** from `monitor.ts` - it's now redundant 3. **Rely on `isRecoverableTelegramNetworkError`** which already handles cause chain traversal via `collectErrorCandidates()` ## Test plan - [x] Unit tests pass (`npm test -- src/telegram/network-errors.test.ts`) - [x] Added tests for the new message snippets - [x] Added tests verifying send context skips message-only matching - [x] Build passes (`npm run build`) - [x] Lint passes (`npm run lint`) Fixes #6077 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR removes the Telegram monitor’s duplicate `isNetworkRelatedError` check and relies solely on `isRecoverableTelegramNetworkError`, which already traverses error cause chains. To preserve prior behavior, it expands `RECOVERABLE_MESSAGE_SNIPPETS` and adds unit tests covering the new snippets and the send-context message-matching bypass. The change centralizes network error classification in `src/telegram/network-errors.ts`, simplifying `src/telegram/monitor.ts` retry logic and aiming to prevent poll crashes when fetch/undici errors are wrapped. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge, with the main risk being broader-than-intended retry classification from generic message snippets. - Changes are localized and covered by tests, and the core behavior (cause-chain traversal) is already implemented. The primary concern is behavioral: adding very generic message substrings can cause false positives in polling/webhook contexts, potentially masking real failures behind retries. - src/telegram/network-errors.ts (message snippet broadness), src/telegram/monitor.ts (retry behavior implications) <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs