Skip to content

The agent that grows with you

refactor(sessions): pinned back-fill uses the canonical last-active expression

kshitijk4poorbca1928650b8
diff --git a/hermes_state_sessions.py b/hermes_state_sessions.py
index 1e448417166..7e2896b247a 100644
--- a/hermes_state_sessions.py
+++ b/hermes_state_sessions.py
@@ -1290,10 +1290,7 @@ class SessionSessionsMixin:
seen_ids = {s["id"] for s in sessions}
pinned_where = f"{where_sql} AND s.pinned = 1" if where_sql else "WHERE s.pinned = 1"
pinned_query = f"""
- {select_head}COALESCE(
- (SELECT MAX(m2.timestamp) FROM messages m2 WHERE m2.session_id = s.id),
- s.started_at
- ) AS last_active
+ {select_head}{_sql_session_last_active("s")} AS last_active
{from_sessions}
{pinned_where}
ORDER BY s.started_at DESC