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
fix(media): naming something that is not on the canvas refuses the cut instead of warning
richard-epsilla9ff02d4d9e31
diff --git a/gateway/app.py b/gateway/app.pyindex 8f7a31a1..d2b31deb 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -9743,6 +9743,12 @@ async def _media_tool_call(name: str, args: dict, hid: str, sid: str, org: str,return _tool_text(f"A timeline holds at most {max_shots} shots; this one has "f"{len(shots_in)}.", True)warnings: list[str] = []+ # NAMING SOMETHING THAT IS NOT THERE IS A MISTAKE, NOT A NOTE IN THE MARGIN. Skipping it+ # and reporting a warning wrote a cut that quietly lacked what was asked for: a real run+ # lost its whole music bed that way — the ids had gone stale, every entry was dropped,+ # the film exported without a note of music in it and nothing failed. A warning the+ # caller is free to ignore is not a guard when the result is silence.+ bad: list[str] = []result: dict = {}def mutate(scene: dict):@@ -9752,7 +9758,7 @@ async def _media_tool_call(name: str, args: dict, hid: str, sid: str, org: str,eid = str(s.get("element_id") or "")el = by_id.get(eid)if not el:- warnings.append(f"Shot {i} names {eid}, which is not on the canvas.")+ bad.append(f"Shot {i} names {eid}, which is not on the canvas.")continuem = media_plane.media_of(el)if m.get("status") != "ready":@@ -9777,11 +9783,11 @@ async def _media_tool_call(name: str, args: dict, hid: str, sid: str, org: str,eid = str(a.get("element_id") or "")m = media_plane.media_of(by_id.get(eid) or {})if not m:- warnings.append(f"Sound {i} names {eid}, which is not on the canvas.")+ bad.append(f"Sound {i} names {eid}, which is not on the canvas.")continueif m.get("kind") != "audio":- warnings.append(f"Sound {i} names {eid}, which is a {m.get('kind')} rather "- f"than a sound. Put it in `shots` or `overlays`.")+ bad.append(f"Sound {i} names {eid}, which is a {m.get('kind')} rather than a "+ f"sound. Put it in `shots` or `overlays`.")continueif m.get("status") != "ready":warnings.append(f"Sound {i} ({eid}) is still rendering — export will refuse "@@ -9795,7 +9801,7 @@ async def _media_tool_call(name: str, args: dict, hid: str, sid: str, org: str,eid = str(o.get("element_id") or "")el = by_id.get(eid)if not el:- warnings.append(f"Layer {i} names {eid}, which is not on the canvas.")+ bad.append(f"Layer {i} names {eid}, which is not on the canvas.")continuem = media_plane.media_of(el)a, b, _ = media_plane.shot_window(@@ -9822,6 +9828,31 @@ async def _media_tool_call(name: str, args: dict, hid: str, sid: str, org: str,result["layers"] = len(overlays)return None+ # Checked against the canvas BEFORE anything is written, so a refusal leaves the cut+ # exactly as it was rather than half-replaced.+ probe = await _media_scene_read(sid)+ by_id = {e.get("id"): e for e in probe.get("elements") or []}+ check_bad: list[str] = []+ for i, s_in in enumerate(shots_in, 1):+ if str(s_in.get("element_id") or "") not in by_id:+ check_bad.append(f"Shot {i} names {s_in.get('element_id')}, which is not on the "+ f"canvas.")+ for i, a_in in enumerate(audio_in, 1):+ m = media_plane.media_of(by_id.get(str(a_in.get("element_id") or "")) or {})+ if not m:+ check_bad.append(f"Sound {i} names {a_in.get('element_id')}, which is not on the "+ f"canvas.")+ elif m.get("kind") != "audio":+ check_bad.append(f"Sound {i} names {a_in.get('element_id')}, which is a "+ f"{m.get('kind')} rather than a sound.")+ for i, o_in in enumerate(overlays_in, 1):+ if str(o_in.get("element_id") or "") not in by_id:+ check_bad.append(f"Layer {i} names {o_in.get('element_id')}, which is not on the "+ f"canvas.")+ if check_bad:+ return _tool_text(" ".join(check_bad) + " Nothing was changed — call describe_canvas "+ "for the ids that exist now.", True)+rev, _ = await _media_scene_touch(sid, mutate)out = {"scene_rev": rev,"timeline": {"shots": result.get("n", 0), "layers": result.get("layers", 0),diff --git a/gateway/tests/test_media_mcp.py b/gateway/tests/test_media_mcp.pyindex cd34ba35..14e3142e 100644--- a/gateway/tests/test_media_mcp.py+++ b/gateway/tests/test_media_mcp.py@@ -2168,20 +2168,36 @@ def test_a_sound_that_is_no_longer_on_the_canvas_stops_the_export(client, harnesassert "Sound 1 is no longer on the canvas" in json.dumps(err), err-def test_set_timeline_says_when_a_sound_names_the_wrong_thing(client, harness, session, provider):- """The warning a shot gets, a sound now gets too — including being handed a video."""+def test_set_timeline_refuses_a_cut_that_names_something_that_is_not_there(client, harness,+ session, provider):+ """A warning the caller is free to ignore is not a guard when the result is silence.++ This began as a warning: the bad entry was skipped, the rest was written, and the tool+ reported success. A real run lost its entire music bed that way — the ids had gone stale+ while the clips were placed again, every sound was dropped, and the film exported without a+ note of music in it. Nothing failed, so nothing was fixed. Naming something that is not on+ the canvas is now a refusal that changes nothing at all.+ """tok = _cred(harness, session)a, _b = _two_ready_clips(client, tok, provider, session)- out = _ok(_call(client, tok, "set_timeline", {- "shots": [{"element_id": a}],- "audio": [{"element_id": "el_nope"}, {"element_id": a}]}))- warned = " ".join(out.get("warnings") or [])- assert "not on the canvas" in warned, out- assert "rather than a sound" in warned, out+ _ok(_call(client, tok, "set_timeline", {"shots": [{"element_id": a}]}))++ err = _call(client, tok, "set_timeline", {+ "shots": [{"element_id": a}], "audio": [{"element_id": "el_nope"}]})+ assert err.get("isError"), err+ assert "not on the canvas" in json.dumps(err), err+ # A sound that is really a video is the other half of the same mistake.+ err2 = _call(client, tok, "set_timeline", {+ "shots": [{"element_id": a}], "audio": [{"element_id": a}]})+ assert err2.get("isError") and "rather than a sound" in json.dumps(err2), err2++ # And the cut that was already there is untouched — a refusal does not half-replace it.scene = asyncio.run(app._media_scene_read(session))+ assert [s["elementId"] for s in scene["timeline"]["shots"]] == [a], scene["timeline"]assert scene["timeline"]["audio"] == [], scene["timeline"]+def test_a_layer_that_has_not_landed_refuses_the_export_like_a_shot(client, harness, session,provider):"""Half a film is not a film. A layer still rendering stops the export saying so, rather