Skip to content

fix(core): apply the Grok image guard to Grok served by any provider - #53803

Open
neriousy wants to merge 2 commits into
v2from
grok-image-guard
Open

neriousy wants to merge 2 commits into
v2from
grok-image-guard

Conversation

@neriousy

@neriousy neriousy commented Oct 7, 2026

Copy link
Copy Markdown
Member

Issue for this PR

Follow-up to #53787 (#53786).

Type of change

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

What does this PR do?

#53787 stops sending GIFs and other non-PNG/JPEG/WebP images to xAI, but it checks the catalog provider ID. Grok served through OpenCode Zen (opencode/grok-4.7) has provider opencode, so the check never matches. Zen passes the GIF to xAI, gets Downloaded response does not contain a valid JPG, PNG, WebP, or ICO image., and the session stays stuck.

  • core: ModelResolver.Resolved now carries the catalog model family. The image check applies when the provider is xai or the family starts with grok (grok and grok-build in the catalog). This covers Zen, and Grok from other hosts such as Copilot, OpenRouter, Azure and Bedrock, which use the same families. Like fix(core): only send png, jpeg and webp images to xAI #53787, it runs when the request is built, so stuck sessions recover.
  • ai: Over the xAI WebSocket transport (the default), invalid_image arrives with no HTTP status and type: "api_error". api_error is a server code, so the error was classified as ProviderInternal and retried. A stuck session spent about 95 seconds (11 attempts) on every message before failing. invalid_image is now an invalid-request code, and an invalid-request code outranks a server code in the same body when there is no status.

How did you verify your code works?

  • New tests in session-model-request.test.ts (Grok family under a non-xAI provider) and provider-error.test.ts (the error body recorded from xAI). Both fail without the change.
  • bun typecheck and bun run check pass. The full packages/core and packages/ai suites have 7 and 2 failures (shell parsing, Bedrock PDF recordings) that also fail on clean v2.
  • Live runs with a still GIF, an animated GIF, a PNG, the read tool on a GIF, and follow-up turns:
  • I could not trigger invalid_image live after the fix, because OpenCode rejects undecodable images before sending them and GIFs no longer reach xAI. The retry fix is covered by the unit test with the recorded body.

Screenshots / recordings

N/A

Checklist

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

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant