fix: buffer Telegram photo-album messages into a single Claude request#188
Open
IliyaBrook wants to merge 1 commit intoRichardAtCT:mainfrom
Open
fix: buffer Telegram photo-album messages into a single Claude request#188IliyaBrook wants to merge 1 commit intoRichardAtCT:mainfrom
IliyaBrook wants to merge 1 commit intoRichardAtCT:mainfrom
Conversation
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.
Follow-up to the discussion in #186 — @MatveyF flagged that the same
"one logical message, N responses" problem happens with images:
Root cause
When a user sends a Telegram album (text + N photos), Telegram delivers
it as N separate
Updates that share a commonmessage.media_group_id;the caption lives on only one of them. The agentic photo handler fires
once per
Update, so Claude is invoked N times independently instead ofseeing the album as a single message.
Fix
MediaGroupBuffer(src/bot/utils/media_group_buffer.py) —debounces photos keyed by
(user_id, chat_id, thread_id, media_group_id).Any photo carrying a
media_group_idis buffered; a short timer(default
1.0s, configurable viaMEDIA_GROUP_BUFFER_TIMEOUT, range0.3 – 5.0) fires after the last photo and flushes all photos +caption as a single payload.
agentic_photorefactored into a dispatcher: standalone photos takethe existing fast path; album photos go through the buffer.
_process_photo_batch— the first photo isprocessed with the caption (so the prompt template keeps user intent),
the rest are processed for image data only, and a single
claude_integration.run_commandis issued with all images attached.