Skip to content

The agent that grows with you

fix(gateway): the skipped-MEDIA warning says whether the file is missing or denied (#100074)

kshitijk4poor370ad21deac8
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py
index f001a9a0b49..d7eb6dabeb0 100644
--- a/gateway/platforms/base.py
+++ b/gateway/platforms/base.py
@@ -1140,10 +1140,20 @@ def _validated_delivery_path(raw_path, session_key: str, label: str) -> Optional
from gateway.media_fetch import fetch_remote_media
safe_path = fetch_remote_media(raw)
if not safe_path:
- logger.warning("Skipping unsafe %s: %s", label, _log_safe_path(raw))
+ # Say WHY: a path that does not exist on the host is the common case (a model hallucinated or
+ # a sandbox path failed to translate) and is not a security rejection.
+ reason = "not found on this host" if not _existing_regular_file(raw) else "denied by the delivery policy"
+ logger.warning("Skipping %s (%s): %s", label, reason, _log_safe_path(raw))
return safe_path
+def _existing_regular_file(raw: str) -> bool:
+ try:
+ return Path(os.path.expanduser(raw)).is_file()
+ except (OSError, RuntimeError, ValueError):
+ return False
+
+
SUPPORTED_DOCUMENT_TYPES = {
".pdf": "application/pdf", ".md": "text/markdown", ".txt": "text/plain", ".csv": "text/csv",
".log": "text/plain", ".json": "application/json", ".xml": "application/xml",
diff --git a/tests/gateway/test_platform_base.py b/tests/gateway/test_platform_base.py
index df54476b245..f9d9c8897ef 100644
--- a/tests/gateway/test_platform_base.py
+++ b/tests/gateway/test_platform_base.py
@@ -1250,8 +1250,15 @@ class TestMediaDeliveryDiagnosability:
with caplog.at_level("WARNING"):
out = BasePlatformAdapter.filter_media_delivery_paths([(str(outside), False)])
assert out == []
- # The dropped path must be in the log so operators can diagnose it.
- assert str(outside) in caplog.text
+ # The dropped path must be in the log so operators can diagnose it, with the REASON: a policy
+ # rejection reads differently from a path that simply does not exist (#100074).
+ assert str(outside) in caplog.text and "denied by the delivery policy" in caplog.text
+
+ def test_missing_file_is_logged_as_not_found_not_unsafe(self, tmp_path, caplog):
+ ghost = tmp_path / "never-written.pdf"
+ with caplog.at_level("WARNING"):
+ assert BasePlatformAdapter.filter_media_delivery_paths([(str(ghost), False)]) == []
+ assert "not found on this host" in caplog.text and "unsafe" not in caplog.text
def test_crafted_null_path_does_not_abort_batch(self, tmp_path, monkeypatch):
"""One crafted ~\\x00 path must not drop every other attachment."""