The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(error_classifier): read Gemini's error.status when error.code is numeric; pin anthropic RATE_LIMIT_ERROR rotation
teknium1b580e2152e98
diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex ce9e3f82a8a..5cc499267dd 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -1264,12 +1264,16 @@ def _extract_error_body(error: Exception) -> dict:def _code_from_payload(payload: Any, top_keys: Sequence[str], peek_message: bool) -> str:"""Code/type from ``payload.error`` or a top-level key; ``"400"`` is not a code.``peek_message`` also parses a JSON ``error.message`` for a nested code- (Responses API surfaces ``invalid_encrypted_content`` this way)."""+ (Responses API surfaces ``invalid_encrypted_content`` this way). Gemini+ puts the HTTP status in ``error.code`` and the symbolic code+ (``UNAVAILABLE``) in ``error.status``, so a numeric code defers to it."""if not isinstance(payload, dict):return ""error_obj = payload.get("error", {})if isinstance(error_obj, dict):code = error_obj.get("code") or error_obj.get("type") or ""+ if not isinstance(code, str):+ code = error_obj.get("status") or codeif isinstance(code, str) and code.strip() and code.strip() != "400":return code.strip()message = error_obj.get("message")diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.pyindex dc6c4eed9f8..b575667ae2d 100644--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@ -1415,6 +1415,20 @@ class TestProviderCodeOnlyErrors:e = MockAPIError("UNAVAILABLE", body={"error": {"code": "UNAVAILABLE"}})assert classify_api_error(e, provider="openai").reason == FailoverReason.unknown+ def test_gemini_wire_body_numeric_code_falls_back_to_status(self):+ """Gemini's real body carries the HTTP status in ``error.code`` and the+ symbolic code in ``error.status``; the numeric code must not shadow it."""+ body = {"error": {"code": 503, "status": "UNAVAILABLE", "message": "Service unavailable."}}+ e = MockAPIError("Service unavailable.", body=body)+ assert classify_api_error(e, provider="gemini").reason == FailoverReason.overloaded++ def test_anthropic_rate_limit_error_code_rotates_credential(self):+ e = MockAPIError("rate limited", body={"error": {"code": "rate_limit_error"}})+ result = classify_api_error(e, provider="anthropic")+ assert result.reason == FailoverReason.rate_limit+ assert result.should_rotate_credential is True+ assert result.should_fallback is True+class TestRateLimitErrorWithoutStatusCode:"""Regression tests for the Copilot/GitHub Models edge case where the