fix(session): repair corrupt legacy-stem files in list_sessions

list_sessions() silently dropped corrupt session files whose filename
stem was a legacy non-base64 name (e.g. telegram_12345.jsonl from the
old lossy path scheme). The repair path called _repair(fallback_key),
but _repair re-encodes the key via _storage_key(), producing a
different base64 filename that never matches the actual file on disk.

Add an optional path parameter to _repair so callers can pass the
actual file path directly, bypassing the key-to-filename round trip.

Signed-off-by: axelray-dev <110029405+axelray-dev@users.noreply.github.com>
This commit is contained in:
axelray-dev
2026-06-28 19:46:55 +08:00
committed by Xubin Ren
parent 67ce6822ca
commit 89dc34df88
2 changed files with 43 additions and 3 deletions
+4 -3
View File
@@ -539,9 +539,10 @@ class SessionManager:
logger.info("Recovered session {} from corrupt file ({} messages)", key, len(repaired.messages))
return repaired
def _repair(self, key: str) -> Session | None:
def _repair(self, key: str, *, path: Path | None = None) -> Session | None:
"""Attempt to recover a session from a corrupt JSONL file."""
path = self._get_session_path(key)
if path is None:
path = self._get_session_path(key)
if not path.exists():
return None
@@ -893,7 +894,7 @@ class SessionManager:
}
)
except Exception:
repaired = self._repair(fallback_key)
repaired = self._repair(fallback_key, path=path)
if repaired is not None:
sessions.append(
{