Skip to content

fix(provider): catch an empty image attachment on the file part shape - #46860

Closed
devYRPauli wants to merge 1 commit into
anomalyco:devfrom
devYRPauli:empty-image-guard
Closed

devYRPauli wants to merge 1 commit into
anomalyco:devfrom
devYRPauli:empty-image-guard

Conversation

@devYRPauli

@devYRPauli devYRPauli commented Sep 2, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #46859

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

unsupportedParts replaces an empty image with error text so the request does not reach the provider. The check read part.image, which only exists on an image part.

The prompt pipeline does not build that shape. session/message-v2.ts:220 pushes an attachment as { type: "file", url, mediaType, filename }, and convertToModelMessages keeps it a file part with the data URL in part.data. So the guard never ran on a real attachment, and the empty image went to the provider, which failed the request with its own error.

The two tests that cover the guard build the image shape by hand, so they passed while the production path was broken.

This reads the data from whichever shape the part carries. It also requires an image/ media type, so an empty PDF no longer gets a message about an image. Moving the mime line above the check is what makes that media-type test available; nothing else about mime changed.

How did you verify your code works?

bun test test/provider/transform.test.ts from packages/opencode: 557 pass, 0 fail. The whole test/provider/ directory: 706 pass, 0 fail. bun run typecheck: 30/30 tasks pass.

I reverted the source change and kept the new tests. Exactly one test fails, and it is the one that drives the real path:

- "text": "ERROR: Image file is empty or corrupted. Please provide a valid image.",
- "type": "text",
+ "data": "data:image/png;base64,",
+ "filename": "empty.png",
+ "mediaType": "image/png",
+ "type": "file",

(fail) should replace an empty image attachment that arrives as a file part
 556 pass, 1 fail

I also measured the part shape directly against the pinned [email protected], which is the evidence in the issue: convertToModelMessages returns type: "file", never type: "image".

The second new test sends a valid 1x1 PNG through the same path and asserts the part is untouched, so a regex that matched too much would fail it.

prettier --check and oxlint are clean on both files (0 errors).

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

unsupportedParts checked part.image for empty base64 data. The prompt
pipeline pushes an attachment as a file part and convertToModelMessages
keeps it as one, so the guard never ran on a real attachment and the
empty image reached the provider.

Read the data from whichever shape the part carries, and require an
image media type so an empty PDF does not get the image error text.

The two existing tests build the image shape by hand, which is why they
passed. The new tests drive convertToModelMessages instead.

Closes anomalyco#46859
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@devYRPauli

Copy link
Copy Markdown
Author

This remains on dev at 907b3bc. AI SDK 6.0.168 converts an empty image attachment to a file part, and the current unsupportedParts function leaves it unchanged. Applying this fix to that function produces the intended error text and preserves a nonempty attachment. Could you reopen this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty image attachment is not caught because the guard reads the wrong part shape

1 participant