The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): an auto-resolved summary model that fails falls back to the main model and is named in the warning
Chukuwebuka-20037d3c0b2f94a2
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex d63434ec623..ae0edde2c08 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -2103,6 +2103,10 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngin# A handoff may carry role="user" only for alternation, so role alone can't prove a human turn existed.self._previous_summary = self._summary_has_user_turn = self._last_summary_error = Noneself._last_aux_model_failure_error = self._last_aux_model_failure_model = None+ # The model the aux lane actually resolved for the most recent summary call (an ``auto`` route+ # may differ from ``summary_model``/``model``). Recorded so a failed auto-resolved model is+ # named in the user-visible warning and falls back to the main model (#116472).+ self._last_aux_resolved_model = Noneself._consecutive_timeout_failures = self._consecutive_truncation_failures = 0# Turns unrecoverably dropped by a static fallback, so callers can warn.self._last_summary_dropped_count = 0@@ -3470,15 +3474,24 @@ Summary generation was unavailable, so this is a best-effort deterministic fallbprev_end = endreturn "".join(parts)- def _fallback_to_main_for_compression(self, e: Exception, reason: str) -> None:- """Fall back from a separate ``summary_model`` to the main model: record the aux failure, clear model + cooldown."""+ def _fallback_to_main_for_compression(+ self, e: Exception, reason: str, failed_model: Optional[str] = None+ ) -> None:+ """Fall back from a separate ``summary_model`` to the main model: record the aux failure, clear model + cooldown.++ ``failed_model`` names the model that actually failed — an ``auto`` route resolves one per call+ without setting ``summary_model``, so without it the user warning would have no model to name+ (#116472)."""+ failed = str(+ failed_model or self.summary_model or getattr(self, "_last_aux_resolved_model", "") or ""+ ).strip()self._summary_model_fallen_back = Truelogger.warning("Summary model '%s' %s (%s). Falling back to main model '%s' for compression.",- self.summary_model, reason, e, self.model,+ failed or "(auto)", reason, e, self.model,)self._last_aux_model_failure_error = _short_error_text(e)- self._last_aux_model_failure_model = self.summary_model+ self._last_aux_model_failure_model = failed or Nonetelemetry = getattr(self, "_active_compression_telemetry", None)if isinstance(telemetry, dict):telemetry["fallback_used"] = True@@ -3526,6 +3539,9 @@ Summary generation was unavailable, so this is a best-effort deterministic fallbfinally:route_known = bool(_aux_route.get("provider") and _aux_route.get("model"))_aux_model = _aux_route.get("model") or self.summary_model or self.model or ""+ # Remember the resolved model for the failure path: an ``auto`` route picks one per call+ # without setting ``summary_model``, so only this names it in the user warning (#116472).+ self._last_aux_resolved_model = _aux_model or Noneself._record_aux_compression_call(prompt_messages=call_kwargs["messages"],# max_tokens is intentionally absent; .get() keeps the telemetry hook from breaking the call.@@ -3805,8 +3821,14 @@ Write only the summary body. Do not include any preamble or prefix.""")# A distinct summary model gets ONE main-model retry: a specific reason for known transient classes,# else a best-effort "failed" retry — losing N turns is worse than one extra summary attempt.- if self.summary_model and self.summary_model != self.model and not getattr(self, "_summary_model_fallen_back", False):- self._fallback_to_main_for_compression(e, kind.fallback_reason())+ # ``provider: auto`` resolves a model per call WITHOUT setting ``summary_model``; use the model the+ # aux lane actually resolved so an auto route that keeps returning empty content (a proxy channel+ # answering 200 with no body) is abandoned for the main model instead of retried forever (#116472).+ _route_model = str(+ self.summary_model or getattr(self, "_last_aux_resolved_model", "") or ""+ ).strip()+ if _route_model and _route_model != self.model and not getattr(self, "_summary_model_fallen_back", False):+ self._fallback_to_main_for_compression(e, kind.fallback_reason(), failed_model=_route_model)# Retry immediately on the main model.return self._generate_summary(turns_to_summarize, focus_topic=focus_topic, memory_context=memory_context)diff --git a/agent/conversation_compression.py b/agent/conversation_compression.pyindex f424327e5fa..36275e766f9 100644--- a/agent/conversation_compression.py+++ b/agent/conversation_compression.py@@ -175,7 +175,8 @@ _COMPRESSOR_ATTEMPT_STATE_FIELDS = ("_last_summary_fallback_used", "_last_compress_aborted", "_last_summary_auth_failure","_last_summary_network_failure", "_last_summary_empty_content_failure", "_last_summary_truncated_failure","_last_summary_overload_failure",- "_last_aux_model_failure_error", "_last_aux_model_failure_model", "_summary_model_fallen_back", "summary_model",+ "_last_aux_model_failure_error", "_last_aux_model_failure_model", "_last_aux_resolved_model",+ "_summary_model_fallen_back", "summary_model","_last_compression_telemetry", "_active_compression_telemetry", "_compression_telemetry_seed","_proactive_prune_rearm_tokens",)diff --git a/tests/agent/test_compression_auto_summary_fallback.py b/tests/agent/test_compression_auto_summary_fallback.pynew file mode 100644index 00000000000..ff58324b13f--- /dev/null+++ b/tests/agent/test_compression_auto_summary_fallback.py@@ -0,0 +1,58 @@+"""#116472: an ``auto``-resolved compression summary model that fails (e.g. a proxy channel+answering HTTP 200 with empty content) must fall back to the main model. ``auto`` resolves a+model per call without setting ``summary_model``, so the retry gate previously saw "no separate+model" and re-hit the same bad route forever; the resolved model is also recorded so the+user-visible warning names it instead of only appearing in errors.log.+"""++from unittest.mock import MagicMock, patch++from agent.context_compressor import ContextCompressor+++def _msgs():+ return [+ {"role": "user", "content": "do something"},+ {"role": "assistant", "content": "ok"},+ ]+++def test_auto_resolved_summary_model_falls_back_to_main_on_empty_content():+ calls = {"n": 0}++ def _route(**kwargs):+ calls["n"] += 1+ if calls["n"] == 1:+ # First (auto) attempt: a proxy channel answers 200 with empty content.+ kwargs["route_info"].update(provider="openrouter", model="z-ai/glm-5.3")+ return {"choices": [{"message": {"content": " "}}]}+ # Main-model retry succeeds.+ kwargs["route_info"].update(provider="openrouter", model="main-model")+ ok = MagicMock()+ ok.choices = [MagicMock()]+ ok.choices[0].message.content = "summary via main model"+ return ok++ with patch("agent.context_compressor.get_model_context_length", return_value=100000):+ c = ContextCompressor(model="main-model", quiet_mode=True) # no override → provider: auto++ with patch("agent.context_compressor.call_llm", side_effect=_route) as mock_call:+ result = c._generate_summary(_msgs())++ assert mock_call.call_count == 2 # first auto route failed → retried on main+ assert "model" not in mock_call.call_args_list[1].kwargs+ assert result is not None and "summary via main model" in result+ # The model that actually failed (the auto-resolved one) is recorded for the user warning.+ assert c._last_aux_model_failure_model == "z-ai/glm-5.3"+ assert "empty content" in (c._last_aux_model_failure_error or "").lower()+++def test_fallback_records_the_explicit_failed_model():+ with patch("agent.context_compressor.get_model_context_length", return_value=100000):+ c = ContextCompressor(model="main-model", quiet_mode=True)++ c._fallback_to_main_for_compression(Exception("boom"), "failed", failed_model="bad/route")++ assert c.summary_model == "" # empty = use the main model+ assert c._summary_model_fallen_back is True+ assert c._last_aux_model_failure_model == "bad/route"