fix(agent): count compression restarts toward retry limit (#3070)
When context overflow triggers compression, the outer retry loop restarts via continue without incrementing retry_count. If compression reduces messages but not enough to fit the context window, this creates an infinite loop burning API credits: API call → overflow → compress → retry → overflow → compress → ... Increment retry_count on compression restarts so the loop exits after max_retries total attempts. Cherry-picked from PR #2766 by dieutx.
This commit is contained in:
@@ -6637,6 +6637,11 @@ class AIAgent:
|
|||||||
if restart_with_compressed_messages:
|
if restart_with_compressed_messages:
|
||||||
api_call_count -= 1
|
api_call_count -= 1
|
||||||
self.iteration_budget.refund()
|
self.iteration_budget.refund()
|
||||||
|
# Count compression restarts toward the retry limit to prevent
|
||||||
|
# infinite loops when compression reduces messages but not enough
|
||||||
|
# to fit the context window.
|
||||||
|
retry_count += 1
|
||||||
|
restart_with_compressed_messages = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if restart_with_length_continuation:
|
if restart_with_length_continuation:
|
||||||
|
|||||||
Reference in New Issue
Block a user