The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): map reversed reasoning-disable rejection to reasoning_mandatory (#114460)
Yagna Vudathu74398c540cb2
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 12e49e80aae..5dd1e3595fd 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -24,7 +24,11 @@ from types import SimpleNamespacefrom typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, TYPE_CHECKING, Unionfrom urllib.parse import urlparse, parse_qs, urlunparse-from agent.error_classifier import _BILLING_PATTERNS, _OVERLOADED_PATTERNS+from agent.error_classifier import (+ _BILLING_PATTERNS,+ _OVERLOADED_PATTERNS,+ is_reasoning_disable_rejected,+)from agent.auxiliary_structured_output import remember_structured_output_rejectionfrom agent.codex_headers import (CODEX_AUX_BASE_URL as _CODEX_AUX_BASE_URL,@@ -3303,24 +3307,10 @@ def _is_reasoning_field_rejection(exc: Exception) -> bool:status = getattr(exc, "status_code", None)if status is not None and status not in {400, 422}:return False- err_lower = str(exc).lower()- if not any(_is_unsupported_parameter_error(exc, name) for name in ("reasoning", "think")):- # Reversed word order some providers use ("reasoning_effort 'none' unsupported"):- # the field token plus standalone "unsupported" nearby is the same rejection (#114460).- token = _REASONING_FIELD_TOKEN.search(err_lower)- if token is None or "unsupported" not in err_lower[token.end():token.end() + 32]:- return False- # The reasoning token must be a standalone wire-field name: not a model-id segment ("The model- # kimi-k2-thinking is not supported when using this account" is route gating that belongs to the- # provider-fallback rung) and not the adjective in "... not supported with reasoning models".- return _REASONING_FIELD_TOKEN.search(str(exc).lower()) is not None---# Reasoning wire-field names (the ``_PROFILE_REASONING_KEYS`` controls minus ``verbosity``), longest first.-_REASONING_FIELD_TOKEN = re.compile(- r"(?<![\w\-/])(?:reasoning_effort|thinking_config|thinking_budget|enable_thinking|thinkingconfig"- r"|thinkingbudget|reasoning|thinking|think)(?![\w\-/])(?!\s+models?\b)"-)+ # Shared wording-class matcher (agent.error_classifier): the strict+ # standalone-token gate inside keeps model-id segments and the "reasoning+ # models" adjective on the provider-fallback rung (#114460).+ return is_reasoning_disable_rejected(str(exc))def _without_reasoning_fields(kwargs: dict) -> Optional[dict]:diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex 1d9d7de3851..501456714ad 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -10,6 +10,7 @@ from __future__ import annotationsimport enumimport jsonimport logging+import reimport timefrom dataclasses import dataclass, fieldfrom typing import Any, Callable, Dict, Iterator, Optional, Sequence@@ -434,6 +435,44 @@ _V_MALFORMED_TOOL_ARGS = _v(_R.format_error, retryable=False, should_fallback=Fa# A reasoning-mandatory route answering ``reasoning: {enabled: false}`` (Nous Portal + OpenRouter wording)._REASONING_MANDATORY_PATTERN = "reasoning is mandatory"+# Reasoning wire-field token shared with the auxiliary retry rung+# (agent/auxiliary_client._is_reasoning_field_rejection, which cannot be imported+# here — it imports from this module). Standalone field name only: never a model-id+# segment ("kimi-k2-thinking") nor the adjective in "... with reasoning models" (#114460).+_REASONING_DISABLE_TOKEN = re.compile(+ r"(?<![\w\-/])(?:reasoning_effort|thinking_config|thinking_budget|enable_thinking|thinkingconfig"+ r"|thinkingbudget|reasoning|thinking|think)(?![\w\-/])(?!\s+models?\b)"+)++# Generic unsupported/unknown markers mirroring the auxiliary rung's parameter check.+_UNSUPPORTED_PARAM_MARKERS = (+ "unsupported parameter", "unsupported_parameter", "not supported", "does not support",+ "doesn't support", "is deprecated for this model",+ "unknown parameter", "unrecognized request argument", "unrecognized parameter",+ "invalid parameter", "extra inputs are not permitted",+)+++def is_reasoning_disable_rejected(error_msg: str) -> bool:+ """True when a provider error rejects a reasoning wire control by name (#114460).++ Covers the forward markers ("Unrecognized request argument supplied:+ reasoning_effort") and the reversed word order some providers use+ ("reasoning_effort 'none' unsupported": field token plus standalone+ "unsupported" within 32 chars). The main loop maps this to+ reasoning_mandatory (drop the disable, retry); the auxiliary ladder maps it+ to its strip-and-retry rung. Same wording class, same remedy.+ """+ msg = (error_msg or "").lower()+ if "reasoning" not in msg and "think" not in msg:+ return False+ if not any(name in msg and any(m in msg for m in _UNSUPPORTED_PARAM_MARKERS)+ for name in ("reasoning", "think")):+ token = _REASONING_DISABLE_TOKEN.search(msg)+ if token is None or "unsupported" not in msg[token.end():token.end() + 32]:+ return False+ return _REASONING_DISABLE_TOKEN.search(msg) is not None+def _billing_hints(error_msg: str) -> Verdict:"""Billing verdict carrying the #82154 ambiguity marker when applicable."""@@ -896,7 +935,7 @@ def _classify_400(c: _Ctx) -> Verdict:# Reasoning-mandatory route rejecting a disable (GLM-5.3 on Nous Portal / OpenRouter). Deterministic# for the request shape, but the only bad field is ``reasoning: {enabled: false}`` — the loop drops# the disable and retries once. Must precede request-validation, which would abort as format_error.- if _REASONING_MANDATORY_PATTERN in msg:+ if _REASONING_MANDATORY_PATTERN in msg or is_reasoning_disable_rejected(msg):return _V_REASONING_MANDATORY# 400 blaming a field this route never sent (Codex OAuth injects then rejects# prompt_cache_retention ~20% of the time): transient, retry identical request.diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.pyindex 907dd1221c5..44c7db30764 100644--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@ -891,6 +891,28 @@ class TestClassifyApiError:assert result.should_fallback is Falseassert result.should_compress is False+ def test_reasoning_effort_none_unsupported_wording_is_reasoning_mandatory(self):+ """Reversed wording rejecting a reasoning disable (#114460): the route mandates+ reasoning, so the loop must drop the disable and retry, not abort as format_error."""+ e = MockAPIError(+ "Error code: 400 - reasoning_effort 'none' unsupported; "+ "use minimal|low|medium|high|xhigh",+ status_code=400,+ )+ result = classify_api_error(e, provider="custom", model="halogen-qwen3.8-flash-next")+ assert result.reason == FailoverReason.reasoning_mandatory+ assert result.retryable is True+ assert result.should_fallback is False++ def test_reasoning_model_route_gating_is_not_reasoning_mandatory(self):+ """Model-id segments (kimi-k2-thinking) stay route gating, never disable rejection."""+ e = MockAPIError(+ "The model kimi-k2-thinking is not supported when using this account",+ status_code=400,+ )+ result = classify_api_error(e, provider="custom", model="kimi-k2-thinking")+ assert result.reason != FailoverReason.reasoning_mandatory+# ── Provider-specific: llama.cpp grammar-parse ──def test_llama_cpp_unable_to_generate_parser_template(self):