The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
chore: merge origin/main (resolve agent/chat_completion_helpers.py,tests/agent/test_error_classifier.py)
teknium18d1b2c5b6ec2
diff --cc agent/chat_completion_helpers.pyindex 338274a3504,f4b8b2fbaef..0ab19ac93bb--- a/agent/chat_completion_helpers.py+++ b/agent/chat_completion_helpers.py@@@ -1269,9 -1246,10 +1252,14 @@@ def _reasoning_config_for_wire(agent)if isinstance(cfg, dict) and (cfg.get("enabled") is False or cfg.get("effort") == "none"):+ if getattr(agent, "_reasoning_floor_required", False):+ from agent.auxiliary_reasoning_floor import REASONING_FLOOR_EFFORT- return {**cfg, "enabled": True, "effort": REASONING_FLOOR_EFFORT}++ floored = {**cfg, "enabled": True, "effort": REASONING_FLOOR_EFFORT}++ agent._wire_reasoning_config = floored++ return floored+ agent._wire_reasoning_config = Nonereturn None+ agent._wire_reasoning_config = cfgreturn cfgif ephemeral_off:cfg = {**(cfg or {}), "enabled": False, "effort": "none"}diff --cc agent/error_classifier.pyindex d4e091d1d88,7b88e2f2de2..f015dc48bb4--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@@ -477,17 -496,27 +499,37 @@@ _REASONING_FIELD_TOKEN = re.compiler"|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"""+)++ _REASONING_REQUIRED_MARKERS = (+ "mandatory", "cannot be disabled", "can't be disabled", "must be enabled", "is required",+ "always enabled", "cannot be turned off",+ )+++ def is_reasoning_required_rejection(error_msg: str) -> bool:+ """Provider 400 saying the model's reasoning cannot be switched OFF ("Reasoning is mandatory for+ this endpoint and cannot be disabled", the Nous Portal on gpt-6-astra). The opposite of+ ``is_reasoning_field_rejection``: the field is understood, the *disable* is refused, so the right+ reaction is to step the effort up to the lowest level rather than drop the field (a dropped field+ also works, but tells the caller nothing about the next call)."""+ msg = (error_msg or "").lower()+ token = _REASONING_FIELD_TOKEN.search(msg)+ if token is None:+ return False+ near = msg[max(0, token.start() - 48):token.end() + 96]+ return any(m in near for m in _REASONING_REQUIRED_MARKERS)++def is_reasoning_field_rejection(error_msg: str) -> bool:"""Provider 400 rejecting a reasoning wire control by name (``reasoning_effort``, ``reasoning``,``thinking``/``think``): the field token plus either a generic unsupported marker ("Unrecognizeddiff --cc agent/turn_recovery.pyindex 4ebd362e59d,7d7c955ca08..daa2154fbc0--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@@ -608,16 -637,13 +637,22 @@@ def recover_after_classificationand not _retry.reasoning_mandatory_retry_attempted):_retry.reasoning_mandatory_retry_attempted = True+ sent = getattr(agent, "_wire_reasoning_config", None)+ if isinstance(sent, dict) and sent.get("enabled") is not False and sent.get("effort") not in (None, "none"):+ # The rejected request carried an ENABLED config: the route refuses that reasoning+ # level (#100536: ``reasoning.effort: max`` on a Responses relay). Dropping a disable+ # would resend the identical request; omit the reasoning fields instead (route default).+ agent._reasoning_effort_rejected = True+ _vlines(agent, f"⚠️ {agent.model} rejects reasoning effort {sent['effort']} — using the route's default for this session, retrying...")+ logger.warning("%sReasoning-effort recovery: dropping reasoning config for %s", agent.log_prefix, agent.model)+ return True, recovered_with_poolagent._reasoning_disable_rejected = True+ # "Reasoning is mandatory ... cannot be disabled" understands the field and refuses only the+ # OFF: step up to the floor effort (the closest the route allows to what the user asked for)+ # rather than the route default. A relay that does not know the field at all keeps the+ # drop (a floor would 400 the same way).+ from agent.error_classifier import is_reasoning_required_rejection+ agent._reasoning_floor_required = is_reasoning_required_rejection(str(api_error))try:from hermes_cli.models_reasoning_caps import refresh_reasoning_caps_asyncrefresh_reasoning_caps_async(agent.provider)diff --cc tests/agent/test_error_classifier.pyindex 1f386b75c8b,2e7ed826700..1180c892c54--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@@ -913,28 -942,19 +946,41 @@@ 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++ def test_openai_unsupported_none_effort_body_is_reasoning_mandatory(self):+ """OpenAI's real 400 for ``reasoning.effort: none`` on a model whose ladder has no ``none`` (o3/o4-mini,+ gpt-5/gpt-5-codex; ``none`` is gpt-5.1+): the SDK message carries the body — ``param: reasoning.effort``+ plus ``code: unsupported_value`` — and must take the drop-the-disable retry rung, not a format abort."""+ body = {"error": {"message": "Unsupported value: 'none' is not supported with this model. Supported values "+ "are: 'low', 'medium', and 'high'.",+ "type": "invalid_request_error", "param": "reasoning.effort", "code": "unsupported_value"}}+ msg = f"Error code: 400 - {body}"+ assert is_reasoning_field_rejection(msg)+ result = classify_api_error(MockAPIError(msg, status_code=400, body=body), provider="openai-api", model="o4-mini")+ assert result.reason == FailoverReason.reasoning_mandatory+ assert result.retryable is True and result.should_fallback is False+# ── Provider-specific: llama.cpp grammar-parse ──def test_llama_cpp_unable_to_generate_parser_template(self):