fix: reset model-switch recovery state and include follow-up cleanup - #25343
Closed
NeroNarada wants to merge 3 commits into
Closed
NeroNarada wants to merge 3 commits into
NeroNarada wants to merge 3 commits into
Conversation
NeroNarada
marked this pull request as ready for review
May 14, 2026 01:44
## Why - Explicit model switches can leave turn-scoped retry/recovery state from a previous model in place. - This causes stale empty-response/prefill/tool-loop behavior on the first post-switch turn, sometimes triggering hard retries unexpectedly. ## What changed - Reset stale per-turn model recovery counters/flags in `AIAgent.switch_model` (empty-content, tool failures, JSON/scratchpad prefill retries, tool-call guard state). - Reset `tool_guardrail_halt_decision` and call `_tool_guardrails.reset_for_turn()` when present. - Add regression test ensuring all stale fields clear after `/model` transitions. ## Issue Closes #25325
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AIAgent.switch_modelto prevent stale retry counters/flags and pending request state from leaking into the first turn after a provider/model change.hermes_cli/copilot_auth.pyhermes_cli/models.pytests/hermes_cli/test_api_key_providers.pytests/hermes_cli/test_copilot_auth.pytests/hermes_cli/test_copilot_catalog_oauth_fallback.py.plans/2026-05-14-pr-cleanup.mdfor reviewer context.Issue
Fixes #25325.
Testing
test_switch_model_clears_stale_recovery_state_for_next_turn.