Skip to content

fix(agent): reset fallback provider state in reset_session_state#4382

Open
binhnt92 wants to merge 1 commit intoNousResearch:mainfrom
binhnt92:fix/reset-fallback-state-on-session-reset
Open

fix(agent): reset fallback provider state in reset_session_state#4382
binhnt92 wants to merge 1 commit intoNousResearch:mainfrom
binhnt92:fix/reset-fallback-state-on-session-reset

Conversation

@binhnt92
Copy link
Copy Markdown
Contributor

@binhnt92 binhnt92 commented Apr 1, 2026

reset_session_state() resets all token counters, turn count, and compressor state between gateway conversations — but never resets _fallback_index or _fallback_activated. Once the primary model fails and fallback activates, every subsequent conversation in the same gateway session stays on the fallback model permanently. Users unknowingly talk to a weaker model for all future messages, with no way to return to the primary short of restarting the gateway. Once the fallback chain is fully exhausted, fallback protection is also permanently disabled for that session.

Changes Made

Added self._fallback_index = 0 and self._fallback_activated = False to reset_session_state() in run_agent.py, alongside the existing token/turn/compressor resets.

How to Test

python3 -m pytest tests/test_fallback_reset.py -v

6 tests: fallback index reset to 0, fallback activated reset to False, fallback chain preserved (not cleared), token counters still reset (no regression), source line verification for both fields.

Checklist

  • Tests added (6 tests)
  • Full test suite run — no regressions
  • Tested on Linux (Ubuntu 22.04)
reset_session_state() resets all token counters, turn count, and
compressor state between gateway conversations — but never resets
_fallback_index or _fallback_activated. Once the primary model fails
and fallback activates, every subsequent conversation in the same
gateway session stays on the fallback model permanently. Users
unknowingly talk to a cheaper/weaker model for all future messages
with no way to return to the primary short of restarting the gateway.
Additionally, once the fallback chain is exhausted, fallback protection
is permanently disabled for that session.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant