fix(telegram): harden photo download against crash scenarios#980
Open
snemesh wants to merge 1 commit intoanthropics:mainfrom
Open
fix(telegram): harden photo download against crash scenarios#980snemesh wants to merge 1 commit intoanthropics:mainfrom
snemesh wants to merge 1 commit intoanthropics:mainfrom
Conversation
The photo download callback in message:photo handler has three gaps that can crash the channel process or silently corrupt state: 1. No guard for empty photo array — if ctx.message.photo is empty, photos[photos.length - 1] is undefined and .file_id throws a TypeError that propagates up as an unhandled error. 2. No HTTP status check — if the Telegram file API returns 4xx/5xx, res.arrayBuffer() reads an error page into a Buffer that gets written to disk as a corrupt file. 3. No size limit — the largest photo variant can be up to 20MB; without a cap, a very large response could cause memory pressure in constrained environments. All three return undefined on failure (graceful degradation) instead of crashing the process. The message is still delivered to Claude without the image attachment. Fixes anthropics#944
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sending a photo to the Telegram bot can crash the channel process, making it completely unresponsive until restarted (#944). The photo download callback in
message:photohandler has three gaps:ctx.message.photois empty,photos[photos.length - 1]isundefinedand.file_idthrows aTypeErrorthat propagates as an unhandled errorres.arrayBuffer()reads an error body that gets written to disk as a corrupt JPEGFix
All three cases now return
undefined(graceful degradation) instead of crashing. The message is still delivered to Claude without the image attachment, and errors are logged to stderr.Changes
external_plugins/telegram/server.ts— 10 insertions, 1 deletionTest plan
bun buildpassesTest output (12/12 passed)
Fixes #944