Skip to content

The agent that grows with you

fix(image_gen): say the FAL fallback also failed instead of claiming an image was generated

Mariano Nicolini8daaaca0843d
diff --git a/tests/tools/test_image_generation_plugin_dispatch.py b/tests/tools/test_image_generation_plugin_dispatch.py
index 6439852f728..5571986191b 100644
--- a/tests/tools/test_image_generation_plugin_dispatch.py
+++ b/tests/tools/test_image_generation_plugin_dispatch.py
@@ -96,8 +96,8 @@ class TestPluginDispatch:
assert len(fal_calls) == 1 and fal_calls[0]["fal_model"] == ig.DEFAULT_MODEL
assert result["fallback_from"] == "krea"
assert result["fallback_reason"] == "Krea connection error"
- assert "FAL" in result["note"]
assert result["success"] is fal_ok
+ assert ("generated on FAL" if fal_ok else "also failed") in result["note"]
def test_deepinfra_key_alone_does_not_select_image_backend(self, monkeypatch):
"""DeepInfra chat credentials do not imply consent to image billing."""
diff --git a/tools/image_generation_tool.py b/tools/image_generation_tool.py
index e59ca9773d7..6d79ae0de7f 100644
--- a/tools/image_generation_tool.py
+++ b/tools/image_generation_tool.py
@@ -813,9 +813,11 @@ def _fall_back_to_fal(raw: str, prompt: str, aspect_ratio: str, sources: dict[st
return raw
logger.warning("Managed Krea refused the request before starting a job; falling back to FAL: %s", result.get("error"))
fal_result = json.loads(image_generate_tool(prompt, aspect_ratio, upscale=sources.get("upscale"), fal_model=DEFAULT_MODEL))
+ note = (f"Krea was unavailable, so this image was generated on FAL ({DEFAULT_MODEL}) instead."
+ if fal_result.get("success") else
+ f"Krea was unavailable and the fallback to FAL ({DEFAULT_MODEL}) also failed.")
fal_result.update(
- provider="fal", model=DEFAULT_MODEL, fallback_from="krea", fallback_reason=result.get("error"),
- note=f"Krea was unavailable, so this image was generated on FAL ({DEFAULT_MODEL}) instead.")
+ provider="fal", model=DEFAULT_MODEL, fallback_from="krea", fallback_reason=result.get("error"), note=note)
return json.dumps(fal_result)