The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(video): bind managed SeedVR to source request
Teknium05330e804af9
diff --git a/plugins/video_gen/fal/__init__.py b/plugins/video_gen/fal/__init__.pyindex 3ce20e3d5ef..3d5714d781e 100644--- a/plugins/video_gen/fal/__init__.py+++ b/plugins/video_gen/fal/__init__.py@@ -617,7 +617,10 @@ UPSCALER_ENDPOINT = "fal-ai/seedvr/upscale/video"UPSCALER_FACTOR = 2-def _upscale_video(video_url: str) -> Optional[str]:+def _upscale_video(+ video_url: str,+ source_request_id: Optional[str] = None,+) -> Optional[str]:"""Upscale a generated video via SeedVR2; return the new URL or None.Best-effort: any failure logs and returns ``None`` so the caller falls@@ -626,11 +629,16 @@ def _upscale_video(video_url: str) -> Optional[str]:"""try:logger.info("Upscaling video with SeedVR2 (%dx)...", UPSCALER_FACTOR)- handle = _submit_fal_video_request(UPSCALER_ENDPOINT, {+ arguments: Dict[str, Any] = {"video_url": video_url,"upscale_mode": "factor","upscale_factor": UPSCALER_FACTOR,- })+ }+ if _resolve_managed_fal_video_gateway() is not None:+ if not source_request_id:+ raise RuntimeError("Managed SeedVR upscale requires the source FAL request id")+ arguments["source_request_id"] = source_request_id+ handle = _submit_fal_video_request(UPSCALER_ENDPOINT, arguments)result = handle.get()except Exception as exc: # noqa: BLE001logger.warning("Video upscale failed: %s", exc)@@ -832,6 +840,7 @@ class FALVideoGenProvider(VideoGenProvider):try:handle = _submit_fal_video_request(endpoint, payload)+ source_request_id = getattr(handle, "request_id", None)result = handle.get()except Exception as exc:logger.warning(@@ -864,7 +873,7 @@ class FALVideoGenProvider(VideoGenProvider):# video rather than failing the generation.upscaled = Falseif upscale:- upscaled_url = _upscale_video(url)+ upscaled_url = _upscale_video(url, source_request_id)if upscaled_url:url = upscaled_urlupscaled = Truediff --git a/tests/plugins/video_gen/test_fal_plugin.py b/tests/plugins/video_gen/test_fal_plugin.pyindex 0ab8802ab80..883ed2ed5b9 100644--- a/tests/plugins/video_gen/test_fal_plugin.py+++ b/tests/plugins/video_gen/test_fal_plugin.py@@ -2,6 +2,8 @@from __future__ import annotations+from unittest.mock import Mock+import pytestfrom agent import video_gen_registry@@ -544,10 +546,60 @@ class TestUpscalePass:from plugins.video_gen import fal as fal_pluginfrom plugins.video_gen.fal import FALVideoGenProvider- monkeypatch.setattr(fal_plugin, "_upscale_video", lambda url: None)+ monkeypatch.setattr(+ fal_plugin,+ "_upscale_video",+ lambda url, source_request_id=None: None,+ )result = FALVideoGenProvider().generate("a dog", model="pixverse-v6", upscale=True,)assert result["success"] is Trueassert result["video"] == "https://fake/native.mp4"assert result["upscaled"] is False++ def test_managed_upscale_binds_the_source_request(self, monkeypatch):+ from plugins.video_gen import fal as fal_plugin++ captured = {}++ class FakeHandle:+ def get(self):+ return {"video": {"url": "https://fake/upscaled.mp4"}}++ monkeypatch.setattr(+ fal_plugin,+ "_resolve_managed_fal_video_gateway",+ lambda: object(),+ )+ monkeypatch.setattr(+ fal_plugin,+ "_submit_fal_video_request",+ lambda endpoint, arguments: (+ captured.update(endpoint=endpoint, arguments=arguments)+ or FakeHandle()+ ),+ )++ assert (+ fal_plugin._upscale_video(+ "https://fake/native.mp4",+ "source-request-1",+ )+ == "https://fake/upscaled.mp4"+ )+ assert captured["arguments"]["source_request_id"] == "source-request-1"++ def test_managed_upscale_without_source_request_falls_back(self, monkeypatch):+ from plugins.video_gen import fal as fal_plugin++ submit = Mock()+ monkeypatch.setattr(+ fal_plugin,+ "_resolve_managed_fal_video_gateway",+ lambda: object(),+ )+ monkeypatch.setattr(fal_plugin, "_submit_fal_video_request", submit)++ assert fal_plugin._upscale_video("https://fake/native.mp4") is None+ submit.assert_not_called()