From 000a881fcf61ea631c2fd12747f554847814a395 Mon Sep 17 00:00:00 2001 From: Teknium Date: Sat, 11 Apr 2026 15:26:13 -0700 Subject: [PATCH] fix: reset compression_attempts and primary_recovery_attempted on fallback activation When _try_activate_fallback() switches to a new provider, retry_count was reset to 0 but compression_attempts and primary_recovery_attempted were not. This meant a fallback provider that hit context overflow would only get the leftover compression budget from the failed primary provider, and transport recovery was blocked because the flag was still True from the old provider's attempt. Reset both counters at all 5 fallback activation sites inside the retry loop so each fallback provider gets a fresh compression budget (3 attempts) and its own transport recovery opportunity. --- run_agent.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/run_agent.py b/run_agent.py index b65a8574a..a3f04c6e0 100644 --- a/run_agent.py +++ b/run_agent.py @@ -8185,6 +8185,8 @@ class AIAgent: self._emit_status("⚠️ Empty/malformed response — switching to fallback...") if self._try_activate_fallback(): retry_count = 0 + compression_attempts = 0 + primary_recovery_attempted = False continue # Check for error field in response (some providers include this) @@ -8220,6 +8222,8 @@ class AIAgent: self._emit_status(f"⚠️ Max retries ({max_retries}) for invalid responses — trying fallback...") if self._try_activate_fallback(): retry_count = 0 + compression_attempts = 0 + primary_recovery_attempted = False continue self._emit_status(f"❌ Max retries ({max_retries}) exceeded for invalid responses. Giving up.") logging.error(f"{self.log_prefix}Invalid API response after {max_retries} retries.") @@ -8874,6 +8878,8 @@ class AIAgent: self._emit_status("⚠️ Rate limited — switching to fallback provider...") if self._try_activate_fallback(): retry_count = 0 + compression_attempts = 0 + primary_recovery_attempted = False continue is_payload_too_large = ( @@ -9087,6 +9093,8 @@ class AIAgent: self._emit_status(f"⚠️ Non-retryable error (HTTP {status_code}) — trying fallback...") if self._try_activate_fallback(): retry_count = 0 + compression_attempts = 0 + primary_recovery_attempted = False continue if api_kwargs is not None: self._dump_api_request_debug( @@ -9152,6 +9160,8 @@ class AIAgent: self._emit_status(f"⚠️ Max retries ({max_retries}) exhausted — trying fallback...") if self._try_activate_fallback(): retry_count = 0 + compression_attempts = 0 + primary_recovery_attempted = False continue _final_summary = self._summarize_api_error(api_error) if is_rate_limited: