From d634b37047c8a685353680da031a3cc68706e59e Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:25:48 +0530 Subject: [PATCH] refactor(gateway): retire private repair alias per replay_cleanup precedent Phase 2c on the full final diff flagged the re-export shim as contradicting the adjacent house pattern (agent.replay_cleanup import, which documents retiring private aliases once tests migrate). Migrate all six tests to the canonical gateway.media_repair seam, import the canonical name in run.py, and drop the dead 'and result' guard at the background-task call site. --- gateway/run.py | 11 ++++++----- tests/gateway/test_media_extraction.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index f3fb48bbcc..9b6e0b406a 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -1825,9 +1825,10 @@ _TOOL_MEDIA_RE = re.compile( # Shared with cron delivery and gateway background tasks — the repair must # run on every surface that feeds a final response into media extraction. -# Re-exported under the historical private name for tests and callers. +# Canonical names live in gateway.media_repair (same retirement of private +# aliases as the agent.replay_cleanup import above). from gateway.media_repair import ( # noqa: E402 - repair_explicit_computer_use_media_paths as _repair_explicit_computer_use_media_paths, + repair_explicit_computer_use_media_paths, tool_name_by_call_id as _tool_name_by_call_id, ) @@ -6429,7 +6430,7 @@ class TurnRunner: if isinstance(result, dict): _result_final = result.get("final_response") if isinstance(_result_final, str): - result["final_response"] = _repair_explicit_computer_use_media_paths( + result["final_response"] = repair_explicit_computer_use_media_paths( _result_final, result.get("messages", []), history_offset=len(agent_history), @@ -22789,8 +22790,8 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew # Background tasks start a fresh conversation (no prior history), # so history_offset=0: every message in the run belongs to this # turn. Mirrors the repair on the main turn path. - if response and result: - response = _repair_explicit_computer_use_media_paths( + if response: + response = repair_explicit_computer_use_media_paths( response, result.get("messages", []), ) diff --git a/tests/gateway/test_media_extraction.py b/tests/gateway/test_media_extraction.py index 5150c4a20d..9a1214542f 100644 --- a/tests/gateway/test_media_extraction.py +++ b/tests/gateway/test_media_extraction.py @@ -107,7 +107,9 @@ class TestMediaExtraction: """Tests for MEDIA tag extraction from tool results.""" def test_repairs_explicit_computer_use_media_path_from_json_result(self): - from gateway.run import _repair_explicit_computer_use_media_paths + from gateway.media_repair import ( + repair_explicit_computer_use_media_paths as _repair_explicit_computer_use_media_paths, + ) capture_name = "computer_use_0123456789abcdef0123456789abcdef.png" canonical = rf"C:\Users\Alice\AppData\Local\hermes\cache\images\{capture_name}" @@ -134,7 +136,9 @@ class TestMediaExtraction: assert repaired == f"Here is the screenshot.\nMEDIA:{canonical}" def test_repairs_explicit_path_from_multimodal_text_summary(self): - from gateway.run import _repair_explicit_computer_use_media_paths + from gateway.media_repair import ( + repair_explicit_computer_use_media_paths as _repair_explicit_computer_use_media_paths, + ) capture_name = "computer_use_fedcba9876543210fedcba9876543210.jpg" canonical = rf"D:\Hermes Data\cache\images\{capture_name}" @@ -165,7 +169,9 @@ class TestMediaExtraction: assert repaired == f'MEDIA:"{canonical}"' def test_does_not_auto_attach_computer_use_capture(self): - from gateway.run import _repair_explicit_computer_use_media_paths + from gateway.media_repair import ( + repair_explicit_computer_use_media_paths as _repair_explicit_computer_use_media_paths, + ) capture_name = "computer_use_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png" canonical = rf"C:\Users\Alice\AppData\Local\hermes\cache\images\{capture_name}" @@ -183,7 +189,9 @@ class TestMediaExtraction: ) def test_does_not_rewrite_unmatched_or_previous_turn_capture(self): - from gateway.run import _repair_explicit_computer_use_media_paths + from gateway.media_repair import ( + repair_explicit_computer_use_media_paths as _repair_explicit_computer_use_media_paths, + ) old_name = "computer_use_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.png" current_name = "computer_use_cccccccccccccccccccccccccccccccc.png"