Merge pull request #13622 from NousResearch/bb/tui-model-switch-sticks

fix(model-switch): /model --provider X sticks instead of silently falling back
This commit is contained in:
brooklyn! 2026-04-21 16:34:19 -05:00 committed by GitHub
commit e6e993552a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 158 additions and 0 deletions

View file

@ -2005,6 +2005,22 @@ class AIAgent:
self._fallback_activated = False
self._fallback_index = 0
# When the user deliberately swaps primary providers (e.g. openrouter
# → anthropic), drop any fallback entries that target the OLD primary
# or the NEW one. The chain was seeded from config at agent init for
# the original provider — without pruning, a failed turn on the new
# primary silently re-activates the provider the user just rejected,
# which is exactly what was reported during TUI v2 blitz testing
# ("switched to anthropic, tui keeps trying openrouter").
old_norm = (old_provider or "").strip().lower()
new_norm = (new_provider or "").strip().lower()
if old_norm and new_norm and old_norm != new_norm:
self._fallback_chain = [
entry for entry in self._fallback_chain
if (entry.get("provider") or "").strip().lower() not in {old_norm, new_norm}
]
self._fallback_model = self._fallback_chain[0] if self._fallback_chain else None
logging.info(
"Model switched in-place: %s (%s) -> %s (%s)",
old_model, old_provider, new_model, new_provider,