mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-20 15:33:54 +00:00
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.
This commit is contained in:
parent
3990bdf551
commit
9fc8fe2176
1 changed files with 23 additions and 15 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue