The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(state): tidy the unique-title repair sort key and user rank
kshitijk4poor54893a83f879
diff --git a/hermes_state_schema.py b/hermes_state_schema.pyindex 29df2289321..b8a66df5fb8 100644--- a/hermes_state_schema.py+++ b/hermes_state_schema.py@@ -1188,9 +1188,9 @@ class SessionSchemaMixin:"(SELECT title FROM sessions WHERE title IS NOT NULL GROUP BY title HAVING COUNT(*) > 1)").fetchall()groups: Dict[str, list] = {}- for row in sorted(rows, key=lambda r: (self._title_rank(r[2]), r[3] or 0, r[0]), reverse=True):+ for row in sorted(rows, key=lambda r: (self._title_rank(r[2]), r[3], r[0]), reverse=True):groups.setdefault(row[1], []).append(row)- user_rank = self._title_rank(self.TITLE_SOURCE_USER)+ user_rank = self._TITLE_SOURCE_RANK[self.TITLE_SOURCE_USER]for title, group in groups.items():# User titles: the OLDEST keeps the base and newer ones get "#k" in# chronological order, so resolve_session_by_title (which prefers thediff --git a/tests/hermes_state/test_hermes_state.py b/tests/hermes_state/test_hermes_state.pyindex 9e6af35d996..78e90e27787 100644--- a/tests/hermes_state/test_hermes_state.py+++ b/tests/hermes_state/test_hermes_state.py@@ -1779,7 +1779,7 @@ class TestSessionTitleIndexRepair:db.close()seed = {"a": ("Trip", "user", 100), "b": ("Trip", "llm", 300), "c": ("Note", "derived", 200),"d": ("Note", "derived", 100), "e": ("Trip", "user", 200)}- with sqlite3.connect(db_path) as conn:+ with contextlib.closing(sqlite3.connect(db_path)) as conn, conn:conn.execute("DROP INDEX idx_sessions_title_unique")conn.executemany("UPDATE sessions SET title = ?, title_source = ?, started_at = ? WHERE id = ?",