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:
yorkhellen
2026-06-19 21:07:47 +08:00
committed by Xubin Ren
parent 6da56f3574
commit 33638417be
2 changed files with 93 additions and 11 deletions
+13 -11
View File
@@ -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,