fix: clamp aux reasoning effort once before profile projection

Follow-up to the cherry-picked #112019 (@KoNit-K): the clamp in the generic
``extra_body.reasoning`` fallback only covered providers WITHOUT a
reasoning-aware profile. On the profile path (OpenRouter/Nous slots used as
MoA aggregator or aux model) ``_project_provider_profile`` received the raw
config and the OpenRouter profile passes ``ultra`` through whenever the
catalog vocabulary is cold, so the 400 from #112010 survived there.

Move the clamp up to ``_build_call_kwargs`` so both the profile projection
and the fallback see a wire-level effort — the same entry clamp the main
transport applies in ``_reasoning_config_for_model`` (#89503). The shared
policy lives once in ``agent.reasoning_effort.clamp_reasoning_config``; the
transport delegates to it instead of carrying its own copy.

Offline kwargs probe (issue's exact call): before
``extra_body.reasoning == {'enabled': True, 'effort': 'ultra'}`` on nous and
openrouter aux/MoA routes; after ``'effort': 'max'`` on every route,
``high`` verbatim and ``{'enabled': False}`` unchanged.
This commit is contained in:
teknium1
2026-09-15 12:04:40 -07:00
committed by Teknium
parent c02db64077
commit 9e45a90488
4 changed files with 49 additions and 15 deletions
+7 -9
View File
@@ -6157,14 +6157,8 @@ def _merge_aux_extra_body(
if reasoning_config.get("enabled") is False:
merged_extra["reasoning"] = {"enabled": False}
else:
# This fallback uses the OpenAI-compatible chat-completions wire. Hermes'
# internal ``ultra`` tier is not accepted there, including for MoA slots.
from agent.reasoning_effort import OPENAI_COMPAT_WIRE_EFFORTS, clamp_effort
effort = reasoning_config.get("effort") or "medium"
merged_extra["reasoning"] = {
"enabled": True,
"effort": clamp_effort(effort, OPENAI_COMPAT_WIRE_EFFORTS),
}
# ``reasoning_config`` is already clamped to the OpenAI-compat wire by _build_call_kwargs.
merged_extra["reasoning"] = {"enabled": True, "effort": reasoning_config.get("effort") or "medium"}
# Portal tags + sticky session_id fallback when the profile didn't supply them; session_id
# keeps aux calls on the main turn's upstream instance (cache warmth) — tags alone are not
# enough on /v1/messages.
@@ -6209,7 +6203,11 @@ def _build_call_kwargs(
kwargs["tools"] = _dedupe_tool_names(tools, provider, model)
# Provider profiles are the source of truth for reasoning wire shapes (top-level, nested body,
# or extra_body.reasoning); providers without a reasoning-aware profile keep the generic
# ``extra_body.reasoning`` fallback.
# ``extra_body.reasoning`` fallback. Clamp Hermes-internal levels (``ultra``) to the
# OpenAI-compat wire ONCE here, before either path sees the config — the same entry clamp the
# main transport applies (#89503); MoA aggregator/reference and aux calls 400'd without it (#112010).
from agent.reasoning_effort import clamp_reasoning_config
reasoning_config = clamp_reasoning_config(reasoning_config)
projection = _project_provider_profile(provider, provider_norm, model, effective_base, reasoning_config)
kwargs.update(projection.top_level)
if merged_extra := _merge_aux_extra_body(extra_body, projection, reasoning_config, provider_norm):