From 77d4766602ef68c15de9721ab3b8014e87007a6b Mon Sep 17 00:00:00 2001 From: Teknium Date: Sun, 26 Apr 2026 19:01:00 -0700 Subject: [PATCH] fix(gateway): clear pending model note on auto-reset paths too PR #16013 plugged the leak in `/new`, but two sibling session-boundary resets had the same bug: 1. Inactivity / suspended-session auto-reset (top of `_handle_message`) previously cleared only reasoning. Now drops model override and the queued "/model switched" note as well. 2. Compression-exhaustion auto-reset now also drops the pending note alongside the existing model/reasoning cleanup. All three session-boundary sites now use the identical cleanup idiom. --- gateway/run.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gateway/run.py b/gateway/run.py index 5578338c8f..3305c20ad0 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -4339,7 +4339,14 @@ class GatewayRunner: session_entry = self.session_store.get_or_create_session(source) session_key = session_entry.session_key if getattr(session_entry, "was_auto_reset", False): + # Treat auto-reset as a full conversation boundary — drop every + # session-scoped transient state so the fresh session does not + # inherit the previous conversation's model/reasoning overrides + # or a queued "/model switched" note. + self._session_model_overrides.pop(session_key, None) self._set_session_reasoning_override(session_key, None) + if hasattr(self, "_pending_model_notes"): + self._pending_model_notes.pop(session_key, None) # Emit session:start for new or auto-reset sessions _is_new_session = ( @@ -5019,6 +5026,8 @@ class GatewayRunner: self._evict_cached_agent(session_key) self._session_model_overrides.pop(session_key, None) self._set_session_reasoning_override(session_key, None) + if hasattr(self, "_pending_model_notes"): + self._pending_model_notes.pop(session_key, None) response = (response or "") + ( "\n\nšŸ”„ Session auto-reset — the conversation exceeded the " "maximum context size and could not be compressed further. "