From 4b12b7a359b06468b5d2f5e7457d2ab3df59dd71 Mon Sep 17 00:00:00 2001 From: Alec Date: Fri, 10 Jul 2026 04:22:19 +0800 Subject: [PATCH] fix(session): check reset policy in self-healing recovery path (#54878) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the session expiry watcher finalizes a session (daily/idle reset) and the next message triggers the #54878 self-healing path (get_or_create_session detects sessions.json / state.db mismatch), the recovered session was silently reopened without checking whether it should have been reset. This caused sessions to persist indefinitely across reset boundaries. Fix: after dropping the stale sessions.json entry in the self-healing path, call _should_reset() against the old entry's updated_at. If a reset is due, set db_end_session_id to skip DB recovery and create a fresh session — matching the normal reset flow. --- gateway/session.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gateway/session.py b/gateway/session.py index b33b87a9384..884be41e8f2 100644 --- a/gateway/session.py +++ b/gateway/session.py @@ -1954,6 +1954,14 @@ class SessionStore: session_key, entry.session_id, ) self._entries.pop(session_key, None) + # If an expiry watcher (daily/idle reset) already finalized + # this session, honour the reset decision instead of silently + # reopening it via recovery. + if _reset_reason: + was_auto_reset = True + auto_reset_reason = _reset_reason + reset_had_activity = entry.last_prompt_tokens > 0 + db_end_session_id = entry.session_id entry = None _needs_recover = True elif entry.session_id != _stale_session_id: