length_continue_retries and truncated_response_prefix were initialized once before the outer loop and never reset after a successful continuation. If a conversation hit length truncation once (counter=1), succeeded on continuation, did more tool calls, then hit length again, the counter started at 1 instead of 0 — reducing available retries from 3 to 2. The stale truncated_response_prefix would also leak into the next response. Reset both after the prefix is consumed on a successful final response.
319 KiB
319 KiB