fix(session): degrade gracefully when SQLite lacks FTS5

This commit is contained in:
LeonSGP43
2026-05-29 20:11:07 -07:00
committed by Teknium
parent 860cf28dab
commit 5ad2b4c6da
2 changed files with 63 additions and 3 deletions
+20 -3
View File
@@ -380,6 +380,7 @@ class SessionDB:
self._lock = threading.Lock()
self._write_count = 0
self._fts_enabled = False
try:
self._conn = sqlite3.connect(
str(self.db_path),
@@ -388,7 +389,6 @@ class SessionDB:
# handles contention instead of sitting in SQLite's internal
# busy handler for up to 30s.
timeout=1.0,
# Autocommit mode: Python's default isolation_level=""
# auto-starts transactions on DML, which conflicts with our
# explicit BEGIN IMMEDIATE. None = we manage transactions
# ourselves.
@@ -724,8 +724,22 @@ class SessionDB:
# FTS5 setup (separate because CREATE VIRTUAL TABLE can't be in executescript with IF NOT EXISTS reliably)
try:
cursor.execute("SELECT * FROM messages_fts LIMIT 0")
except sqlite3.OperationalError:
cursor.executescript(FTS_SQL)
self._fts_enabled = True
except sqlite3.OperationalError as exc:
if "no such table" not in str(exc).lower():
raise
try:
cursor.executescript(FTS_SQL)
self._fts_enabled = True
except sqlite3.OperationalError as fts_exc:
err = str(fts_exc).lower()
if "fts5" not in err and "no such module" not in err:
raise
logger.warning(
"SQLite FTS5 unavailable for %s; full-text search disabled: %s",
self.db_path,
fts_exc,
)
# Trigram FTS5 for CJK/substring search
try:
@@ -2317,6 +2331,9 @@ class SessionDB:
ignores ``sort``. The trigram CJK path honours ``sort`` like the main
FTS5 path.
"""
if not self._fts_enabled:
return []
if not query or not query.strip():
return []