The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: recognize structured reasoning-field 400s (param / invalid_reasoning_effort) as reasoning rejections
teknium1e343fbd28b37
diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex 1e7f209d74a..d4e091d1d88 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -477,6 +477,16 @@ _REASONING_FIELD_TOKEN = re.compile(r"|thinkingbudget|reasoning|thinking|think)(?![\w\-/])(?!\s+models?\b)")+# Structured rejection of a reasoning field, read from the stringified body: OpenAI-style+# ``param`` naming a reasoning field (``reasoning_effort`` on chat, ``reasoning.effort`` on+# Responses) or an ``invalid_reasoning_effort`` code. Custom Responses relays send this with NO+# message at all (#100536), so no wording rule can match it — and without a match the message-less+# 400 fell through to the generic large-session overflow heuristic and started compression.+_REASONING_PARAM_REJECTION = re.compile(+ r"""['"]param['"]\s*:\s*['"](?:reasoning(?:[._]effort)?|thinking(?:_config|_budget)?|enable_thinking)['"]"""+ r"""|invalid_reasoning_effort"""+)+def is_reasoning_field_rejection(error_msg: str) -> bool:"""Provider 400 rejecting a reasoning wire control by name (``reasoning_effort``, ``reasoning``,@@ -484,13 +494,17 @@ def is_reasoning_field_rejection(error_msg: str) -> bool:request argument supplied: reasoning_effort", #112781) or a standalone "unsupported" next to thefield in either word order ("unsupported reasoning_effort"; "reasoning_effort 'none' unsupported;use minimal|low|medium|high|xhigh", #114460). The route default is the right answer for such a- model, so both the main loop and the auxiliary ladder retry once without the disable.+ model, so both the main loop and the auxiliary ladder retry once without the disable. A body+ whose structured ``param``/code names the reasoning field (``'param': 'reasoning.effort'``,+ ``invalid_reasoning_effort``, #100536) is a rejection whatever the message says — even none.Known trade-off: a 400 about a thinking *state* ("Function calling is not supported whenthinking is enabled") also matches — the marker sits right next to the token, so no proximityrule separates it from the forward wordings. Cost is one dropped-disable retry before thespent path takes the fallback chain; the auxiliary ladder already treated it this way."""msg = (error_msg or "").lower()+ if _REASONING_PARAM_REJECTION.search(msg):+ return Truetoken = _REASONING_FIELD_TOKEN.search(msg)if token is None:return Falsediff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.pyindex dbc35f63429..1f386b75c8b 100644--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@ -913,6 +913,28 @@ class TestClassifyApiError:)assert gated.reason != FailoverReason.reasoning_mandatory+ def test_structured_invalid_reasoning_effort_400_never_compresses(self):+ """A custom Responses relay rejects an unsupported ``reasoning.effort`` with a message-less+ structured 400 (``param`` + ``error_code: invalid_reasoning_effort``, #100536). No wording rule+ can match it; before, the empty message fell to the large-session overflow heuristic and the+ loop compressed a tiny conversation. Now it is a reasoning-field rejection with+ ``should_compress`` off on every session size; a genuine context-window 400 still compresses."""+ body = {"error": {"param": "reasoning.effort", "error_code": "invalid_reasoning_effort", "retryable": False}}+ for approx_tokens, num_messages in ((77, 3), (90000, 100)):+ result = classify_api_error(+ MockAPIError(f"Error code: 400 - {body}", status_code=400, body=body),+ provider="custom", model="m", approx_tokens=approx_tokens, context_length=200000,+ num_messages=num_messages,+ )+ assert result.reason == FailoverReason.reasoning_mandatory, approx_tokens+ assert result.should_compress is False+ overflow = classify_api_error(+ MockAPIError("This model's maximum context length is 128000 tokens. Please reduce the length "+ "of the messages.", status_code=400),+ provider="custom", model="m", approx_tokens=77, num_messages=3,+ )+ assert overflow.reason == FailoverReason.context_overflow and overflow.should_compress is True+# ── Provider-specific: llama.cpp grammar-parse ──def test_llama_cpp_unable_to_generate_parser_template(self):