3 months ago
5524dcbIndexing drops FTS triggers to avoid double-writes, then restores them after chunk inserts. If indexing is interrupted (crash, kill), triggers are never restored — chunks exist in the chunks table but are absent from chunks_fts. On restart, the schema init saw the FTS table already existed and skipped backfill entirely, leaving those chunks permanently unsearchable. Fix: when chunks_fts already exists, run a LEFT JOIN backfill to insert any chunks missing from FTS, and delete orphaned FTS rows whose chunks were deleted. This runs before restoreFtsTriggerDefinitions so triggers don't double-insert during backfill. Typecheck 8/8, tests 144 pass. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Parent0cda296