Skip to content

fix(image_gen): soft-accept configured provider in check_fn (#16027) - #16377

Closed
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/16027-image-generate-discovery-race
Closed

Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/16027-image-generate-discovery-race

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

check_image_generation_requirements returned False when:

  1. FAL_KEY was not set, AND
  2. Plugin discovery hadn't yet registered the provider named in image_gen.provider.

The cached check_fn result determines tool availability for the session's lifetime, so a discovery race at gateway/session init left image_generate permanently excluded from the session — even though _handle_image_generate (which retries discovery with force=True, courtesy of #14502) and the underlying provider both work fine when invoked directly. The user sees the tool simply missing, with no diagnostic.

This PR is the missing companion to #14502: that PR fixed the symptom at call time; this one fixes it at check time. Without both, the tool isn't in the session's tool list to be retried at call time.

Adds a soft-accept gate between the FAL branch and the plugin probe in check_image_generation_requirements: if image_gen.provider is explicitly set in config.yaml (and is not fal, which is the in-tree backend), trust that the user wants this tool and surface it. Provider availability is re-checked at call time in _dispatch_to_plugin_provider, which retries discovery and returns a clear provider_not_registered error if the named plugin still isn't there.

Mirrors the soft-accept pattern used for browser-cdp (#15952) and openai-codex models (#16172).

Related Issue

Fixes #16027

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • tools/image_generation_tool.py: insert a soft-accept gate in check_image_generation_requirements() between the FAL branch and the plugin probe. If _read_configured_image_provider() returns a non-fal value, return True without requiring registry population.
  • tests/tools/test_image_generation_check_fn.py (new): 4 tests covering the new behavior plus regression guards.

How to Test

  1. scripts/run_tests.sh tests/tools/test_image_generation_check_fn.py tests/tools/test_image_generation_env.py tests/tools/test_image_generation.py tests/tools/test_image_generation_plugin_dispatch.py — 65 pass.
  2. Revert tools/image_generation_tool.py change → 2 of 4 new tests fail (the new-behavior tests; the 2 regression guards still pass).
  3. Manual repro from the issue: configure image_gen.provider: openai-codex with valid Codex OAuth, restart gateway, send a message — image_generate is now in the session's tool list (previously missing in some sessions due to the race).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15 (Darwin 24.6.0)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

scripts/run_tests.sh tests/tools/test_image_generation_check_fn.py tests/tools/test_image_generation_env.py tests/tools/test_image_generation.py tests/tools/test_image_generation_plugin_dispatch.py
# 65 pass

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets tool/vision Vision analysis and image generation labels Apr 27, 2026
@Tranquil-Flow
Tranquil-Flow force-pushed the fix/16027-image-generate-discovery-race branch from b2f9d59 to b4e6426 Compare May 25, 2026 09:13
…arch#16027)

`check_image_generation_requirements` returned False when:

  1. FAL_KEY was not set, AND
  2. Plugin discovery hadn't yet registered the provider named in
     `image_gen.provider`.

The cached `check_fn` result determines tool availability for the
session's lifetime, so a discovery race at gateway/session init left
`image_generate` permanently excluded — even though
`_handle_image_generate` (which retries discovery with `force=True`) and
the underlying provider both work fine when invoked directly. The user
sees the tool simply missing, with no diagnostic.

Add a soft-accept gate between the FAL branch and the plugin probe: if
`image_gen.provider` is explicitly set in config.yaml (and is not
"fal", which is the in-tree backend), trust that the user wants this
tool and surface it. Provider availability is re-checked at call time
in `_dispatch_to_plugin_provider`, which retries discovery and returns
a clear "provider_not_registered" error if the named plugin still
isn't there. Mirrors the soft-accept pattern used for browser-cdp
(NousResearch#15952) and openai-codex models (NousResearch#16172).

Adds tests/tools/test_image_generation_check_fn.py covering:
  * configured provider + empty registry → True (the original repro)
  * configured provider registered but is_available()=False → True
  * no config + no FAL + empty registry → False (regression guard)
  * provider="fal" + FAL_KEY unset → False (don't soft-accept fal)

The 2 new-behavior tests fail without the fix; the 2 regression guards
pass either way.
@Tranquil-Flow
Tranquil-Flow force-pushed the fix/16027-image-generate-discovery-race branch from b4e6426 to fabe634 Compare May 25, 2026 11:05
@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the focused regression coverage.

This automated hermes-sweeper review found that the linked #16027 behavior is already implemented on current main:

Closing as superseded by the implementation already on main.

@teknium1 teknium1 closed this Jul 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main 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.

[Bug]: image_generate check_fn returns False at session init due to plugin discovery timing — tool permanently excluded

3 participants