From 4ab9a06a51268a2864cc66ee36ef34bf6f9ef6e8 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sat, 16 May 2026 23:41:45 -0700 Subject: [PATCH] fix(agent): reset _fallback_index at turn start even when no fallback activated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit 33528b428 by konsisumer targeted _restore_primary_runtime in pre-refactor run_agent.py. The body now lives in agent/agent_runtime_helpers.restore_primary_runtime — re-applied there. Fixes #20465 Co-authored-by: konsisumer --- agent/agent_runtime_helpers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py index bac21f14061..b5c70392946 100644 --- a/agent/agent_runtime_helpers.py +++ b/agent/agent_runtime_helpers.py @@ -819,6 +819,14 @@ def restore_primary_runtime(agent) -> bool: ``gateway/run.py``), so this restoration IS needed there too. """ if not agent._fallback_activated: + # Reset the chain index even when no fallback was activated this + # turn. Without this, a turn where _try_activate_fallback() was + # called but returned False (chain exhausted or provider not + # configured) leaves _fallback_index >= len(_fallback_chain) while + # _fallback_activated stays False. The next turn skips this block + # entirely, stranding the index and silently blocking all future + # fallback attempts for the session. Fixes #20465. + agent._fallback_index = 0 return False if getattr(agent, "_rate_limited_until", 0) > time.monotonic():