The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(classifier): route two more rejected-reasoning-replay 400s to the replay strip
teknium1c7cf3f8af1d1
diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex b64feed68d0..be91240975c 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -717,6 +717,11 @@ def _provider_special_cases(c: _Ctx) -> Optional[Verdict]:# ``codex_reasoning_items`` — a genuine block with nothing to strip behaves as before.if _is_codex_masked_replay_rejection(c):return _v(_R.invalid_encrypted_content, **_ABORT_FALLBACK)+ # OpenAI Responses rejects a stale encrypted-reasoning replay with this code (#70595). It contains+ # both "thinking" and "signature", so it must beat the Anthropic heuristic below: that recovery+ # strips Anthropic thinking blocks and resends the same encrypted item forever.+ if status == 400 and (c.code == "thinking_signature_invalid" or "thinking_signature_invalid" in msg):+ return _V_INVALID_ENCRYPTED# Anthropic thinking-block 400s (signature mismatch after transcript# mutation). Not gated on provider — OpenRouter proxies Anthropic errors.if status == 400 and "thinking" in msg and any(p in msg for p in _THINKING_MUTATION_WORDS):@@ -1107,16 +1112,24 @@ def _is_server_injected_param_rejection(error_msg: str, provider: str) -> bool:_CODEX_MASKED_REPLAY_MESSAGE = "request blocked."+_CODEX_UNSUPPORTED_CONTENT_DETAIL = "unsupported content type"def _is_codex_masked_replay_rejection(c: "_Ctx") -> bool:"""HTTP 400 / status-less ``{code: invalid_prompt, message: "Request blocked."}`` from``openai-codex`` — as an SDK error body, a Responses ``error`` SSE frame, or the- ``response.failed`` text ``"invalid_prompt: Request blocked."``."""+ ``response.failed`` text ``"invalid_prompt: Request blocked."`` — or the bare+ ``{"detail": "Unsupported content type"}`` envelope the same backend returns for a rejected+ encrypted-reasoning replay (#51512). Both are exact envelopes, provider-gated."""if c.provider_slug != "openai-codex" or c.status_code not in (None, 400):return False+ body = c.body if isinstance(c.body, dict) else {}+ if str(body.get("detail") or "").strip().lower() == _CODEX_UNSUPPORTED_CONTENT_DETAIL or (+ not body and _CODEX_UNSUPPORTED_CONTENT_DETAIL in c.msg and "detail" in c.msg+ ):+ return True# The OpenAI SDK unwraps ``body["error"]`` on status errors; stream frames keep the envelope.- body_msg = next((str(m).strip().lower() for m in _body_message_candidates(c.body or {}) if m), "")+ body_msg = next((str(m).strip().lower() for m in _body_message_candidates(body) if m), "")return (c.code == "invalid_prompt" and body_msg == _CODEX_MASKED_REPLAY_MESSAGE) or (c.msg.strip() == f"invalid_prompt: {_CODEX_MASKED_REPLAY_MESSAGE}")diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.pyindex 4e403f3d600..8da04278de8 100644--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@ -858,6 +858,26 @@ class TestClassifyApiError:e = MockAPIError("Error code: 400 - " + body["message"], status_code=400, body=body)assert classify_api_error(e, provider=provider, model="gpt-5.5").reason == expected+ @pytest.mark.parametrize(("provider", "expected"), [+ ("openai-codex", FailoverReason.invalid_encrypted_content),+ ("openai", FailoverReason.format_error), # same envelope elsewhere is a genuine request-shape 400+ ], ids=["codex", "other-provider"])+ def test_codex_unsupported_content_type_detail_reaches_replay_strip(self, provider, expected):+ """#51512: the ChatGPT Codex backend rejects a replayed encrypted-reasoning item as a bare+ ``{"detail": "Unsupported content type"}`` 400; only the codex provider maps it to the replay strip."""+ e = MockAPIError("Error code: 400 - {'detail': 'Unsupported content type'}", status_code=400,+ body={"detail": "Unsupported content type"})+ assert classify_api_error(e, provider=provider, model="gpt-5.5").reason == expected++ def test_thinking_signature_invalid_uses_encrypted_replay_recovery(self):+ """#70595: the OpenAI code contains "thinking" + "signature", so it must beat the Anthropic+ thinking-block heuristic and reach the one-shot encrypted-replay strip (retry, no fallback)."""+ body = {"error": {"code": "thinking_signature_invalid", "message": "The reasoning signature is no longer valid."}}+ e = MockAPIError(f"Error code: 400 - {body}", status_code=400, body=body)+ result = classify_api_error(e, provider="openai", model="gpt-5.5")+ assert result.reason == FailoverReason.invalid_encrypted_content+ assert result.retryable is True and result.should_fallback is False+@pytest.mark.parametrize(("provider", "model", "message", "code"), [("azure-foundry", "gpt-6-astra", "Conflicting authenticated continuation identities.", "invalid_value"),# Custom Responses endpoint wraps the replay rejection in a generic bad_request (#95834).