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}" 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 }