fix(agent-core): detect image format from bytes when reading media - #970
Merged
Conversation
🦋 Changeset detectedLatest commit: 6b61226 The changes in this PR will be included in the next version bump. 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 |
When ReadMediaFile reads a file whose bytes have no recognisable image magic (for example a `.png` that is actually plain text), detectFileType previously fell back to the extension MIME type and built a data URL whose bytes did not match the declared format, which the model API rejected. Every image format the model accepts (PNG/JPEG/GIF/WebP) has a reliable magic signature, so a failed sniff means the bytes are not a supported image. Report such files as `unknown` so ReadMediaFile returns a clear error instead of a bad data URL. The extension fallback is kept for video containers with no magic signature (for example MPEG-PS `.mpg`); format acceptance beyond that is left to the provider.
7Sageer
force-pushed
the
fix/read-media-mime-gate
branch
from
June 22, 2026 09:38
df0cd56 to
6b61226
Compare
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
No related issue.
Problem
When
ReadMediaFilereads a file whose extension claims an image but whose bytes are not a recognised image (for example a.pngthat is actually plain text, or a truncated/renamed file),detectFileTypefell back to the extension's MIME type and built adata:URL whose bytes did not match the declared format. The model API then rejects the request with400 Invalid request: unsupported image format: application/octet-stream, failing the turn.What changed
unknownfor an image extension whose bytes fail to sniff, soReadMediaFilereports a clear "not a supported image or video file" error instead of shipping a bad data URL. Every image format the model accepts (PNG/JPEG/GIF/WebP) has a reliable magic signature, so a failed sniff means the bytes are not a supported image..mpg). Beyond the sniff-failed image case, format acceptance is left to the provider — the tool does not gate on image format.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.