Skip to content

Commit 1d9924b

Browse files
committed
fix: reset empty response retry counter after successful recovery
The retry counter was per-invocation, not per-failure-burst. If a model returned empty responses at different points during the same invocation, earlier (recovered) empties consumed the budget. A later empty response would exhaust the counter and halt silently. Fix: reset empty_response_count to 0 after any successful (non-empty) response. Also add a warning log when retries are exhausted so the halt is not silent.
1 parent 101ce8c commit 1d9924b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/google/adk/flows/llm_flows/base_llm_flow.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,11 @@ async def run_async(
808808
):
809809
is_empty_response = True
810810

811+
# Reset retry budget after a successful (non-empty) response so that
812+
# later empty responses in the same invocation still get retried.
813+
if not is_empty_response and empty_response_count > 0:
814+
empty_response_count = 0
815+
811816
if (
812817
is_empty_response
813818
and empty_response_count < _MAX_EMPTY_RESPONSE_RETRIES
@@ -841,6 +846,16 @@ async def run_async(
841846
)
842847
continue
843848

849+
if (
850+
is_empty_response
851+
and empty_response_count >= _MAX_EMPTY_RESPONSE_RETRIES
852+
):
853+
logger.warning(
854+
'Model returned an empty response but retry budget (%d) is'
855+
' exhausted. Halting.',
856+
_MAX_EMPTY_RESPONSE_RETRIES,
857+
)
858+
844859
# Normal termination conditions.
845860
if not last_event or last_event.is_final_response() or last_event.partial:
846861
if last_event and last_event.partial:

0 commit comments

Comments
 (0)