fix(state): guard the duplicate-title repair so it can never abort DB open

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.
fix/verification-admin-route-recovery
Teknium 2026-07-16 06:32:35 -07:00
parent 3990bdf551
commit 9fc8fe2176
1 changed files with 23 additions and 15 deletions

View File

@ -1787,21 +1787,29 @@ class SessionDB:
try: try:
cursor.execute(title_index_sql) cursor.execute(title_index_sql)
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
cursor.execute( # The index is an optimization — its creation must never abort
"""UPDATE sessions AS older # opening the database, so the repair itself is also guarded.
SET title = NULL try:
WHERE title IS NOT NULL cursor.execute(
AND EXISTS ( """UPDATE sessions AS older
SELECT 1 FROM sessions AS newer SET title = NULL
WHERE newer.title = older.title WHERE title IS NOT NULL
AND newer.rowid > older.rowid AND EXISTS (
)""" SELECT 1 FROM sessions AS newer
) WHERE newer.title = older.title
logger.warning( AND newer.rowid > older.rowid
"Cleared %d duplicate session title(s) while restoring the unique index", )"""
cursor.rowcount, )
) logger.warning(
cursor.execute(title_index_sql) "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: except sqlite3.OperationalError:
pass # Index already exists pass # Index already exists