The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): classify xAI's downloaded-response wording as a corrupt image
Sora-bluesky564113572e60
diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex 7dd31e41c58..b6358161bb8 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -301,11 +301,20 @@ _IMAGE_TOO_LARGE_PATTERNS = [# "base64 string of provided image cannot be decoded" for unaligned# truncation (confirmed by the issue reporter — same root cause, two wire# messages).+# A third xAI wording covers the URL-image path — the provider downloads+# the image itself and rejects the fetched bytes:+# {"code":"invalid-argument","error":"code: 'Client specified an invalid+# argument', message: \"Downloaded response does not contain a valid JPG,+# PNG, WebP, or ICO image.\""}+# Matched as the full observed sentence on purpose — shorter fragments+# ("downloaded response does not contain a valid") also match non-image+# download failures and would misroute them into strip-and-retry.# See: https://github.com/NousResearch/hermes-agent/issues/69078_IMAGE_CORRUPT_PATTERNS = ["invalid png image","invalid jpeg image","base64 string of provided image cannot be decoded",+ "downloaded response does not contain a valid jpg, png, webp, or ico image",]# Providers that follow the OpenAI spec strictly require tool messagediff --git a/tests/run_agent/test_69078_image_corrupt_recovery.py b/tests/run_agent/test_69078_image_corrupt_recovery.pyindex e3726f433ae..ddc29ddb790 100644--- a/tests/run_agent/test_69078_image_corrupt_recovery.py+++ b/tests/run_agent/test_69078_image_corrupt_recovery.py@@ -89,6 +89,50 @@ class TestImageCorruptClassification:assert result.reason == FailoverReason.image_corruptassert result.retryable is True+ def test_xai_downloaded_response_wording_classifies_as_image_corrupt(self):+ """xAI's third wire wording for the same corruption class — fires on+ the URL-image path, where the provider downloads the image itself+ and rejects the fetched bytes. Exercises the 400-status route+ (_classify_400)."""+ err = _FakeApiError(+ status_code=400,+ message='{"code":"invalid-argument","error":"code: \'Client '+ 'specified an invalid argument\', message: \\"Downloaded '+ 'response does not contain a valid JPG, PNG, WebP, or '+ 'ICO image.\\""}',+ )+ result = classify_api_error(err, provider="xai", model="grok-5")+ assert result.reason == FailoverReason.image_corrupt+ assert result.retryable is True++ def test_downloaded_response_wording_message_only_path(self):+ """Same downloaded-response wording with no status_code must still+ classify via the message-pattern route (_classify_by_message)."""+ err = Exception(+ "Downloaded response does not contain a valid JPG, PNG, WebP, "+ "or ICO image."+ )+ result = classify_api_error(err, provider="xai", model="grok-5")+ assert result.reason == FailoverReason.image_corrupt+ assert result.retryable is True++ def test_downloaded_response_non_image_wording_is_not_image_corrupt(self):+ """Negative guard on the downloaded-response pattern: a 400 whose+ message shares the "Downloaded response does not contain a valid"+ head but names a NON-image payload must not be swept into+ image_corrupt — it stays on the existing unrelated-400 route+ (format_error). This is why the pattern is the full reported+ wording rather than a broader fragment of it."""+ err = _FakeApiError(+ status_code=400,+ message="Downloaded response does not contain a valid "+ "certificate chain.",+ )+ result = classify_api_error(err, provider="xai", model="grok-5")+ assert result.reason != FailoverReason.image_corrupt+ assert result.reason == FailoverReason.format_error+ assert result.retryable is False+def test_does_not_route_to_shrink_path(self):"""image_corrupt must be a distinct reason from image_too_large —the retry loop only enters the shrink branch on an exact match, so