HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
media: an empty answer says what was missing, not that the provider answered HTTP 200 (#487)
Rudy Mizrahi Celekliee1d89289e93
diff --git a/gateway/media_plane.py b/gateway/media_plane.pyindex 6041a746..57e032b4 100644--- a/gateway/media_plane.py+++ b/gateway/media_plane.py@@ -1063,7 +1063,7 @@ def _read_submit(cand: dict, status: int, doc) -> tuple[str, Payload | None]:if shape == "video-generation":tid = str(doc.get("task_id") or doc.get("id") or "")if not tid:- raise MediaEmpty(provider_message(doc, status) or+ raise MediaEmpty(provider_said(doc) or"the provider accepted the request but returned no task id")return tid, None@@ -1121,14 +1121,14 @@ def _read_submit(cand: dict, status: int, doc) -> tuple[str, Payload | None]:op = doc.get("operation")if op is not None:return json.dumps(op, separators=(",", ":")), None- raise MediaEmpty(provider_message(doc, status) or+ raise MediaEmpty(provider_said(doc) or"the provider accepted the request but returned no job handle")if shape == "vercel-speech":if doc.get("audio"):fmt = str(cand.get("format") or "mp3")return "", Payload(data=_b64(str(doc["audio"])), mime=f"audio/{fmt}")- raise MediaEmpty(provider_message(doc, status) or+ raise MediaEmpty(provider_said(doc) or"the provider answered with no audio")raise MediaError(f"No adapter for endpoint shape {shape!r}.")@@ -1216,7 +1216,7 @@ def _read_poll(cand: dict, status: int, doc) -> tuple[str, Payload | None, str,# Completed with nothing in it billed and delivered nothing. Same rule as everywhere.return "failed", None, "the provider reported completed and returned no video", ""if st in ("failed", "cancelled", "canceled"):- return "failed", None, scrub(provider_message(doc, status)+ return "failed", None, scrub(provider_said(doc)or f"the render ended as {st}"), ""if st == "pending" or not st:return "running", None, "", ""@@ -1356,6 +1356,12 @@ def _clean(value):def provider_message(doc, status: int) -> str:"""The provider's own sentence, which is what the agent needs — never our paraphrase of it.Scrubbed of credentials, which is not a paraphrase: everything that diagnoses survives."""+ return provider_said(doc) or f"the provider answered HTTP {status}"+++def provider_said(doc) -> str:+ """The provider's own sentence in this body, "" when it carried none. A caller with a better+ sentence than "the provider answered HTTP 200" for a body that said nothing uses this one."""if isinstance(doc, dict):for key in ("message", "error", "detail", "msg"):v = doc.get(key)@@ -1384,7 +1390,7 @@ def provider_message(doc, status: int) -> str:return scrub("; ".join(said))if isinstance(doc.get("code"), str) and doc["code"] and doc["code"] != "success":return scrub(str(doc["code"]))- return f"the provider answered HTTP {status}"+ return ""def usage_usd(doc) -> float | None:diff --git a/gateway/tests/test_media_mcp.py b/gateway/tests/test_media_mcp.pyindex a48117c4..70732021 100644--- a/gateway/tests/test_media_mcp.py+++ b/gateway/tests/test_media_mcp.py@@ -3274,3 +3274,32 @@ def test_an_import_that_is_not_media_is_refused_rather_than_stored(api, harness,r = api.post(base, content=b"this is not a picture")assert r.status_code == 415, r.textassert api.post(base, content=b"").status_code == 400+++def test_a_submit_that_answered_without_its_handle_says_which_one_was_missing():+ """A 200 with no task id, job handle or audio was meant to say so in our own sentence when the+ provider gave none. provider_message never returns "", so the `or` never reached that sentence+ and the agent read "the provider answered HTTP 200", which says nothing went wrong."""+ for shape, said in (("video-generation", "returned no task id"),+ ("vercel-video", "returned no job handle"),+ ("vercel-speech", "answered with no audio")):+ with pytest.raises(media_plane.MediaEmpty) as e:+ media_plane.read_submit({"shape": shape}, 200, {"status": "queued"})+ assert said in str(e.value), (shape, str(e.value))+ assert "HTTP 200" not in str(e.value)+++def test_a_submit_without_its_handle_still_carries_the_providers_own_sentence():+ with pytest.raises(media_plane.MediaEmpty) as e:+ media_plane.read_submit({"shape": "video-generation"}, 200, {"error": {"message": "quota exhausted"}})+ assert "quota exhausted" in str(e.value)+ assert media_plane.provider_message({}, 503) == "the provider answered HTTP 503"+++def test_a_render_that_ended_without_a_reason_says_how_it_ended():+ """The same dead fallback on the poll: a vercel-video job that ended `cancelled` with no message+ was reported as "the provider answered HTTP 200" instead of "the render ended as cancelled"."""+ st, _, err, _ = media_plane.read_poll({"shape": "vercel-video"}, 200, {"status": "cancelled"})+ assert st == "failed" and err == "the render ended as cancelled", err+ st, _, err, _ = media_plane.read_poll({"shape": "vercel-video"}, 200, {"status": "failed", "error": "nsfw"})+ assert st == "failed" and "nsfw" in err, err