Skip to content

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.

gateway: an export refuses a sound whose bytes are gone, as it does a shot and a layer (#564)

Rudy Mizrahi Celekliffc4e46a3ea8
diff --git a/gateway/app.py b/gateway/app.py
index 1a71c206..ae40b7e0 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -15834,7 +15834,7 @@ async def _media_export_run(job: dict, plan: list[dict], audio_plan: list[dict],
data = await _blob_get(_media_blob(sid, a["media_id"], str(meta.get("ext") or "wav")),
kb=BLOB_KB)
if not data:
- continue
+ raise media_plane.ExportRefused(f"Sound {j + 1} is no longer readable.")
path = os.path.join(tmp, f"track{j}.{meta.get('ext') or 'wav'}")
pathlib.Path(path).write_bytes(data)
tracks.append({"path": path, "start_s": a["start_s"], "gain_db": a["gain_db"]})
diff --git a/gateway/tests/test_media_mcp.py b/gateway/tests/test_media_mcp.py
index 596eb71e..5adc600e 100644
--- a/gateway/tests/test_media_mcp.py
+++ b/gateway/tests/test_media_mcp.py
@@ -2287,6 +2287,61 @@ def test_a_layer_that_has_not_landed_refuses_the_export_like_a_shot(client, harn
assert "Layer 1 is still rendering" in json.dumps(err), err
+@needs_ffmpeg
+def test_a_sound_whose_bytes_are_gone_refuses_the_export_like_a_shot(client, harness, session,
+ provider):
+ """The export run read bytes for three kinds of track and refused for two of them.
+
+ `0821eab` is titled "a sound was the one track nobody checked, and a silent film reported
+ success" and closed the STALE-ID route to that outcome in set_timeline and in the export's
+ planner. The UNREADABLE-BYTES route stayed open: in `_media_export_run` the shot loop and
+ the layer loop raise ExportRefused when the blob comes back empty, and the audio loop
+ `continue`d — so the film was assembled with no sound in it and landed `succeeded`.
+
+ Note what this does NOT duplicate: `test_an_unreadable_sound_is_refused_exactly_like_an_
+ unreadable_shot` is a `media_plane.verify` DURATION check on freshly generated bytes. It
+ never reaches `_media_export_run`, which is the function under test here.
+ """
+ tok = _cred(harness, session)
+ a, _b = _two_ready_clips(client, tok, provider, session)
+ sp = _ok(_call(client, tok, "generate_speech", {"text": "hello"}))
+ eid = _ok(_call(client, tok, "place",
+ {"items": [{"job_id": sp["job_id"]}]}))["placed"][0]["element_id"]
+ _ok(_call(client, tok, "set_timeline", {"shots": [{"element_id": a}],
+ "audio": [{"element_id": eid}]}))
+
+ # FIRST, the film everybody expects: one shot, one sound, both readable. Without this the
+ # refusal below would be satisfied by an export that refuses every timeline with sound in it.
+ good = _ok(_call(client, tok, "export_timeline", {}))
+ assert _await_media_job(good["job_id"])["status"] == "succeeded", "a readable film failed"
+
+ # Now take the sound's BYTES away and leave everything else exactly as it was. The element is
+ # still on the canvas and still ready, so nothing the planner checks has changed.
+ med = str(sp["media_id"])
+ meta = asyncio.run(app._media_meta(session, med)) or {}
+ assert asyncio.run(app._blob_delete(app._media_blob(session, med,
+ str(meta.get("ext") or "mp3")))), meta
+ assert not asyncio.run(app._blob_get(app._media_blob(session, med,
+ str(meta.get("ext") or "mp3")),
+ kb=app.BLOB_KB)), "the sound is still readable"
+
+ out = _ok(_call(client, tok, "export_timeline", {}))
+ job = _await_media_job(out["job_id"])
+ assert job["status"] == "failed", job
+ assert "Sound 1 is no longer readable" in str(job.get("error")), job.get("error")
+ assert not job.get("media_id"), "a silent film was still delivered"
+
+
+def _await_media_job(job_id: str, tries: int = 120) -> dict:
+ """An export runs as a task; `running` is not an answer, so wait for the one it lands on."""
+ for _ in range(tries):
+ job = asyncio.run(app._media_job_get(job_id))
+ if job["status"] != "running":
+ return job
+ time.sleep(0.5)
+ raise AssertionError(f"export {job_id} never settled")
+
+
@needs_ffmpeg
def test_export_letterboxes_and_validates_its_own_duration(client, harness, session, provider):
"""Invariants 22 and 23. One 9:16 shot in position 1 must not distort the film, and an