fix(tools): guard against unsupported image formats to prevent session deadlock#1095
fix(tools): guard against unsupported image formats to prevent session deadlock#1095itxaiohanglover wants to merge 2 commits into
Conversation
…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 detectedLatest commit: 7ed11f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
💡 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']; |
There was a problem hiding this comment.
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 👍 / 👎.
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_incapability check:supportedImageMimesincludes that MIME typeThis prevents the session deadlock because the unsupported image never enters the conversation history.
Validation