fix(session): use database session count for has_any_sessions (#351)
The previous implementation used `len(self._entries) > 1` to check if any sessions had ever been created. This failed for single-platform users because when sessions reset (via /reset, auto-reset, or gateway restart), the entry for the same session_key is replaced in _entries, not added. So len(_entries) stays at 1 for users who only use one platform. Fix: Query the SQLite database's session count instead. The database preserves historical session records (marked as ended), so session_count() correctly returns > 1 for returning users even after resets. This prevents the agent from reintroducing itself to returning users after every session reset. Fixes #351
This commit is contained in:
parent
152e0800e6
commit
87a16ad2e5
2 changed files with 59 additions and 1 deletions
|
|
@ -391,8 +391,16 @@ class SessionStore:
|
|||
|
||||
def has_any_sessions(self) -> bool:
|
||||
"""Check if any sessions have ever been created (across all platforms)."""
|
||||
if self._db:
|
||||
# Database tracks all sessions ever created (including ended ones).
|
||||
# This correctly handles session resets where the in-memory _entries
|
||||
# dict replaces the entry for the same session_key, but the DB
|
||||
# preserves the historical record.
|
||||
# > 1 because the current session is already created.
|
||||
return self._db.session_count() > 1
|
||||
# Fallback for when DB is not available (e.g., tests)
|
||||
self._ensure_loaded()
|
||||
return len(self._entries) > 1 # >1 because the current new session is already in _entries
|
||||
return len(self._entries) > 1
|
||||
|
||||
def get_or_create_session(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue