From 1a4c2df19e0eab6fd5960d333c7fc0013b9c9aaf Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 15 Jun 2026 06:53:18 -0700 Subject: [PATCH] fix(vision): respect MiMo tool-result media limits Salvages the Xiaomi MiMo vision fast-path fixes from #39692/#45571/#43686 into one focused provider-capability gate. Co-authored-by: liuhao1024 Co-authored-by: gkd2323c Co-authored-by: NemoJaaskelainen <82179872+NemoJaaskelainen@users.noreply.github.com> --- scripts/release.py | 2 + tests/tools/test_vision_native_fast_path.py | 29 +++++++++++++ tools/vision_tools.py | 48 +++++++++++++-------- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/scripts/release.py b/scripts/release.py index e5b0fd2226dc..0ee76c7861a6 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -541,6 +541,7 @@ AUTHOR_MAP = { "79389617+txbxxx@users.noreply.github.com": "txbxxx", "liuhao03@bilibili.com": "liuhao1024", "130918800+devorun@users.noreply.github.com": "devorun", + "82179872+NemoJaaskelainen@users.noreply.github.com": "NemoJaaskelainen", "surat.s@itm.kmutnb.ac.th": "beesrsj2500", "beesr@bee.localdomain": "beesrsj2500", "mind-dragon@nous.research": "Mind-Dragon", @@ -1545,6 +1546,7 @@ AUTHOR_MAP = { "andreas@schwarz-ketsch.de": "Nea74", # PR #40022 co-author credit (same Windows ConPTY bridge design) "chanhokyim@gmail.com": "joel611", # PR #33958 salvage (DISCORD_ALLOWED_ROLES role_authorized gateway flag) "desg38@gmail.com": "dschnurbusch", # PR #42373 salvage (archive compressed conversation lineages) + "gkd2323c@users.noreply.github.com": "gkd2323c", # PR #45571 salvage (Xiaomi MiMo vision tool-result routing) "bsmith@bramarstrategicservices.com": "bcsmith528", # PR #20589 salvage (register_slack_action_handler plugin API) "sunsky.lau@gmail.com": "liuhao1024", # PR #45494 salvage (claim session slot before auto-resume task; #45456) "andrewdmwalker@gmail.com": "capt-marbles", # PR #38440 salvage (resolve xAI OAuth credentials across profiles; #43589) diff --git a/tests/tools/test_vision_native_fast_path.py b/tests/tools/test_vision_native_fast_path.py index bb396c05dc36..754c4c370c19 100644 --- a/tests/tools/test_vision_native_fast_path.py +++ b/tests/tools/test_vision_native_fast_path.py @@ -53,6 +53,9 @@ class TestSupportsMediaInToolResults: def test_gemini_2_no(self): assert _supports_media_in_tool_results("google", "gemini-2.5-pro") is False + def test_xiaomi_vision_models_reject_tool_result_media(self): + assert _supports_media_in_tool_results("xiaomi", "mimo-v2.5-pro") is False + def test_unknown_provider_conservative_no(self): assert _supports_media_in_tool_results("brand-new-provider", "any-model") is False @@ -273,6 +276,32 @@ class TestHandleVisionAnalyzeFastPath: assert isinstance(result, dict) and result.get("_multimodal") is True mock_aux.assert_not_called() + def test_supports_vision_override_does_not_bypass_provider_tool_result_deny(self, tmp_path): + """Xiaomi accepts image user messages but rejects image tool results.""" + img = tmp_path / "x.png" + img.write_bytes(_TINY_PNG) + + async def _aux_sentinel(*args, **kwargs): + return '{"sentinel": "aux-path"}' + + from agent.auxiliary_client import set_runtime_main, clear_runtime_main + set_runtime_main("xiaomi", "mimo-v2.5-pro") + try: + with patch( + "hermes_cli.config.load_config", + return_value={"model": {"supports_vision": True}}, + ), patch( + "tools.vision_tools.vision_analyze_tool", side_effect=_aux_sentinel, + ) as mock_aux: + coro = _handle_vision_analyze({"image_url": str(img), "question": "?"}) + result = asyncio.get_event_loop().run_until_complete(coro) + finally: + clear_runtime_main() + + assert isinstance(result, str) + assert json.loads(result) == {"sentinel": "aux-path"} + mock_aux.assert_called_once() + def test_text_mode_wins_over_supports_vision_override(self, tmp_path): """Explicit text routing blocks the fast path even with supports_vision.""" img = tmp_path / "x.png" diff --git a/tools/vision_tools.py b/tools/vision_tools.py index cfc933dae0fb..477a8534c521 100644 --- a/tools/vision_tools.py +++ b/tools/vision_tools.py @@ -545,8 +545,9 @@ def _supports_media_in_tool_results(provider: str, model: str) -> bool: results. Older Gemini does NOT. For unknown / legacy providers we conservatively return False — the - caller falls back to the legacy aux-LLM text path. The check is relaxed - when the provider's ``ProviderProfile`` declares ``supports_vision=True``. + caller falls back to the legacy aux-LLM text path. Model-level vision + support is deliberately not enough here: providers like Xiaomi MiMo accept + image content in user messages but reject list-type tool-result content. """ if not isinstance(provider, str): return False @@ -554,6 +555,16 @@ def _supports_media_in_tool_results(provider: str, model: str) -> bool: if not p: return False + # Provider profiles can explicitly deny list-type tool-result content + # even when their models accept multimodal user messages. + try: + from providers import get_provider_profile + profile = get_provider_profile(p) + if profile is not None and getattr(profile, "supports_vision_tool_messages", True) is False: + return False + except Exception: + pass + # Aggregators that route to multiple vendors — assume support since # users on these aggregators are typically using vision-capable # frontier models. Falling back to text would be a regression for @@ -583,17 +594,6 @@ def _supports_media_in_tool_results(provider: str, model: str) -> bool: return True return False - # Check the provider's registered profile for the supports_vision flag. - # This covers vision-capable providers like xiaomi, minimax, etc. that - # aren't in the hardcoded list above. - try: - from providers import get_provider_profile - profile = get_provider_profile(p) - if profile is not None and profile.supports_vision: - return True - except Exception: - pass - # Other vision-capable provider stacks. Conservative default: False. # Add explicit entries here as we verify each provider's tool-result # multimodal support empirically. @@ -606,14 +606,15 @@ def _should_use_native_vision_fast_path() -> bool: True when image routing resolves to ``native`` AND either the provider is known to accept images inside tool results, or the user explicitly declared - the model vision-capable via the ``model.supports_vision`` config override. - The override is the escape hatch for custom/local providers that aren't in - the static allowlist. Best-effort: any resolution failure returns False so - the caller falls back to the legacy aux-LLM path. + the model vision-capable via the ``model.supports_vision`` config override + without the provider profile explicitly denying tool-message vision. The + override is the escape hatch for custom/local providers that aren't in the + static allowlist. Best-effort: any resolution failure returns False so the + caller falls back to the legacy aux-LLM path. """ try: from agent.auxiliary_client import _read_main_provider, _read_main_model - from agent.image_routing import decide_image_input_mode, _lookup_supports_vision + from agent.image_routing import decide_image_input_mode, _supports_vision_override from hermes_cli.config import load_config provider = _read_main_provider() @@ -621,9 +622,18 @@ def _should_use_native_vision_fast_path() -> bool: cfg = load_config() if decide_image_input_mode(provider, model, cfg) != "native": return False + + try: + from providers import get_provider_profile + profile = get_provider_profile((provider or "").strip()) + if profile is not None and getattr(profile, "supports_vision_tool_messages", True) is False: + return False + except Exception: + pass + return ( _supports_media_in_tool_results(provider, model) - or _lookup_supports_vision(provider, model, cfg) is True + or _supports_vision_override(cfg, provider, model) is True ) except Exception as exc: logger.debug("Native vision fast-path check failed: %s", exc)