The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): use the pinned mirror when the upstream host does not resolve
ethernetadb6d45038d0
diff --git a/pm/downloader.py b/pm/downloader.pyindex 82e2788263c..9074828b99c 100644--- a/pm/downloader.py+++ b/pm/downloader.py@@ -28,6 +28,7 @@ import osimport reimport shutilimport logging+import socketimport sslimport threadingimport time@@ -130,8 +131,11 @@ class DownloadTransportError(DownloadError):def __init__(self, url: str, cause: Exception):self.url = urlself.status = cause.code if isinstance(cause, urllib.error.HTTPError) else None+ # A host that does not resolve is not worth a retry, but the pinned+ # mirror is a different host and the hash still guards the bytes.+ unresolved = isinstance(getattr(cause, "reason", cause), socket.gaierror)self.fallback_allowed = (- self.status in (401, 403, 404, 410) or is_transient(cause)+ self.status in (401, 403, 404, 410) or unresolved or is_transient(cause))reason = f"{cause}; the host refused access" if self.status in (401, 403) else str(cause)super().__init__(f"download failed from {url}: {reason}")diff --git a/tests/pm/test_download_mirrors.py b/tests/pm/test_download_mirrors.pyindex 3509c802775..509b67736b1 100644--- a/tests/pm/test_download_mirrors.py+++ b/tests/pm/test_download_mirrors.py@@ -70,9 +70,11 @@ def test_exhausted_mirrors_name_each_attempted_url(tmp_path, dl_server, monkeypaassert not (tmp_path / "absent").exists()[email protected]("failure", ["503", "tls", "disk", "pause"])[email protected]("failure", ["503", "dns", "tls", "disk", "pause"])def test_only_availability_failures_can_use_a_mirror(tmp_path, dl_server, monkeypatch, failure):+ import socketimport ssl+ import urllib.errorfrom pm import downloader, networkpayload = b"still pinned"@@ -95,12 +97,19 @@ def test_only_availability_failures_can_use_a_mirror(tmp_path, dl_server, monkeyif failure == "pause":dl.pause()if failure == "503":- import urllib.errorraise urllib.error.HTTPError(request.full_url, 503, "Unavailable", {}, None)+ if failure == "dns":+ # The macOS runner's error for an upstream host it cannot resolve.+ raise urllib.error.URLError(socket.gaierror(socket.EAI_NONAME, "nodename nor servname provided"))return original(request, **kwargs)monkeypatch.setattr(downloader._OPENER, "open", open_request)- if failure == "503":+ if failure == "dns":+ dl.run()+ assert (tmp_path / "tool").read_bytes() == payload+ assert requests.count(url(dl_server, "/primary")) == 1+ assert not waits+ elif failure == "503":dl.run()assert (tmp_path / "tool").read_bytes() == payloadassert requests.count(url(dl_server, "/primary")) == network._ATTEMPTS