Skip to content

The agent that grows with you

fix(agent): bound sustained summary-overload aborts so they cannot guarantee a session wipe

Yuan Lia5e8ad9f0218
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index 5357187552e..bda2c51052e 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -810,6 +810,15 @@ _TERMINAL_SUMMARY_FAILURES = (
# capped request after its per-turn attempt budget was refilled (#69637).
_TIMEOUT_COOLDOWN_LADDER = (60, 300, 900)
+# Sustained-overload escalation (#123167): ONE overload aborts so a later retry can still win (#115906),
+# but if every summary attempt keeps aborting the transcript only grows until the session exits
+# compression_exhausted and the gateway auto-resets — bounded middle-window loss becomes a total
+# session wipe, just deferred. After this many consecutive overload aborts in one session the overload
+# stops counting as terminal and compress() commits the deterministic fallback instead — the same
+# bounded degrade the repeated-stall ladder takes (#112420). abort_on_summary_failure=true still
+# hard-aborts every attempt. A successful summary resets the count.
+_CONSECUTIVE_OVERLOAD_ABORT_ESCALATION = 3
+
def _next_timeout_cooldown(compressor: Any, counter: str = "_consecutive_timeout_failures") -> int:
"""Bump ``compressor.<counter>`` and return the ladder rung for it.
@@ -2205,6 +2214,9 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngin
# named in the user-visible warning and falls back to the main model (#116472).
self._last_aux_resolved_model = None
self._consecutive_timeout_failures = self._consecutive_truncation_failures = 0
+ # Sustained-overload escalation bookkeeping (#123167): per-session, reset by success.
+ self._consecutive_overload_aborts = 0
+ self._last_summary_overload_degraded = False
# Turns unrecoverably dropped by a static fallback, so callers can warn.
self._last_summary_dropped_count = 0
self._last_summary_fallback_used = self._last_feasibility_skip = False
@@ -2240,6 +2252,7 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngin
self._cooldown_persist_failed = False
self._last_summary_error = None
self._consecutive_timeout_failures = self._consecutive_truncation_failures = self._fallback_compression_streak = 0
+ self._consecutive_overload_aborts = 0
self._ineffective_compression_count = self._prellm_skip_count = 0
self._anti_thrash_recovery_deadline = self._structural_no_op_backoff_until = 0.0
self._reset_proactive_prune_rearm()
@@ -3904,6 +3917,8 @@ Summary generation was unavailable, so this is a best-effort deterministic fallb
self._last_summary_error = None
for flag, _class, _msg in _TERMINAL_SUMMARY_FAILURES:
setattr(self, flag, False)
+ # The provider answered a summary again: the sustained-overload budget restarts (#123167).
+ self._consecutive_overload_aborts = 0
return self._with_summary_prefix(summary)
except Exception as e:
return self._on_summary_failure(e, turns_to_summarize, focus_topic, memory_context)
@@ -4118,7 +4133,15 @@ Write only the summary body. Do not include any preamble or prefix."""
elif kind.empty_content:
self._last_summary_empty_content_failure = True
elif kind.overloaded:
- self._last_summary_overload_failure = True
+ self._consecutive_overload_aborts += 1
+ # Sustained-overload escalation (#123167): keep aborting only while a retry could still
+ # succeed soon (#115906); once every recent attempt has aborted, stop treating the
+ # overload as terminal so compress() commits the deterministic fallback instead of
+ # growing the transcript into a compression_exhausted auto-reset (total session wipe).
+ self._last_summary_overload_failure = (
+ self._consecutive_overload_aborts < _CONSECUTIVE_OVERLOAD_ABORT_ESCALATION
+ )
+ self._last_summary_overload_degraded = not self._last_summary_overload_failure
logger.warning(
"Failed to generate context summary: %s. Further summary attempts paused for %d seconds.", e,
_transient_cooldown,
@@ -4996,6 +5019,7 @@ Write only the summary body. Do not include any preamble or prefix."""
self._last_aux_model_failure_model = None
self._last_compress_aborted = False
self._last_compress_refused_would_grow = False
+ self._last_summary_overload_degraded = False
self._last_compression_made_progress = False
# Do NOT reset the *_failure flags: the cooldown early-return doesn't re-assert them, so a
# reset would fall through to the destructive static fallback (#29559). Success clears them.
@@ -5081,7 +5105,8 @@ Write only the summary body. Do not include any preamble or prefix."""
self, telemetry: Dict[str, Any], n_skipped: int, previous_summary_before_scan: Optional[str],
) -> bool:
"""Abort (messages unchanged) on a terminal failure or when configured to; True when aborted.
- Access/quota, network, truncated and empty-content failures ALWAYS abort (#29559); otherwise
+ Access/quota, network, truncated and empty-content failures ALWAYS abort (#29559); an overload
+ aborts only until the sustained-overload escalation (#123167); otherwise
``abort_on_summary_failure`` decides between abort and the static fallback."""
terminal_failure = next(
((failure_class, message) for flag, failure_class, message in _TERMINAL_SUMMARY_FAILURES if getattr(self, flag)),
@@ -5142,7 +5167,9 @@ Write only the summary body. Do not include any preamble or prefix."""
telemetry["fallback_used"] = True
# Feasibility skip is deliberate, not aux-model breakage — keep the telemetry class distinct.
telemetry["failure_class"] = telemetry.get("failure_class") or (
- "feasibility_skip" if feasibility_skip else "summary_generation_failed"
+ "feasibility_skip" if feasibility_skip
+ else "summary_overload_degraded" if getattr(self, "_last_summary_overload_degraded", False)
+ else "summary_generation_failed"
)
return self._build_static_fallback_summary(
turns_to_summarize,
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py
index 2ab66e32432..f16accb4db2 100644
--- a/agent/conversation_compression.py
+++ b/agent/conversation_compression.py
@@ -174,7 +174,7 @@ _COMPRESSOR_ATTEMPT_STATE_FIELDS = (
"_last_summary_dropped_count",
"_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_summary_overload_failure", "_consecutive_overload_aborts", "_last_summary_overload_degraded",
"_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",
diff --git a/tests/agent/test_context_compressor.py b/tests/agent/test_context_compressor.py
index 4c60d58e81b..e71ff311267 100644
--- a/tests/agent/test_context_compressor.py
+++ b/tests/agent/test_context_compressor.py
@@ -1034,6 +1034,84 @@ class TestAuthFailureAborts:
assert c._last_summary_empty_content_failure is True
+class TestSustainedOverloadEscalation:
+ """#123167: a sustained summary-provider overload must not guarantee a session wipe.
+
+ One overload aborts so a retry can still win (#115906). But when every attempt keeps
+ aborting, the transcript only grows until the session exits compression_exhausted and
+ the gateway auto-resets — total loss, deferred. After 3 consecutive overload aborts the
+ overload stops being terminal and compress() commits the deterministic fallback instead
+ (the same bounded degrade the repeated-stall ladder takes, #112420).
+ """
+
+ def _err(self):
+ return StubProviderError(
+ "Our servers are currently overloaded. Please try again later.",
+ status_code=503,
+ )
+
+ def _compressor(self, **kwargs):
+ with patch("agent.context_compressor.get_model_context_length", return_value=100000):
+ c = ContextCompressor(
+ model="test",
+ quiet_mode=True,
+ protect_first_n=2,
+ protect_last_n=2,
+ **kwargs,
+ )
+ c.summary_model = "test/auxiliary"
+ return c
+
+ def test_first_overloads_still_abort_then_third_commits_fallback(self):
+ c = self._compressor(abort_on_summary_failure=False)
+ msgs = self._msgs(12)
+ with patch("agent.context_compressor.call_llm", side_effect=self._err()):
+ first = c.compress(msgs, current_tokens=999999, force=True)
+ second = c.compress(msgs, current_tokens=999999, force=True)
+ # First two: preserve the transcript unchanged (#115906 semantics).
+ assert first == msgs and second == msgs
+ assert c._last_compress_aborted is True
+ third = c.compress(msgs, current_tokens=999999, force=True)
+
+ # Third: sustained overload escalates — bounded fallback beats a deferred total wipe.
+ assert third != msgs
+ assert c._last_compress_aborted is False
+ assert c._last_summary_fallback_used is True
+ assert c._last_summary_dropped_count > 0
+ assert c._last_compression_telemetry["failure_class"] == "summary_overload_degraded"
+
+ def test_abort_on_summary_failure_true_still_hard_aborts_when_sustained(self):
+ c = self._compressor(abort_on_summary_failure=True)
+ msgs = self._msgs(12)
+ with patch("agent.context_compressor.call_llm", side_effect=self._err()):
+ for _ in range(3):
+ result = c.compress(msgs, current_tokens=999999, force=True)
+
+ assert result == msgs
+ assert c._last_compress_aborted is True
+ assert c._last_summary_fallback_used is False
+
+ def test_successful_summary_resets_the_escalation_budget(self):
+ c = self._compressor(abort_on_summary_failure=False)
+ msgs = self._msgs(12)
+ err_then_ok = [self._err(), self._err(), "ok summary body"]
+ with patch("agent.context_compressor.call_llm", side_effect=err_then_ok):
+ c.compress(msgs, current_tokens=999999, force=True) # 2 calls, aborts
+ c.compress(msgs, current_tokens=999999, force=True) # 1 call, succeeds
+ assert c._consecutive_overload_aborts == 0
+ with patch("agent.context_compressor.call_llm", side_effect=self._err()):
+ fresh_abort = c.compress(msgs, current_tokens=999999, force=True)
+ # Budget was reset by the success, so this overload aborts again (not escalate).
+ assert fresh_abort == msgs
+ assert c._last_compress_aborted is True
+
+ def _msgs(self, n=10):
+ return [
+ {"role": "user" if i % 2 == 0 else "assistant", "content": f"msg {i}"}
+ for i in range(n)
+ ]
+
+
class TestSummaryFallbackToMainModel:
"""When ``summary_model`` differs from the main model and the summary LLM
call fails, the compressor should retry once on the main model before
diff --git a/website/docs/developer-guide/context-compression-and-caching.md b/website/docs/developer-guide/context-compression-and-caching.md
index 0ea61aee121..e1f70109fc5 100644
--- a/website/docs/developer-guide/context-compression-and-caching.md
+++ b/website/docs/developer-guide/context-compression-and-caching.md
@@ -211,7 +211,14 @@ attempt anyway:
deterministic fallback; the warning names the overload
(`failure_class=summary_overload_failure`) and `/compress` retries once
capacity recovers. Auth/quota, network and empty-content failures already
- abort the same way.
+ abort the same way. *Sustained* overload escalates (#123167): after 3
+ consecutive overload aborts in one session the overload stops counting as
+ terminal and compress() commits the deterministic fallback
+ (`failure_class=summary_overload_degraded`) — a bounded middle-window loss
+ instead of letting the transcript grow into `compression_exhausted` and a
+ gateway auto-reset that discards the whole session. A successful summary
+ resets the budget; `abort_on_summary_failure: true` still hard-aborts every
+ attempt.
- **Provider-proven overflow** — when the provider itself rejects the request
with a context-length error, the recovery pass ignores the cooldown for one
bounded attempt (`max_compression_attempts`) without clearing it. Deferring