The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(local-runtime): transcode WebP to PNG for the managed server — its decoder drops WebP silently
emozilla3e899b258f0b
diff --git a/agent/image_routing.py b/agent/image_routing.pyindex 17a0e2696f5..cc07c831a73 100644--- a/agent/image_routing.py+++ b/agent/image_routing.py@@ -734,12 +734,31 @@ def _file_to_data_url(path: Path) -> Optional[str]:logger.warning("image_routing: failed to read %s — %s", path, exc)return Nonemime = _guess_mime(path, raw=raw)- if mime not in _UNIVERSALLY_SUPPORTED_MIMES:+ accepted = _UNIVERSALLY_SUPPORTED_MIMES+ # The managed local server decodes fewer formats than cloud providers+ # (no WebP — and a WebP part fails SILENTLY: the model never sees an+ # image and confabulates a description). When the active main model is+ # served by the managed runtime, narrow the accepted set so those+ # formats transcode to PNG here instead of vanishing server-side.+ try:+ from agent.auxiliary_client import _runtime_main_value+ from hermes_cli.local_runtime.capabilities import (+ ACCEPTED_IMAGE_MIMES,+ is_managed_provider,+ )++ if is_managed_provider(+ str(_runtime_main_value("provider") or ""),+ str(_runtime_main_value("base_url") or "")):+ accepted = ACCEPTED_IMAGE_MIMES+ except Exception: # noqa: BLE001 — best-effort narrowing only+ pass+ if mime not in accepted:transcoded = _transcode_to_png(raw)if transcoded is None:logger.warning(- "image_routing: %s is %s which is not accepted by all major "- "vision providers and could not be transcoded to PNG; "+ "image_routing: %s is %s which is not accepted by the "+ "active provider and could not be transcoded to PNG; ""skipping this attachment.",path, mime,)diff --git a/hermes_cli/local_runtime/capabilities.py b/hermes_cli/local_runtime/capabilities.pyindex 9d979e343a4..b30152fadfd 100644--- a/hermes_cli/local_runtime/capabilities.py+++ b/hermes_cli/local_runtime/capabilities.py@@ -29,6 +29,14 @@ logger = logging.getLogger(__name__)_LLAMACPP_ALIASES = frozenset({"llamacpp", "llama.cpp", "llama-cpp"})+# Image formats the managed server's decoder actually handles. llama.cpp+# decodes with stb_image: PNG/JPEG/GIF/BMP yes, WebP NO — and a WebP part+# fails SILENTLY (no HTTP error, no log line; the model just never sees an+# image and confabulates a description). Anything outside this set must be+# transcoded before the request. Measured against the live server: the+# same red square answered 'Red' as PNG and 'Unseen' as WebP.+ACCEPTED_IMAGE_MIMES = frozenset({"image/png", "image/jpeg"})+def is_managed_provider(provider: str, base_url: str = "") -> bool:"""True when this provider/base_url pair points at the managed server.diff --git a/tests/hermes_cli/test_managed_vision_capability.py b/tests/hermes_cli/test_managed_vision_capability.pyindex 4a17d54eebf..1ad35b1a4b2 100644--- a/tests/hermes_cli/test_managed_vision_capability.py+++ b/tests/hermes_cli/test_managed_vision_capability.py@@ -108,3 +108,49 @@ def test_lookup_chain_consults_managed_runtime(hermes_home, monkeypatch):"supports_vision": False}}got = ir._lookup_supports_vision("llamacpp", "Some-Local-Model", cfg)assert got is False+++def test_webp_transcodes_to_png_for_managed_provider(hermes_home, monkeypatch, tmp_path):+ """A .webp attachment bound for the managed server must arrive as PNG:+ llama.cpp's stb_image decoder has no WebP support and drops the part+ SILENTLY — the model confabulates a description of an image it never+ saw. Measured live: the same red square answered 'Red' as PNG and+ 'Unseen' as WebP."""+ pytest.importorskip("PIL")+ import io++ from PIL import Image++ import agent.image_routing as ir++ webp_path = tmp_path / "shot.webp"+ img = Image.new("RGB", (32, 32), (255, 0, 0))+ img.save(webp_path, format="WEBP")++ monkeypatch.setattr("agent.auxiliary_client._runtime_main_value",+ lambda k: {"provider": "llamacpp",+ "base_url": ""}.get(k, ""))++ data_url = ir._file_to_data_url(webp_path)+ assert data_url is not None+ assert data_url.startswith("data:image/png;base64,"), (+ "webp must transcode to png for the managed server")+++def test_webp_passes_through_for_cloud_providers(hermes_home, monkeypatch, tmp_path):+ """Cloud providers accept WebP natively — no transcode tax for them."""+ pytest.importorskip("PIL")+ from PIL import Image++ import agent.image_routing as ir++ webp_path = tmp_path / "shot.webp"+ Image.new("RGB", (32, 32), (255, 0, 0)).save(webp_path, format="WEBP")++ monkeypatch.setattr("agent.auxiliary_client._runtime_main_value",+ lambda k: {"provider": "anthropic",+ "base_url": ""}.get(k, ""))++ data_url = ir._file_to_data_url(webp_path)+ assert data_url is not None+ assert data_url.startswith("data:image/webp;base64,")