fix(state): guard gateway FTS rebuild + comment early flag-set

Add the foreign-holder guard to gateway/session.py::_rebuild_fts_once(),
the third FTS rebuild path that was not covered by the original fix.
Also add a comment explaining why _fts_runtime_rebuild_attempted is set
before the foreign-holder check: the fail-open path that follows
persists FTS_STALE_KEY so the next startup retries via _recover_stale_fts.
This commit is contained in:
kshitijk4poor
2026-08-22 03:15:16 +05:30
committed by kshitij
parent fc72d6c716
commit c45e2b19c3
2 changed files with 19 additions and 0 deletions
+13
View File
@@ -3875,6 +3875,19 @@ class SessionStore:
db = self._db
if db is None or not hasattr(db, "rebuild_fts"):
return False
# Guard against the same WAL split-brain risk as the automatic
# rebuild paths: skip when a foreign process holds state.db or
# its WAL sidecars open.
if hasattr(db, "_foreign_state_db_holders"):
foreign_holders = db._foreign_state_db_holders()
if foreign_holders:
logger.warning(
"Skipping Session DB FTS rebuild while foreign processes "
"hold the database or WAL sidecars (%s); canonical "
"transcript writes remain available.",
foreign_holders,
)
return False
try:
rebuilt = db.rebuild_fts()
except Exception as exc: