The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(gateway): warn when a Docker sandbox MEDIA path fails translation
Michael Nguyena15533b64635
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.pyindex b5bedd1a9fa..00304f30c73 100644--- a/gateway/platforms/base.py+++ b/gateway/platforms/base.py@@ -1641,6 +1641,26 @@ def _cache_dir_container_mounts() -> List[Tuple[Path, Path]]:return []+def _warn_unresolved_docker_media(candidate: Path, session_key: str, reason: str) -> None:+ """Name WHY a container-absolute MEDIA path failed translation (#93950).++ Under Docker these failures used to surface only as the generic+ "Skipping unsafe MEDIA directive path" line one level up, leaving the+ file seemingly vanished. Point at the sandbox/session mismatch instead.+ Gated to Docker mode so host-path rejections stay quiet.+ """+ if os.getenv("TERMINAL_ENV", "").strip().lower() != "docker":+ return+ logger.warning(+ "Docker MEDIA path %s did not resolve to a host sandbox file (%s%s); "+ "the producing container's sandbox directory may not exist yet or "+ "was pruned",+ _log_safe_path(str(candidate)),+ reason,+ f", session_key={session_key}" if session_key else "",+ )++def _translate_docker_container_media_path(candidate: Path, session_key: str = "") -> Optional[Path]:"""Translate a container-absolute path to its host path when possible.@@ -1684,8 +1704,8 @@ def _translate_docker_container_media_path(candidate: Path, session_key: str = "mounts.append((default_home, Path("/root")))if not mounts:+ _warn_unresolved_docker_media(candidate, session_key, "no sandbox mounts resolved")return None-# Longest container-prefix match.best: Optional[Tuple[Path, Path, int]] = Nonecandidate_posix = candidate.as_posix()@@ -1696,13 +1716,14 @@ def _translate_docker_container_media_path(candidate: Path, session_key: str = "if best is None or score > best[2]:best = (host_root, container_root, score)if best is None:+ _warn_unresolved_docker_media(candidate, session_key, "no mounted prefix matches")return None-host_root, container_root, _ = besttry:relative = candidate.relative_to(container_root)translated = (host_root / relative).resolve(strict=True)except (OSError, RuntimeError, ValueError):+ _warn_unresolved_docker_media(candidate, session_key, "host file missing from sandbox")return Noneif translated != host_root and not _path_is_within(translated, host_root):return Nonediff --git a/tests/gateway/test_platform_base.py b/tests/gateway/test_platform_base.pyindex 1a484691c3b..8d8fe8e0ff2 100644--- a/tests/gateway/test_platform_base.py+++ b/tests/gateway/test_platform_base.py@@ -1360,3 +1360,22 @@ class TestDockerSessionSandboxMediaTranslation:)assert kept == [(str(produced.resolve()), False)]++ def test_unresolved_docker_media_names_the_cause(self, monkeypatch, caplog):+ """Approach C: a container path whose sandbox never existed must log+ WHY it was dropped (sandbox mismatch), not just the generic unsafe-+ path line — the silent-drop mode reported in #93950."""+ import logging++ self._enable_docker(monkeypatch)+ with caplog.at_level(logging.WARNING, logger="gateway.platforms.base"):+ resolved = BasePlatformAdapter.validate_media_delivery_path(+ "/workspace/ghost.png", session_key=self.SESSION_KEY+ )++ assert resolved is None+ assert any(+ "did not resolve to a host sandbox file" in r.message+ and f"session_key={self.SESSION_KEY}" in r.message+ for r in caplog.records+ )