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():