fix(copilot): prevent infinite transient retry loop

The transient_retries counter was reset to 0 at the top of the while
loop on every iteration, including after transient retry `continue`
statements.  Since transient retries don't increment `attempt`, the
counter reset every time, creating an infinite retry loop that could
never exhaust the max_transient budget.

Fix: only reset transient_retries when the context-level `attempt`
actually changes, using a _last_reset_attempt sentinel.
This commit is contained in:
Zamil Majdy
2026-04-01 18:21:50 +02:00
parent 3f24a003ad
commit e753aee7a0

View File

@@ -2057,11 +2057,18 @@ async def stream_chat_completion_sdk(
)
attempt = 0
_last_reset_attempt = -1
while attempt < _MAX_STREAM_ATTEMPTS:
# Reset transient retry counter per context-level attempt so
# each attempt (original, compacted, no-transcript) gets the
# full retry budget for transient errors.
transient_retries = 0
# Only reset when the attempt number actually changes —
# transient retries `continue` back to the loop top without
# incrementing `attempt`, so resetting unconditionally would
# create an infinite retry loop.
if attempt != _last_reset_attempt:
transient_retries = 0
_last_reset_attempt = attempt
# Clear any stale stash signal from the previous attempt so
# wait_for_stash() doesn't fire prematurely on a leftover event.
reset_stash_event()