Skip to content

fix(assistant): handle gif URLs breaking vision responses - #279

Merged
vertyco merged 1 commit into
mainfrom
claude/assistant-cog-gif-bug-jezyu1
Jun 21, 2026
Merged

fix(assistant): handle gif URLs breaking vision responses#279
vertyco merged 1 commit into
mainfrom
claude/assistant-cog-gif-bug-jezyu1

Conversation

@vertyco

@vertyco vertyco commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Problem

When a message contained a GIF URL (e.g. Mirosbird.gif), the bot failed the entire response with:

Bad Request Error2(400): Error while downloading Mirosbird.gif

Root cause

The image URL regex in assistant/common/chat.py included gif, so gif URLs were forwarded to the vision API. OpenAI's vision can't process (animated) gifs and returns a 400 Error while downloading. The attachment handler right below it already excluded gif (img_ext = ["png", "jpg", "jpeg", "webp"]), so the two paths were inconsistent.

Additionally, the BadRequestError handler only retried-without-images on "Invalid image", not "Error while downloading", so this error fell through and broke the whole reply.

Fix

  1. Removed gif from the image URL regex so gif URLs are no longer sent to the vision API, matching the attachment handler.
  2. The BadRequestError handler now also strips images and retries on "Error while downloading", so any unfetchable image URL degrades gracefully (text answer still returned) instead of failing the entire response.

purge_images() already removes URL-sourced images, so the retry path works correctly.

Bumped changelog to v8.18.3.


Generated by Claude Code

A gif URL in a message was matched by the image URL regex and sent to the
vision API, which returned a 400 "Error while downloading ...gif" (the API
cannot process animated gifs), failing the entire response.

- Exclude gif from the image URL regex to match the attachment handler,
  which already skipped gif.
- Strip images and retry on "Error while downloading" in the BadRequestError
  handler so any unfetchable image URL degrades gracefully.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011vjHtN5hcQi9hGonuDbMEG
Copilot AI review requested due to automatic review settings June 21, 2026 03:12
@vertyco
vertyco merged commit 1c05206 into main Jun 21, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a failure mode in the assistant chat flow where GIF URLs (and other unfetchable image URLs) could break the entire response by being forwarded to the vision API and triggering a 400 error.

Changes:

  • Excludes gif from the inline image URL regex so GIF links are not sent to the vision API.
  • Extends BadRequestError handling to purge images and retry when the API returns “Error while downloading”.
  • Adds a v8.18.3 changelog entry documenting the fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
assistant/common/chat.py Stops treating GIF URLs as vision images and retries gracefully on image-download 400s by stripping images.
assistant/CHANGELOG.md Documents the bugfix and bumps changelog to v8.18.3.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread assistant/common/chat.py
Comment on lines 1059 to +1063
except openai.BadRequestError as e:
if "Invalid image" in str(e):
err_text = str(e)
# Some image URLs (e.g. gifs, or links the API can't fetch) cause a 400. Rather than
# failing the whole response, strip images from the payload and retry without them.
if "Invalid image" in err_text or "Error while downloading" in err_text:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants