Skip to content

fix(gateway): clear last-resolved-model cache on /new and compression auto-reset - #58431

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-58403-model-reset-after-new
Closed

fix(gateway): clear last-resolved-model cache on /new and compression auto-reset#58431
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-58403-model-reset-after-new

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Clears the per-session _last_resolved_model cache when /new (or /reset) is issued, and on compression-exhausted auto-reset. This ensures the next turn resolves the model from the current config.yaml instead of falling back to a stale cached value.

Before this fix: After changing config.yaml model (e.g. deepseek-chatmimo-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: /new clears both _session_model_overrides AND _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

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/slash_commands.py: Added _last_resolved_model.pop(session_key, None) in _handle_reset_command after the existing _session_model_overrides.pop call. Uses getattr guard for bare test runners that skip __init__.
  • gateway/run.py: Added the same _last_resolved_model.pop in 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

  1. Run 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.
  2. The existing test_empty_model_recovery.py tests (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_model on normal turns.
  3. The new tests verify that after /new, the per-session cache is cleared so a config change takes effect on the next message.

Checklist

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/gateway/test_new_clears_last_resolved_model.py tests/gateway/test_empty_model_recovery.py -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: macOS
  • I've updated relevant documentation — N/A
  • I've updated cli-config.yaml.example — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A
  • I've considered cross-platform impact — N/A (pure Python logic, no platform-specific behavior)
  • I've updated tool descriptions/schemas — N/A

… 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
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P2 Medium — degraded but workaround exists labels Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/new doesn't reset model config — old session keeps using stale model after config change

2 participants