Skip to content

fix(core): omit undersized xAI images from requests - #54327

Closed
batteryshark wants to merge 2 commits into
anomalyco:devfrom
batteryshark:grok-image-minimum
Closed

batteryshark wants to merge 2 commits into
anomalyco:devfrom
batteryshark:grok-image-minimum

Conversation

@batteryshark

@batteryshark batteryshark commented Oct 10, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #54325

Type of change

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

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.ts in packages/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).
  • On installed OpenCode 2.0.25, an equivalent local request-hook guard recovered the original failing Grok session; it accepted a new prompt and completed successfully. The core source change itself was validated by the regression tests above.

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

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

Added by the opencode bot (AI-generated).

Related: #52042

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:41
@github-actions

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.

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.

xAI: undersized images persist in history and prevent session recovery

1 participant