fix: handle malformed FTS probes during migration#331
Merged
Conversation
Catch failures from the summaries_fts schema probe and force the existing drop/recreate path so corrupt legacy FTS tables can self-heal during migration. Add a regression test that simulates PRAGMA table_info(summaries_fts) throwing while the real SQLite rebuild SQL still runs and repopulates the table from summaries. Regeneration-Prompt: | Fix the migration crash when a legacy or corrupt summaries_fts virtual table causes PRAGMA table_info(summaries_fts) to throw before the self-heal logic runs. Preserve the existing rebuild path instead of inventing a new repair flow: if the probe throws, treat that as a signal to recreate summaries_fts and repopulate it from summaries. Check whether messages_fts has the same table_info probe pattern earlier in the migration and only change it if that exact risk exists. Add a regression test in the migration test suite that simulates the probe failure against a real database so the drop/create and repopulation SQL are exercised. Verify with the focused migration test and the full pnpm test suite.
This was referenced Apr 9, 2026
Merged
jalehman
added a commit
that referenced
this pull request
Apr 9, 2026
Restore the broadened migration tests after rebasing onto main and add a changeset for the startup recovery fixes. Regeneration-Prompt: | Rebase the malformed-FTS recovery branch onto origin/main after PR #331 landed. Preserve the broader standalone FTS hardening from the branch, but fix the review findings before pushing: startup migrations must not reuse a cached fts5Available value from the engine constructor, and stale summaries_fts_cjk tables on runtimes without trigram support must be dropped before any other FTS schema introspection runs. Keep the existing malformed summaries_fts probe regression from #331, update it for the quoted PRAGMA helper, retain the added shadow-table recovery coverage, add a new regression for the stale-trigram ordering issue, and include a patch changeset.
jalehman
added a commit
that referenced
this pull request
Apr 9, 2026
* fix migration recovery for malformed FTS tables * drop stale cjk fts tables without trigram * drop orphaned fts shadow tables on recovery * quote identifiers in fts recovery helpers * fix: finalize FTS recovery hardening after rebase Restore the broadened migration tests after rebasing onto main and add a changeset for the startup recovery fixes. Regeneration-Prompt: | Rebase the malformed-FTS recovery branch onto origin/main after PR #331 landed. Preserve the broader standalone FTS hardening from the branch, but fix the review findings before pushing: startup migrations must not reuse a cached fts5Available value from the engine constructor, and stale summaries_fts_cjk tables on runtimes without trigram support must be dropped before any other FTS schema introspection runs. Keep the existing malformed summaries_fts probe regression from #331, update it for the quoted PRAGMA helper, retain the added shadow-table recovery coverage, add a new regression for the stale-trigram ordering issue, and include a patch changeset. --------- Co-authored-by: Eva <eva@100yen.org> Co-authored-by: Josh Lehman <josh@martian.engineering>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Catch failures from the
summaries_ftsPRAGMA table_info(...)probe during migration and force the existing drop/recreate self-heal path so corrupt legacy FTS tables don't crash plugin startup withmalformed database schema (1).Root cause
Users upgrading from older versions (0.4.x–0.6.x) could have a corrupt or structurally incompatible
summaries_ftsvirtual table. The migration code probed it withPRAGMA table_info(summaries_fts)to detect whether recreation was needed, but this probe itself throws on a malformed FTS table — before the self-healDROP TABLE IF EXISTS+ recreate path ever runs.Fix
Wrap the PRAGMA probe in a try/catch. If it throws, set
summariesFtsColumns = null, which triggersshouldRecreateSummariesFts = trueand lets the existing rebuild path run normally.Testing
test/migration.test.tsthat simulates the probe failurepnpm testpasses (full suite)