fix(gateway): clear last-resolved-model cache on /new and compression auto-reset - #58431
Closed
liuhao1024 wants to merge 1 commit into
Closed
Conversation
… auto-reset After a config change (e.g. switching model provider), the /new command must clear the per-session _last_resolved_model cache so the next turn resolves the model from the updated config instead of falling back to the stale cached value. Without this fix, if a transient config-cache miss occurs on the first post-/new turn, the NousResearch#35314 recovery path serves the old model from the cache — the user sees the old model being used even though they changed config.yaml and explicitly ran /new. Fix applies to both call sites that reset session model state: - GatewaySlashCommandsMixin._handle_reset_command (slash_commands.py) - GatewayRunner compression-exhausted auto-reset (run.py) Fixes NousResearch#58403
This was referenced Jul 5, 2026
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.
What does this PR do?
Clears the per-session
_last_resolved_modelcache when/new(or/reset) is issued, and on compression-exhausted auto-reset. This ensures the next turn resolves the model from the currentconfig.yamlinstead of falling back to a stale cached value.Before this fix: After changing
config.yamlmodel (e.g.deepseek-chat→mimo-v2.5-free) and running/new, the_last_resolved_model[session_key]dict still held the old model name. If the first post-/new config read returned empty (transient mtime-cache miss — the #35314 race), the recovery path served the stale cached model instead of surfacing the config-miss error.After this fix:
/newclears both_session_model_overridesAND_last_resolved_model[session_key]. The process-wide"*"fallback is preserved as a safety net for other sessions.Related Issue
Fixes #58403
Type of Change
Changes Made
gateway/slash_commands.py: Added_last_resolved_model.pop(session_key, None)in_handle_reset_commandafter the existing_session_model_overrides.popcall. Usesgetattrguard for bare test runners that skip__init__.gateway/run.py: Added the same_last_resolved_model.popin the compression-exhausted auto-reset path (line ~11398), which performs the same session-model cleanup as/new.tests/gateway/test_new_clears_last_resolved_model.py: 3 regression tests verifying (1) per-session cache cleared on /new, (2) global"*"fallback preserved, (3) stale model not served after config change + empty config read.How to Test
python -m pytest tests/gateway/test_new_clears_last_resolved_model.py tests/gateway/test_empty_model_recovery.py -q— all 12 tests should pass.test_empty_model_recovery.pytests (9 tests) verify the [Bug] model= empty on recovery turn after stream_interrupt_abort — "trying fallback..." logged but never executed, session goes silent #35314 safety net still works: transient empty config reads recover via_last_resolved_modelon normal turns./new, the per-session cache is cleared so a config change takes effect on the next message.Checklist
fix(scope):)pytest tests/gateway/test_new_clears_last_resolved_model.py tests/gateway/test_empty_model_recovery.py -qand all tests passcli-config.yaml.example— N/ACONTRIBUTING.mdorAGENTS.md— N/A