Repository navigation
fix(core): omit undersized xAI images from requests - #54327
batteryshark wants to merge 2 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
This looks good. I ran the reproduction from #54325 against the request-preparation code: on the base, the stored 6×8 PNG from the read result is still sent to xAI; with this change it is replaced by the text notice. The added tests and the packages/core type check pass. I didn't make a real xAI request because there are no credentials here. The header parsing for PNG, JPEG and WebP looks correct, and if a header is cut off or unrecognised it returns nothing without throwing, so the image is sent as before.
Public API: unchanged (everything touched is internal to packages/core).
One thing worth fixing: the whole image is decoded on every turn just to read its header (see the inline comment). Also, open #53803 changes xAI's image check to match Grok models on any provider, while this check only looks at provider === "xai". Whichever lands second should line the two up.
Related: #52042
|
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:
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. |
Issue for this PR
Closes #54325
Type of change
What does this PR do?
Reading a 6×8 image with Grok stores it in tool history. xAI rejects it on every subsequent request, so another user message cannot recover the session.
Filter inline PNG, JPEG and WebP images below xAI's 8-pixel minimum in request preparation, replacing them with an explicit text notice. This covers user attachments and replayed tool results, preserves stored messages and source files, and leaves other providers unchanged. Remote URLs are not inspected. The notice asks the agent to pad or enlarge the image before reading it again.
How did you verify your code works?
bun test test/image-dimensions.test.ts test/session-model-request.test.tsinpackages/core: 15 passed. Generated fixtures cover both dimension boundaries, baseline/progressive JPEG and lossy/lossless WebP; tests also cover byte-backed attachments, history preservation, truncated WebP chunks, and JPEG frame headers beyond the bounded prefix. Header inspection decodes at most 64 KiB of base64 (48 KiB of bytes) per image; headers beyond this prefix are left unchanged.ASTRO_TELEMETRY_DISABLED=1 bun run check: passed (lint and all 36 workspace type-check tasks).Related integration: #53803 is still open and widens the existing image-type guard to Grok models served by gateways. Whichever PR lands second should apply this dimension check under the same provider/family predicate.
Screenshots / recordings
Request preparation only; no rendered UI change.
Checklist
Added by the opencode bot (AI-generated).
Related: #52042