Skip to content

fix: reset model-switch recovery state and include follow-up cleanup - #25343

Closed
NeroNarada wants to merge 3 commits into
NousResearch:mainfrom
NeroNarada:fix-25325-model-switch-reliability
Closed

NeroNarada wants to merge 3 commits into
NousResearch:mainfrom
NeroNarada:fix-25325-model-switch-reliability

Conversation

@NeroNarada

@NeroNarada NeroNarada commented May 14, 2026

Copy link
Copy Markdown

Summary

  • Reset turn-scoped recovery state in AIAgent.switch_model to prevent stale retry counters/flags and pending request state from leaking into the first turn after a provider/model change.
  • Include follow-up auth and test updates in this PR:
    • hermes_cli/copilot_auth.py
    • hermes_cli/models.py
    • tests/hermes_cli/test_api_key_providers.py
    • tests/hermes_cli/test_copilot_auth.py
    • tests/hermes_cli/test_copilot_catalog_oauth_fallback.py
  • Added PR handoff notes in .plans/2026-05-14-pr-cleanup.md for reviewer context.

Issue

Fixes #25325.

Testing

  • Added regression test: test_switch_model_clears_stale_recovery_state_for_next_turn.
  • No full test suite run in this step.

@NeroNarada
NeroNarada marked this pull request as ready for review May 14, 2026 01:44
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 14, 2026
@NeroNarada NeroNarada changed the title Clear stale recovery state during model-switch transitions Fix model-switch recovery state with stale-state reset and follow-up cleanup May 14, 2026
@NeroNarada NeroNarada changed the title Fix model-switch recovery state with stale-state reset and follow-up cleanup fix: reset model-switch recovery state and include related auth/test cleanup May 14, 2026
@NeroNarada NeroNarada changed the title fix: reset model-switch recovery state and include related auth/test cleanup fix: reset model-switch recovery state and include follow-up cleanup May 14, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Model switching corrupts session/request state with Hindsight enabled, causing retry loop and IndexError

2 participants