feat(logs): Update pruning heuristic to always remove empty logs regardless of age

This commit is contained in:
2026-03-07 12:32:27 -05:00
parent 3671a28aed
commit b6084aefbb
3 changed files with 106 additions and 7 deletions

View File

@@ -222,6 +222,7 @@ class LogRegistry:
"""
Retrieves a list of sessions that are older than a specific cutoff time
and are not marked as whitelisted.
Also includes non-whitelisted sessions that are empty (message_count=0 or size_kb=0).
Args:
cutoff_datetime (datetime): The threshold time for identifying old sessions.
@@ -241,11 +242,19 @@ class LogRegistry:
else:
start_time = start_time_raw
is_whitelisted = session_data.get('whitelisted', False)
if start_time is not None and start_time < cutoff_datetime and not is_whitelisted:
old_sessions.append({
'session_id': session_id,
'path': session_data.get('path'),
'start_time': start_time_raw
})
# Heuristic: also include non-whitelisted sessions that have 0 messages or 0 KB size
metadata = session_data.get('metadata', {}) or {}
message_count = metadata.get('message_count', -1)
size_kb = metadata.get('size_kb', -1)
is_empty = (message_count == 0 or size_kb == 0)
if start_time is not None and not is_whitelisted:
if start_time < cutoff_datetime or is_empty:
old_sessions.append({
'session_id': session_id,
'path': session_data.get('path'),
'start_time': start_time_raw
})
return old_sessions