From bcce700783814c0fc75459735f85082b47204004 Mon Sep 17 00:00:00 2001 From: srojk34 <286497132+srojk34@users.noreply.github.com> Date: Fri, 17 Jul 2026 07:59:08 -0700 Subject: [PATCH] fix(compression): reset failure cooldown on runtime switch --- agent/context_compressor.py | 4 +++- tests/agent/test_context_compressor.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index e023aecba9bd1..0194c829886db 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -1175,6 +1175,9 @@ class ContextCompressor(ContextEngine): if runtime_changed: self._fallback_compression_streak = 0 self._persist_fallback_compression_streak() + # Failure cooldowns are scoped to the model/provider that failed. + # A switch must give the new runtime an immediate summary attempt. + self._clear_compression_failure_cooldown() self._verify_compaction_cleared_threshold = False self._last_compression_made_progress = False @@ -1260,7 +1263,6 @@ class ContextCompressor(ContextEngine): return max(1, min(int(effective_window * ContextCompressor._MIN_CTX_TRIGGER_RATIO), effective_window - 1)) return floored - def __init__( self, model: str, diff --git a/tests/agent/test_context_compressor.py b/tests/agent/test_context_compressor.py index 08ef6da986ebd..d44f0e97edc65 100644 --- a/tests/agent/test_context_compressor.py +++ b/tests/agent/test_context_compressor.py @@ -3039,6 +3039,31 @@ class TestUpdateModelResetsCalibration: assert comp.should_defer_preflight_to_real_usage(comp.threshold_tokens + 5_000) is False + def test_summary_failure_cooldown_cleared(self): + """Stale summary-failure cooldown from the old model must not block + the new model from generating summaries after a switch.""" + import time + comp = self._comp() + # Simulate a 600-second cooldown set because the old model had no + # provider configured for summarization. + comp._summary_failure_cooldown_until = time.monotonic() + 600 + + comp.update_model("new-model", context_length=128_000) + + assert comp._summary_failure_cooldown_until == 0.0 + + def test_summary_failure_cooldown_survives_same_runtime_refresh(self): + """Refreshing metadata for the same runtime must not defeat backoff.""" + import time + comp = self._comp() + cooldown_until = time.monotonic() + 600 + comp._summary_failure_cooldown_until = cooldown_until + + comp.update_model("big-model", context_length=128_000) + + assert comp._summary_failure_cooldown_until == cooldown_until + + class TestTruncateToolCallArgsJson: """Regression tests for #11762.