fix: correct off-by-one in retry exhaustion checks
The retry exhaustion checks used > instead of >= to compare retry_count against max_retries. Since the while loop condition is retry_count < max_retries, the check retry_count > max_retries can never be true inside the loop. When retries are exhausted, the loop exits and falls through to response.choices[0] on an invalid response, crashing with IndexError instead of returning a proper error.
This commit is contained in:
parent
6366177118
commit
c33f8d381b
2 changed files with 48 additions and 2 deletions
|
|
@ -2092,7 +2092,7 @@ class AIAgent:
|
|||
print(f"{self.log_prefix} 📝 Provider message: {error_msg[:200]}")
|
||||
print(f"{self.log_prefix} ⏱️ Response time: {api_duration:.2f}s (fast response often indicates rate limiting)")
|
||||
|
||||
if retry_count > max_retries:
|
||||
if retry_count >= max_retries:
|
||||
print(f"{self.log_prefix}❌ Max retries ({max_retries}) exceeded for invalid responses. Giving up.")
|
||||
logging.error(f"{self.log_prefix}Invalid API response after {max_retries} retries.")
|
||||
self._persist_session(messages, conversation_history)
|
||||
|
|
@ -2323,7 +2323,7 @@ class AIAgent:
|
|||
"partial": True
|
||||
}
|
||||
|
||||
if retry_count > max_retries:
|
||||
if retry_count >= max_retries:
|
||||
print(f"{self.log_prefix}❌ Max retries ({max_retries}) exceeded. Giving up.")
|
||||
logging.error(f"{self.log_prefix}API call failed after {max_retries} retries. Last error: {api_error}")
|
||||
logging.error(f"{self.log_prefix}Request details - Messages: {len(api_messages)}, Approx tokens: {approx_tokens:,}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue