Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gateway/platforms/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown
Collaborator

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 emits image/jpg at line 7801. Please transplant this normalization there (the plugin already defines _TELEGRAM_IMAGE_EXT_TO_MIME at lines 236-242) and cover it with a regression test.

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:
Expand Down
22 changes: 21 additions & 1 deletion gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand All @@ -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:
Expand Down Expand Up @@ -12171,6 +12180,7 @@ async def _enrich_message_with_vision(
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add regression coverage for this new all-failed path: success: false and thrown exceptions with no caption should return the fail-fast text, while a mixed success/failure batch must preserve the successful description and the original caption behavior.


enriched_parts = []
all_failed = True
for path in image_paths:
try:
logger.debug("Auto-analyzing user image: %s", path)
Expand All @@ -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 "
Expand All @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down