Skip to content

fix(image-gen): honor top-level image_gen.model and dispatch model kwarg in the xAI provider - #55927

Closed
Frowtek wants to merge 1 commit into
NousResearch:mainfrom
Frowtek:fix/image-gen-xai-honor-top-level-model
Closed

fix(image-gen): honor top-level image_gen.model and dispatch model kwarg in the xAI provider#55927
Frowtek wants to merge 1 commit into
NousResearch:mainfrom
Frowtek:fix/image-gen-xai-honor-top-level-model

Conversation

@Frowtek

@Frowtek Frowtek commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a parity gap in image-gen model resolution. hermes tools persists the
selected image model to the top-level image_gen.model, and the
image_generate dispatcher forwards it to provider.generate() as a model
kwarg. The xAI provider read only the scoped image_gen.xai.model (plus
the XAI_IMAGE_MODEL env var) and called _resolve_model() with no arguments
— so a user's hermes tools selection was silently dropped and xAI always fell
back to its default grok-imagine-image.

This is the same gap recently fixed for the OpenRouter/Nous provider; openai,
openai-codex and krea already honor the top-level image_gen.model, so xAI was
the lone holdout. This brings xAI in line with the rest.

Related Issue

N/A

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • plugins/image_gen/xai/__init__.py
    • Add _load_image_gen_config() — reads the top-level image_gen section.
    • _resolve_model(explicit=None) now follows the same precedence as the
      other providers: explicit dispatch model kwarg → XAI_IMAGE_MODEL env →
      scoped image_gen.xai.model → top-level image_gen.modelDEFAULT_MODEL.
    • generate() forwards the dispatched kwarg: _resolve_model(kwargs.get("model")).
    • The scoped reader _load_xai_config and _resolve_resolution are left untouched.
  • tests/plugins/image_gen/test_xai_provider.py — add scoped / top-level /
    explicit-kwarg model-resolution coverage.

How to Test

Reproduction: set the image model in the top-level image_gen.model (what
hermes tools writes) without a scoped image_gen.xai.model, then resolve the
xAI model.

  • Before: plugins.image_gen.xai._resolve_model() returns grok-imagine-image
    (the default) — the selection is ignored.
  • After: it returns the selected model. The scoped key still works, and an
    explicit dispatched model kwarg wins over config.

Tests run and results:

pytest tests/plugins/image_gen/test_xai_provider.py::TestConfig -v

  TestConfig::test_default_model ........................... PASSED
  TestConfig::test_default_resolution ...................... PASSED
  TestConfig::test_custom_model ............................ PASSED
  TestConfig::test_scoped_config_model            (new) .... PASSED
  TestConfig::test_top_level_config_model         (new) .... PASSED
  TestConfig::test_explicit_model_kwarg_wins_over_config (new)  PASSED
  => 6 passed

The change is isolated to xAI model resolution; verified against an unmodified
baseline that it introduces no new failures in the full
tests/plugins/image_gen/ suite (it adds the 3 passing tests above).

Checklist

  • Read the Contributing Guide; commit follows Conventional Commits (fix(image-gen): …)
  • Searched existing PRs/issues to avoid a duplicate
  • PR contains only changes related to this fix
  • Ran the tests for the affected area — pass (results above)
  • Added tests for the change
  • Documentation / config / tool-schema — N/A (no new config keys; image_gen.model is already documented and honored by the other providers)

…arg in the xAI provider

`hermes tools` persists the selected image model to the top-level
`image_gen.model`, and the image_generate dispatcher forwards it as a `model`
kwarg to `provider.generate()`. The xAI provider read only the scoped
`image_gen.xai.model` (plus the `XAI_IMAGE_MODEL` env var) and called
`_resolve_model()` with no arguments, so a user's `hermes tools` selection was
silently dropped — xAI always fell back to its default `grok-imagine-image`.

This is the same gap recently fixed for the OpenRouter/Nous provider; openai,
openai-codex and krea already honor the top-level key, so xAI was the lone
holdout.

Mirror the established precedence (explicit dispatch `model` kwarg →
`XAI_IMAGE_MODEL` env → scoped `image_gen.xai.model` → top-level
`image_gen.model` → `DEFAULT_MODEL`) by adding an `explicit` parameter and a
top-level fallthrough to `_resolve_model`, and passing the dispatched kwarg
from `generate()`. The scoped config reader (`_load_xai_config`) and the
resolution lookup are left untouched.

Adds top-level / scoped / explicit-kwarg coverage to
tests/plugins/image_gen/test_xai_provider.py::TestConfig.
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins tool/vision Vision analysis and image generation provider/xai xAI (Grok) P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jun 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #55893 -- both make plugins/image_gen/xai/_resolve_model() accept a caller-supplied model override at top precedence and thread kwargs.get("model") from generate(), so the top-level image_gen.model is honored for xAI instead of falling back to grok-imagine-image. Same file, same mechanism; #55893 is the earlier open PR. Marking this as the duplicate; maintainer to pick whichever is cleaner. Both mirror the merged Nous/OpenRouter fix #55672.

@teknium1 teknium1 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.

Thanks for tracing the configuration path. The fix matches the current dispatcher contract: tools/image_generation_tool.py:1336-1349 forwards top-level image_gen.model, while current xAI code drops it at plugins/image_gen/xai/__init__.py:242 by calling _resolve_model() without arguments.

Problems

  • The new resolver tests do not exercise the changed generate() forwarding call. tests/plugins/image_gen/test_xai_provider.py:139-157 already mocks a successful generation, but it does not pass model= or assert the outbound JSON payload. This leaves the exact dispatch behavior changed at plugins/image_gen/xai/__init__.py:259 unverified.

Suggested changes

  • Add a generation-path regression test passing model="grok-imagine-image-quality" and asserting both the returned model and requests.post JSON payload use that ID. The earlier duplicate #55893 includes this shape of coverage.

Automated hermes-sweeper review.

@@ -234,7 +259,7 @@ def generate(
aspect_ratio=aspect_ratio,

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.

Please add a generation-path regression test for this forwarding call: invoke generate(..., model="grok-imagine-image-quality") and assert the mocked POST JSON contains that model. The new tests currently exercise _resolve_model() directly, not this changed dispatch path.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 15, 2026
@andrexibiza

Copy link
Copy Markdown
Contributor

Campaign #80424 collision class — XAI-IMAGE-MODEL

This PR is part of a collision class adjudicated under the Grok/xAI campaign rebaseline (2026-08-14). The canonical disposition is recorded on #80424.

Implementation of this class is blocked until Wave 0 (T00-T04) completes classification and the canonical collision/supersession table is agreed.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks @Frowtek — the fix this PR implements is now on main via #89890. We salvaged #55893, which was the earliest submission of the same model-kwarg forwarding mechanism (yours followed by ~90 minutes), so first credit went there per our earliest-submitter policy.

Worth noting: your additional top-level image_gen.model fallback inside the provider turned out unnecessary — the dispatcher already forwards that config value as the model kwarg, which the landed fix now honors. Your precedence analysis in the PR description was accurate and helped confirm the fix shape.

Closing as implemented on main. Thanks for the contribution!

@teknium1 teknium1 closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have provider/xai xAI (Grok) sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants