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:
Teknium
2026-03-25 16:35:17 -07:00
committed by GitHub
parent 9d1e13019e
commit 9792bde31a

View File

@@ -6637,6 +6637,11 @@ class AIAgent:
if restart_with_compressed_messages:
api_call_count -= 1
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
if restart_with_length_continuation: