From 9fc8fe2176e2258ea525a15a1ac2a861a5c4bfc3 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 16 Jul 2026 06:32:35 -0700 Subject: [PATCH] fix(state): guard the duplicate-title repair so it can never abort DB open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the salvaged #65636: if the dedup UPDATE or the retried CREATE INDEX raises, log and continue — the unique title index is an optimization and must not block SessionDB initialization. --- hermes_state.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/hermes_state.py b/hermes_state.py index 7ea0e620ccd5..1e3945822944 100644 --- a/hermes_state.py +++ b/hermes_state.py @@ -1787,21 +1787,29 @@ class SessionDB: try: cursor.execute(title_index_sql) except sqlite3.IntegrityError: - cursor.execute( - """UPDATE sessions AS older - SET title = NULL - WHERE title IS NOT NULL - AND EXISTS ( - SELECT 1 FROM sessions AS newer - WHERE newer.title = older.title - AND newer.rowid > older.rowid - )""" - ) - logger.warning( - "Cleared %d duplicate session title(s) while restoring the unique index", - cursor.rowcount, - ) - cursor.execute(title_index_sql) + # The index is an optimization — its creation must never abort + # opening the database, so the repair itself is also guarded. + try: + cursor.execute( + """UPDATE sessions AS older + SET title = NULL + WHERE title IS NOT NULL + AND EXISTS ( + SELECT 1 FROM sessions AS newer + WHERE newer.title = older.title + AND newer.rowid > older.rowid + )""" + ) + logger.warning( + "Cleared %d duplicate session title(s) while restoring the unique index", + cursor.rowcount, + ) + cursor.execute(title_index_sql) + except sqlite3.Error: + logger.exception( + "Could not repair duplicate session titles; " + "unique title index not created" + ) except sqlite3.OperationalError: pass # Index already exists