#17243: fix(telegram): catch getFile network failures to prevent gateway crash (#17227)
size: XS
experienced-contributor
Cluster:
Network Error Handling Improvements
## Problem
When Telegram's `getFile` API call fails due to network issues (timeout, DNS failure), the gateway crashes with an unhandled promise rejection. The error chain is: `processMessage` → `resolveMedia` → `ctx.getFile()` → unhandled rejection → crash.
Fixes #17227
## Solution
Add error handling to the unguarded `onFlush` promise path in `src/auto-reply/inbound-debounce.ts`:
The `enqueue` function's immediate-flush path (`await params.onFlush([item])`) had no try/catch — wrapped with error routing to `params.onError`, following the existing callback pattern used by the batched flush path.
## Changes
- `src/auto-reply/inbound-debounce.ts` — 5 insertions, 1 deletion
## Testing
Existing tests pass.
---
## Local Validation
- `pnpm build` ✅
- `pnpm check` (oxlint) ✅
- Relevant test suites pass ✅
## Contribution Checklist
- [x] Focused scope — single fix per PR
- [x] Clear "what" + "why" in description
- [x] AI-assisted (Codex/Claude) — reviewed and tested by human
- [x] Local validation run (`pnpm build && pnpm check`)
*AI-assisted (Claude). Reviewed by human.*
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Wraps the unguarded `params.onFlush([item])` call in the immediate-flush path of `createInboundDebouncer.enqueue` with a try/catch that routes errors to `params.onError`. This aligns the non-debounce path with the existing error handling in `flushBuffer` (lines 60-64), preventing unhandled promise rejections from crashing the gateway when callers lack their own outer try/catch (e.g., the Slack message handler).
- **`src/auto-reply/inbound-debounce.ts`**: 5-line change adds try/catch around the immediate-flush `onFlush` call, consistent with the batched-flush error pattern
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it is a minimal, well-scoped defensive fix that follows an established pattern.
- The change is a 5-line addition that wraps an existing `onFlush` call with the same try/catch + `onError` pattern already used by `flushBuffer`. It introduces no new behavior, no API changes, and no risk of regression. The fix is correct and addresses a real gap in error handling.
- No files require special attention.
<sub>Last reviewed commit: 6960057</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17435: fix(debounce): retry flush with exponential backoff to prevent sile...
by widingmarcus-cyber · 2026-02-15
83.6%
#15985: fix(telegram): defer buffer deletion until processing succeeds
by coygeek · 2026-02-14
82.5%
#12870: fix: recover from telegram fetch errors (issue #12835)
by ambicuity · 2026-02-09
79.7%
#7141: fix(telegram): unify network error detection to prevent poll crashes
by hclsys · 2026-02-02
78.2%
#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection ha...
by Nipurn123 · 2026-02-07
76.5%
#15996: fix(agents): messages arrive out of order — tool output beats narra...
by yinghaosang · 2026-02-14
76.5%
#23134: fix(gateway): skip auto-restart for webhook channels that resolve i...
by puneet1409 · 2026-02-22
76.3%
#7558: fix: Handle Grammy/Telegram network errors to prevent gateway crashes
by kaigritun · 2026-02-03
76.3%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
75.9%
#21163: Prevent Slack DNS errors from crashing the gateway
by graysurf · 2026-02-19
75.8%