diff --git a/agent/error_classifier.py b/agent/error_classifier.py index 55df8b363e..329607b931 100644 --- a/agent/error_classifier.py +++ b/agent/error_classifier.py @@ -1274,8 +1274,10 @@ _403_TRANSIENT_CODES = frozenset({"upstream_unavailable"}) # wrapper this was verified on (OpenCode stamping "Upstream request failed: # [...]" when the upstream answer was unparseable, #117869): the code alone is # not proof, because ``error.code`` falls back to ``error.type`` and several -# providers reuse the same word for plain permission refusals. -_403_SERVER_ERROR_WRAPPER_MARKERS = ("upstream request failed",) +# providers reuse the same word for plain permission refusals. The bracketed inner +# code must say ``server_error`` too: the relay reuses the same wrapper for a missing +# subscription and for region refusals, which retrying cannot fix. +_403_SERVER_ERROR_WRAPPER_MARKERS = ("upstream request failed: [server_error]",) def _explicit_error_code_field(body: Any) -> str: @@ -1306,6 +1308,11 @@ def _status_403(c: _Ctx) -> Verdict: # 403 and on established block/challenge markers; any other 403 stays auth. if any(p in c.msg for p in _UPSTREAM_BLOCKED_PATTERNS): return _V_UPSTREAM_BLOCKED + # A proxy soft throttle names its reset window in the 403 body ("HTTP 403 (reset after + # 2m)", #42167): the key is fine and the window reopens, so it is the 429 rate limit. + reset = _rate_limit_reset_seconds(c.msg, c.body, c.headers) + if reset: + return _v(_R.rate_limit, **_ROTATE_FALLBACK, error_context={"reset_at": time.time() + reset}) if c.code in _403_TRANSIENT_CODES: return _V_OVERLOADED if _explicit_error_code_field(c.body) == "server_error" and any( diff --git a/agent/retry_utils.py b/agent/retry_utils.py index f51ca2036a..8e6ba3fb70 100644 --- a/agent/retry_utils.py +++ b/agent/retry_utils.py @@ -67,9 +67,10 @@ def parse_retry_after_seconds(value_or_headers: Any) -> Optional[float]: # Free-text "reset" grammars providers put in error bodies, tried in order. One table so the # conversation loop's error context and the credential pool's cooldown agree on the same wait. _QUOTA_RESET_DELAY_RE = re.compile(r"quotaResetDelay[:\s\"]+(\d+(?:\.\d+)?)(ms|s)", re.IGNORECASE) -# "Resets in 4hr 5min" (weekly usage limits), "resets in 2 hours 5 minutes", "resets in 30s". +# "Resets in 4hr 5min" (weekly usage limits), "resets in 2 hours 5 minutes", "resets in 30s"; +# proxies word the same window "(reset after 2m)" (#42167). _RESETS_IN_RE = re.compile( - r"resets?\s+in\s+" + r"resets?\s+(?:in|after)\s+" r"(?:(\d+(?:\.\d+)?)\s*(?:h|hr|hrs|hour|hours)\b\s*)?" r"(?:(\d+(?:\.\d+)?)\s*(?:m|min|mins|minute|minutes)\b\s*)?" r"(?:(\d+(?:\.\d+)?)\s*(?:s|sec|secs|second|seconds)\b)?", re.IGNORECASE,