The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: name a CDN firewall block instead of a bare HTTP 403 (#128295)
Teknium5ac6af436dcb
diff --git a/hermes_cli/debug.py b/hermes_cli/debug.pyindex a10952d22b3..ae868062c76 100644--- a/hermes_cli/debug.py+++ b/hermes_cli/debug.py@@ -591,9 +591,11 @@ def _run_debug_share_nous(args, *, log_lines: int, redact: bool) -> None:try:res = share_to_nous(build_nous_bundle(bundle, redact=redact))except Exception as exc:+ from pm.network import edge_block+error = redact_debug_support_text(exc)- print(f"\nNous upload failed: {error}\n"- "\nThe Nous diagnostics service may be unavailable or not yet provisioned.\n"+ cause = edge_block(exc) or "The Nous diagnostics service may be unavailable or not yet provisioned"+ print(f"\nNous upload failed: {error}\n\n{cause}.\n""Run `hermes debug share --local` to print the report instead, ""or `hermes debug share` to upload to a public paste service.\n", file=sys.stderr)sys.exit(1)diff --git a/hermes_cli/release_channels.py b/hermes_cli/release_channels.pyindex 0e556cbcdb5..7f8315a6bec 100644--- a/hermes_cli/release_channels.py+++ b/hermes_cli/release_channels.py@@ -287,7 +287,7 @@ class ChannelReader:# Channel reads are idempotent and precede the PM download path, so an explicit update# uses the same bounded transient-failure policy instead of a second retry classifier.- from pm.network import retry_network+ from pm.network import edge_block, retry_networkdef read() -> bytes:with self.opener(Request(url, headers={"Cache-Control": "no-cache"}), timeout=30) as response:@@ -300,7 +300,8 @@ class ChannelReader:except HTTPError as exc:if exc.code == 404:raise ChannelNotFound(f"Channel object not found: {key}") from exc- raise ChannelError(f"Channel read unavailable: HTTP {exc.code}") from exc+ block = edge_block(exc)+ raise ChannelError(f"Channel read unavailable: HTTP {exc.code}" + (f"; {block}" if block else "")) from excexcept (OSError, URLError) as exc:raise ChannelError("Channel read unavailable") from excif len(body) > MAX_METADATA:diff --git a/pm/downloader.py b/pm/downloader.pyindex fc1f63f6024..24e33613f5b 100644--- a/pm/downloader.py+++ b/pm/downloader.py@@ -39,7 +39,7 @@ from dataclasses import dataclassfrom pathlib import Pathfrom typing import Callable, Optional, Sequence-from pm.network import is_transient, retry_network+from pm.network import edge_block, is_transient, retry_network# GitHub's release-asset CDN (release-assets.githubusercontent.com, which# TUR's pool 302s to) 403s unknown tool UAs from CI runner IP ranges --@@ -137,7 +137,8 @@ class DownloadTransportError(DownloadError):self.fallback_allowed = (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)+ refused = edge_block(cause) or "the host refused access"+ reason = f"{cause}; {refused}" if self.status in (401, 403) else str(cause)super().__init__(f"download failed from {url}: {reason}")diff --git a/pm/network.py b/pm/network.pyindex eca4961d916..3baab827036 100644--- a/pm/network.py+++ b/pm/network.py@@ -9,6 +9,7 @@ import socketimport sslimport timeimport urllib.error+import urllib.parsefrom datetime import timezone, UTCfrom email.utils import parsedate_to_datetimefrom typing import Callable, TypeVar@@ -40,6 +41,29 @@ def is_transient(exc: Exception) -> bool:return isinstance(exc, OSError) and exc.errno in _NETWORK_ERRNOS+def edge_block(exc: BaseException) -> str | None:+ """Explain a 403/429 that a CDN firewall sent instead of the server, else None.++ A bare "HTTP 403" from a regional block reads as a broken install or a missing+ file (#128295). Cloudflare marks challenges with ``cf-mitigated``, and on an R2+ custom domain a response without ``cf-cache-status`` never reached the bucket+ (Cloudflare R2 troubleshooting docs); Vercel's firewall sets ``x-vercel-mitigated``.+ """+ if not isinstance(exc, urllib.error.HTTPError) or exc.code not in (403, 429):+ return None+ headers = exc.headers or {}+ if headers.get("x-vercel-mitigated"):+ cdn = "Vercel"+ elif headers.get("cf-mitigated") or (+ (headers.get("server") or "").lower() == "cloudflare" and not headers.get("cf-cache-status")):+ cdn = "Cloudflare"+ else:+ return None+ host = urllib.parse.urlsplit(exc.filename or "").hostname or "the server"+ return (f"{host}'s CDN firewall ({cdn}) refused this network. Your install is fine; "+ "retry from another network, or with your VPN or proxy turned off")++def _delay(exc: Exception, attempt: int) -> float:delay = float(2 ** attempt)if isinstance(exc, urllib.error.HTTPError):diff --git a/tests/hermes_cli/test_release_channels.py b/tests/hermes_cli/test_release_channels.pyindex b1b5f68b9e4..a25b63e5432 100644--- a/tests/hermes_cli/test_release_channels.py+++ b/tests/hermes_cli/test_release_channels.py@@ -141,6 +141,29 @@ def test_passive_reads_and_missing_objects_make_one_attempt(monkeypatch):assert waits == [][email protected](("headers", "blocked"), [+ ({"Server": "cloudflare", "Content-Type": "text/html"}, True),+ ({"Server": "cloudflare", "cf-cache-status": "DYNAMIC"}, False),+])+def test_cdn_firewall_403_names_the_network_not_the_install(headers, blocked):+ """#128295: a Cloudflare block that never reached the bucket must not read as a bare HTTP 403."""+ from email.message import Message+ from urllib.error import HTTPError+ from hermes_cli.release_channels import ChannelError, ChannelReader++ hdrs = Message()+ for key, value in headers.items():+ hdrs[key] = value++ def opener(request, timeout):+ raise HTTPError(request.full_url, 403, "Forbidden", hdrs, None)++ with pytest.raises(ChannelError) as raised:+ ChannelReader("https://hermes-assets.example", opener=opener).read_bytes("releases/channels/pm-preview.json")+ assert ("hermes-assets.example's CDN firewall (Cloudflare) refused this network" in str(raised.value)) is blocked+ assert str(raised.value).startswith("Channel read unavailable: HTTP 403")++def test_reader_rejects_cycles_identity_substitution_and_cross_authority():from hermes_cli.release_channels import ChannelReader, ChannelError, canonical_jsonwith object_server() as (url, objects, _headers, _requests, _faults):diff --git a/tests/pm/test_network.py b/tests/pm/test_network.pyindex 1ba2c84dbad..dd4a1aa092c 100644--- a/tests/pm/test_network.py+++ b/tests/pm/test_network.py@@ -91,3 +91,22 @@ def test_retry_after_is_bounded_and_interruptible(monkeypatch, retry_after, mininetwork.retry_network(fail, wait=cancel)assert len(attempts) == len(waits) == 1assert minimum <= waits[0] <= network._MAX_DELAY++[email protected]("status,headers,cdn", [+ pytest.param(403, {"Server": "Vercel", "x-vercel-mitigated": "deny"}, "Vercel", id="vercel-deny"),+ pytest.param(403, {"Server": "cloudflare", "cf-mitigated": "challenge", "cf-cache-status": "DYNAMIC"},+ "Cloudflare", id="cloudflare-challenge"),+ pytest.param(404, {"Server": "cloudflare"}, None, id="missing-object"),+ pytest.param(403, {"Server": "AmazonS3"}, None, id="origin-403"),+])+def test_edge_block_only_names_a_cdn_firewall_refusal(status, headers, cdn):+ hdrs = Message()+ for key, value in headers.items():+ hdrs[key] = value+ error = urllib.error.HTTPError("https://portal.example/api/x", status, "failed", hdrs, None)+ message = network.edge_block(error)+ if cdn is None:+ assert message is None+ else:+ assert (message or "").startswith(f"portal.example's CDN firewall ({cdn})"), message