fix(session): delete_session also removes legacy path files to prevent history revival
SessionManager._load() migrates sessions from the legacy directory (~/.nanobot/sessions/) to the workspace path, but delete_session only checked the workspace path. A user deleting a session could therefore see its history come back the next time the session was loaded. - delete_session now attempts to unlink both paths - returns True if at least one file was removed - added regression tests: legacy-only, both-paths, and no-revival
This commit is contained in:
+13
-11
@@ -641,20 +641,22 @@ class SessionManager:
|
||||
self._cache.pop(key, None)
|
||||
|
||||
def delete_session(self, key: str) -> bool:
|
||||
"""Remove a session from disk and the in-memory cache.
|
||||
"""Remove a session from disk (both workspace and legacy locations) and cache.
|
||||
|
||||
Returns True if a JSONL file was found and unlinked.
|
||||
Returns True if at least one JSONL file was found and unlinked.
|
||||
"""
|
||||
path = self._get_session_path(key)
|
||||
paths = [self._get_session_path(key), self._get_legacy_session_path(key)]
|
||||
self.invalidate(key)
|
||||
if not path.exists():
|
||||
return False
|
||||
try:
|
||||
path.unlink()
|
||||
return True
|
||||
except OSError as e:
|
||||
logger.warning("Failed to delete session file {}: {}", path, e)
|
||||
return False
|
||||
deleted = False
|
||||
for path in paths:
|
||||
if not path.exists():
|
||||
continue
|
||||
try:
|
||||
path.unlink()
|
||||
deleted = True
|
||||
except OSError as e:
|
||||
logger.warning("Failed to delete session file {}: {}", path, e)
|
||||
return deleted
|
||||
|
||||
def fork_session_before_user_index(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user