From c2af70cf732502ce446819f543ab39703aa5b670 Mon Sep 17 00:00:00 2001 From: artboy <80608452+itxaiohanglover@users.noreply.github.com> Date: Thu, 25 Jun 2026 14:50:03 +0800 Subject: [PATCH 1/2] fix(tools): guard against unsupported image formats (webp/gif) to prevent 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 #1082 --- .../src/tools/builtin/file/read-media.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/agent-core/src/tools/builtin/file/read-media.ts b/packages/agent-core/src/tools/builtin/file/read-media.ts index f21886974..85bfe99dd 100644 --- a/packages/agent-core/src/tools/builtin/file/read-media.ts +++ b/packages/agent-core/src/tools/builtin/file/read-media.ts @@ -199,6 +199,22 @@ export class ReadMediaFileTool implements BuiltinTool { 'Tell the user to use a model with image input capability.', }; } + // Guard against image formats the model endpoint may reject. + // Some providers (e.g. kimi-for-coding) accept PNG/JPEG but reject + // 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']; + if (!supported.includes(fileType.mimeType)) { + return { + isError: true, + output: + `The current model does not support ${fileType.mimeType} images. ` + + 'Supported formats: ' + supported.join(', ') + '. ' + + 'Convert the image to PNG or JPEG before reading it.', + }; + } + } if (fileType.kind === 'video' && !this.capabilities.video_in) { return { isError: true, From 7ed11f69707616c5da21009ce3f091f2469e4d2b Mon Sep 17 00:00:00 2001 From: itxaiohanglover <1531137510@qq.com> Date: Fri, 26 Jun 2026 12:13:13 +0800 Subject: [PATCH 2/2] Add changeset --- .changeset/image-format-guard.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/image-format-guard.md diff --git a/.changeset/image-format-guard.md b/.changeset/image-format-guard.md new file mode 100644 index 000000000..837116b42 --- /dev/null +++ b/.changeset/image-format-guard.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Guard against unsupported image formats to prevent crashes when processing WebP/GIF images.