Skip to content

Fix repeated SQLite FTS startup rebuilds#638

Merged
ascorbic merged 1 commit intoemdash-cms:mainfrom
auggernaut:codex/fts-repair-loop
Apr 18, 2026
Merged

Fix repeated SQLite FTS startup rebuilds#638
ascorbic merged 1 commit intoemdash-cms:mainfrom
auggernaut:codex/fts-repair-loop

Conversation

@auggernaut
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes repeated SQLite FTS startup rebuilds when collections have soft-deleted content.

The runtime startup verifier compared non-deleted content rows to COUNT(*) on the external-content FTS virtual table. On SQLite, that count reflects the backing content table, including soft-deleted rows, so the verifier could decide the index was out of sync on every cold start and rebuild it repeatedly.

This patch switches both startup verification and index stats to count rows from the FTS docsize shadow table, which reflects the rows actually present in the full-text index. It also adds a regression test covering soft delete.

Closes #

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation and pnpm locale:extract has been run (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code

Screenshots / test output

  • pnpm --filter emdash typecheck passes locally.
  • Targeted vitest for packages/core/tests/integration/search/fts-repair.test.ts is currently blocked on this machine by a local better-sqlite3 Node ABI mismatch.
  • Repo-wide lint/typecheck are not fully clean in this workspace because of pre-existing unrelated failures outside this patch.
  • Verified the root cause directly with sqlite3: after a soft delete, COUNT(*) on the external-content FTS virtual table still reflected the backing table total, while the ..._docsize shadow table matched the actual indexed row count.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 17, 2026

🦋 Changeset detected

Latest commit: 2993eb4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions
Copy link
Copy Markdown
Contributor

Scope check

This PR changes 16,382 lines across 100 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@auggernaut
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 17, 2026
Copy link
Copy Markdown
Collaborator

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 17, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@638

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@638

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@638

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@638

emdash

npm i https://pkg.pr.new/emdash@638

create-emdash

npm i https://pkg.pr.new/create-emdash@638

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@638

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@638

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@638

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@638

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@638

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@638

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@638

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@638

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@638

commit: 2993eb4

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect startup FTS “out of sync” detection on SQLite when collections contain soft-deleted rows by changing how indexed-row counts are computed.

Changes:

  • Update FTS verification and index stats to count indexed rows via the FTS *_docsize shadow table (instead of COUNT(*) on the external-content virtual table).
  • Add an integration test covering the soft-delete scenario (and a missing-table repair scenario).
  • Add a changeset describing the patch release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/search/fts-manager.ts Switches indexed-row counting to use the FTS docsize shadow table for verification/stats.
packages/core/tests/integration/search/fts-repair.test.ts Adds integration coverage for FTS repair behavior, including soft-delete regression.
.changeset/ten-flies-admire.md Adds release note for the SQLite FTS rebuild fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .changeset/ten-flies-admire.md Outdated
Comment thread packages/core/tests/integration/search/fts-repair.test.ts
@auggernaut auggernaut force-pushed the codex/fts-repair-loop branch from 490cb56 to 2993eb4 Compare April 17, 2026 20:54
@ascorbic ascorbic merged commit 4ffa141 into emdash-cms:main Apr 18, 2026
41 of 42 checks passed
@emdashbot emdashbot bot mentioned this pull request Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants