Repository navigation
fix(telegram): fail fast when user images cannot be accessed #22413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HiddenPuppy
wants to merge
2
commits into
NousResearch:main
Choose a base branch
from
HiddenPuppy:fix/issue-22385-telegram-image-failfast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -690,6 +690,10 @@ def _build_media_placeholder(event) -> str: | |
| dequeued, only .text is extracted. If the event has no caption, | ||
| the media would be silently lost. This builds a placeholder that | ||
| the vision enrichment pipeline will replace with a real description. | ||
|
|
||
| Returns a plain-text fallback so the agent never receives an empty | ||
| user message — empty input causes the agent to stall, retry, or | ||
| hallucinate for 30+ minutes (issue #22385). | ||
| """ | ||
| parts = [] | ||
| media_urls = getattr(event, "media_urls", None) or [] | ||
|
|
@@ -702,7 +706,12 @@ def _build_media_placeholder(event) -> str: | |
| parts.append(f"[User sent audio: {url}]") | ||
| else: | ||
| parts.append(f"[User sent a file: {url}]") | ||
| return "\n".join(parts) | ||
| if parts: | ||
| return "\n".join(parts) | ||
| # Safeguard: if there's nothing to placehold (no media_urls at all), | ||
| # return a neutral fallback so the agent doesn't receive empty input. | ||
| return "[User sent a message with media that couldn't be accessed]" | ||
|
|
||
|
|
||
|
|
||
| def _dequeue_pending_event(adapter, session_key: str) -> MessageEvent | None: | ||
|
|
@@ -12171,6 +12180,7 @@ async def _enrich_message_with_vision( | |
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add regression coverage for this new all-failed path: |
||
|
|
||
| enriched_parts = [] | ||
| all_failed = True | ||
| for path in image_paths: | ||
| try: | ||
| logger.debug("Auto-analyzing user image: %s", path) | ||
|
|
@@ -12182,6 +12192,7 @@ async def _enrich_message_with_vision( | |
| if result.get("success"): | ||
| description = result.get("analysis", "") | ||
| description = sanitize_context(description) | ||
| all_failed = False | ||
| enriched_parts.append( | ||
| f"[The user sent an image~ Here's what I can see:\n{description}]\n" | ||
| f"[If you need a closer look, use vision_analyze with " | ||
|
|
@@ -12203,6 +12214,15 @@ async def _enrich_message_with_vision( | |
|
|
||
| # Combine: vision descriptions first, then the user's original text | ||
| if enriched_parts: | ||
| # If ALL images failed to analyze AND the user didn't | ||
| # provide a caption, give a clear fail-fast message | ||
| # so the agent doesn't keep retrying for 30+ minutes. | ||
| if all_failed and not user_text.strip(): | ||
| return ( | ||
| "[The user sent an image but I'm unable to see it — " | ||
| "the vision analysis is not available right now. " | ||
| "Ask the user to describe what the image contains.]" | ||
| ) | ||
| prefix = "\n\n".join(enriched_parts) | ||
| if user_text: | ||
| return f"{prefix}\n\n{user_text}" | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handler has moved on current main to
plugins/platforms/telegram/adapter.py:7737-7813, where the live assignment still emitsimage/jpgat line 7801. Please transplant this normalization there (the plugin already defines_TELEGRAM_IMAGE_EXT_TO_MIMEat lines 236-242) and cover it with a regression test.