Skip to content

fix(tools): guard against unsupported image formats to prevent session deadlock#1095

Open
itxaiohanglover wants to merge 2 commits into
MoonshotAI:mainfrom
itxaiohanglover:fix/webp-gif-image-guard
Open

fix(tools): guard against unsupported image formats to prevent session deadlock#1095
itxaiohanglover wants to merge 2 commits into
MoonshotAI:mainfrom
itxaiohanglover:fix/webp-gif-image-guard

Conversation

@itxaiohanglover

Copy link
Copy Markdown

Fixes #1082

Problem

When a webp or gif image is read via the Read Media tool, it is sent to the model endpoint as-is. Some providers (e.g. kimi-for-coding) accept PNG/JPEG but reject WebP/GIF with HTTP 400. The failed image stays in conversation history and is re-sent on every subsequent turn, permanently bricking the session — no prompt can recover.

What changed

Added a MIME type guard after the image_in capability check:

  • If the image is webp or gif, check if the model's supportedImageMimes includes that MIME type
  • If not supported, return a helpful error message instead of sending the unsupported image
  • The error tells the user to convert to PNG or JPEG

This prevents the session deadlock because the unsupported image never enters the conversation history.

Validation

  • PNG/JPEG images: no behavior change (always in supported list)
  • WebP/GIF on models that support them: no behavior change (MIME is in supported list)
  • WebP/GIF on models that don't support them: error returned, session not bricked

…vent session deadlock

Some model endpoints accept PNG/JPEG but reject WebP/GIF with 400.
The failed image stays in history and is re-sent every turn, bricking
the session permanently.

Fix: check if the model supports the image MIME type before sending.
If not, return a helpful error instead of sending the unsupported image.

Fixes MoonshotAI#1082
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7ed11f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2af70cf73

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// WebP/GIF, causing a 400 that bricks the session because the failed
// image stays in history and is re-sent on every turn.
if (fileType.kind === 'image' && (fileType.mimeType === 'image/webp' || fileType.mimeType === 'image/gif')) {
const supported = this.capabilities.supportedImageMimes ?? ['image/png', 'image/jpeg'];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the MIME capability field before reading it

In the current @moonshot-ai/kosong contract, ModelCapability has no supportedImageMimes field, so this new access makes the package fail typechecking (Property 'supportedImageMimes' does not exist on type 'ModelCapability'). If the field is intended, it needs to be added to the shared capability type and populated by the capability providers; otherwise this guard cannot compile and release builds for agent-core are blocked.

Useful? React with 👍 / 👎.

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.

webp/gif read via built-in Read-image tool 400s on kimi-for-coding and permanently deadlocks the session (failed image re-sent every turn)

1 participant