The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(web): an origin HTTP 429 never walks the keyless extract ring
Teknium85af2bb43869
diff --git a/plugins/web/keyless_mcp.py b/plugins/web/keyless_mcp.pyindex 8ae85a3e7a9..d4a633c8a52 100644--- a/plugins/web/keyless_mcp.py+++ b/plugins/web/keyless_mcp.py@@ -14,7 +14,9 @@ import threadingimport uuidfrom typing import Any, Callable, Dict, List, Optional-from plugins.web._common import document as _page, page_error as _page_error, search_fail, search_ok, vendor_error_entry, web_hit as _row+from plugins.web._common import (+ document as _page, is_origin_http_error, page_error as _page_error, search_fail, search_ok, vendor_error_entry, web_hit as _row,+)logger = logging.getLogger(__name__)@@ -417,10 +419,14 @@ def search_with_failover(name: str, query: str, limit: int = 5) -> dict[str, Anydef extract_with_failover(name: str, urls: list[str]) -> list[dict[str, Any]]:"""Advances to the next ring vendor only when EVERY url in a batch comesback with a rate-limit-shaped error — partial failures and HTTP 403s can- be page problems, not provider throttling, and return as-is."""+ be page problems, not provider throttling, and return as-is. A target's own+ ``HTTP 429 from origin`` is the page's answer, not the vendor's quota."""++ def _throttled(error: str) -> bool:+ return bool(error) and not is_origin_http_error(error) and _is_rate_limitish(error)def _all_throttled(results: list[dict[str, Any]]) -> bool:- return bool(results) and all(r.get("error", "") and _is_rate_limitish(r.get("error", "")) for r in results)+ return bool(results) and all(_throttled(r.get("error", "")) for r in results)order, _vendor, results, _exhausted = _walk_ring(name, "extract", lambda v: _KEYLESS_EXTRACTORS[v](list(urls)), _all_throttled)if not order:diff --git a/tests/plugins/web/test_extract_origin_status.py b/tests/plugins/web/test_extract_origin_status.pyindex c6e4c37ade9..edfb51250e3 100644--- a/tests/plugins/web/test_extract_origin_status.py+++ b/tests/plugins/web/test_extract_origin_status.py@@ -109,3 +109,25 @@ def test_keyless_rescue_runs_for_backend_failures_not_origin_errors(errors, rescassert rescue.called is rescuedif not rescued:assert [r["error"] for r in out] == errors+++def test_origin_429_does_not_walk_the_keyless_extract_ring():+ """The target's own 429 is the page's answer: the ring must not fail over and swap it for+ another vendor's error. A vendor-side 429 still fails over."""+ calls = []++ def _extractor(vendor, error):+ def _run(urls):+ calls.append(vendor)+ return [{"url": u, "title": "", "content": "", "error": error} for u in urls]+ return _run++ ring = {"parallel": "HTTP 429 from origin", "firecrawl": "Firecrawl: other error"}+ with patch.object(keyless_mcp, "_ring_order", return_value=list(ring)), \+ patch.dict(keyless_mcp._KEYLESS_EXTRACTORS, {v: _extractor(v, e) for v, e in ring.items()}):+ [entry] = keyless_mcp.extract_with_failover("parallel", ["https://t.test/x"])+ assert (calls, entry["error"]) == (["parallel"], "HTTP 429 from origin")+ calls.clear()+ keyless_mcp._KEYLESS_EXTRACTORS["parallel"] = _extractor("parallel", "HTTP 429: Too Many Requests")+ [entry] = keyless_mcp.extract_with_failover("parallel", ["https://t.test/x"])+ assert (calls, entry["error"]) == (["parallel", "firecrawl"], "Firecrawl: other error")