fix(session): check reset policy in self-healing recovery path (#54878)

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.
This commit is contained in:
Alec 2026-07-10 04:22:19 +08:00 committed by Teknium
parent 3305dcedbb
commit 4b12b7a359

View file

@ -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: