From 103ae9b02eddb4c3a154e6b0d0e6bc3ff8cf82e5 Mon Sep 17 00:00:00 2001 From: HiddenPuppy Date: Sat, 9 May 2026 16:40:52 +0800 Subject: [PATCH 1/2] fix(telegram): fail fast when user images cannot be accessed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user sends an image via Telegram and the vision analysis pipeline fails (e.g. no Gemini key configured), the agent previously received either an empty user message or a hint telling it to retry with vision_analyze — causing up to 30+ minutes of futile retries. Changes: - Normalize MIME type 'image/jpg' → 'image/jpeg' in the Telegram photo handler to avoid non-standard MIME types - In _enrich_message_with_vision: track all_failed across all images. When ALL analyses fail AND the user provided no caption, return a clear fail-fast message instead of prompting the agent to retry - In _build_media_placeholder: return a neutral fallback string instead of empty string when there are no media_urls at all, preventing the agent from receiving empty user input Fixes NousResearch/hermes-agent#22385 --- gateway/platforms/telegram.py | 5 ++++- gateway/run.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index e4bba209b8243..5d41774a3acee 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -3221,7 +3221,10 @@ async def _handle_media_message(self, update: Update, context: ContextTypes.DEFA # Save to local cache (for vision tool access) cached_path = cache_image_from_bytes(bytes(image_bytes), ext=ext) event.media_urls = [cached_path] - event.media_types = [f"image/{ext.lstrip('.')}" ] + # Normalize MIME: "image/jpg" → "image/jpeg" (standard MIME) + raw_ext = ext.lstrip('.') + mime_ext = "jpeg" if raw_ext == "jpg" else raw_ext + event.media_types = [f"image/{mime_ext}"] logger.info("[Telegram] Cached user photo at %s", cached_path) media_group_id = getattr(msg, "media_group_id", None) if media_group_id: diff --git a/gateway/run.py b/gateway/run.py index 457dc60d757c6..35ace894c598f 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -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( ) 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}" From 704b2174bd2980e67b27f71af02c134be27b5e86 Mon Sep 17 00:00:00 2001 From: HiddenPuppy Date: Sat, 9 May 2026 17:31:11 +0800 Subject: [PATCH 2/2] chore: add HiddenPuppy to AUTHOR_MAP for attribution checks --- scripts/release.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/release.py b/scripts/release.py index e98899c202626..7dec045bcf85a 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -910,6 +910,7 @@ "wtyopenclaw@gmail.com": "WuTianyi123", # PR #20275 salvage of #13723 (feishu markdown) "zhicheng.han@mathematik.uni-goettingen.de": "hanzckernel", # PR #20311 (api-server approval events) "agentsmithlaor@gmail.com": "oferlaor", # PR #22356 salvage (cron origin sender identity) + "257965685+HiddenPuppy@users.noreply.github.com": "HiddenPuppy", # PR #22413 (telegram image fail-fast) # pander: empty email, salvaged via PR #19665 from #16126 by @ms-alan }