Repository navigation
fix(storage): prevent FTS orphans during replacement - #1435
Conversation
Problem: production FTS drift contained orphan docsize rows with no matching messages rows. The replacement path can delete messages while FTS delete triggers are suspended during bulk ingest, leaving external-content FTS rowids behind. Subsequent per-conversation repair only sees current message rowids and cannot delete already-orphaned rows. What changed: conversation replacement now explicitly issues FTS5 delete commands for message and action-event rows before deleting base rows when the delete triggers are absent. Startup readiness still enforces real FTS parity, but uses conversation_stats rather than a full messages scan before rebuilding. Verification: focused FTS replacement and daemon startup pytest nodes passed; focused mypy passed; ruff format/check passed.
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 42 minutes and 2 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59cd56f93b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Makes FTS correctness real across daemon catch-up/replacement. Conversation replacement now explicitly removes message/action FTS rows before deleting base rows when FTS delete triggers are missing, and daemon startup restores full FTS parity using cheap stats-table counts before the watcher proceeds.
Problem
Production drift showed
messages_fts_docsizeovercounting the basemessagestable by about 108k rows with rowids that no longer exist inmessages. That shape is consistent with deleting/replacing conversation rows while FTS delete triggers are suspended or missing: the base rows disappear, but external-content FTS shadow rows remain. Per-conversation repair then cannot remove those rowids because it only sees currentmessagesrows.FTS must be transparently ready and correct; stale search is not an acceptable steady state.
Solution
deletecommand while the old base rows still exist, so no orphan shadow rows are left behind whenmessages/action_eventsare deleted.messages_fts_docsizetoconversation_statsinstead of scanning the fullmessagestable.Verification
pytest tests/unit/daemon/test_daemon_cli.py::test_ensure_fts_startup_readiness_uses_bounded_probes tests/unit/daemon/test_daemon_cli.py::test_ensure_fts_startup_readiness_rebuilds_empty_fts tests/unit/daemon/test_daemon_cli.py::test_ensure_fts_startup_readiness_rebuilds_stats_count_mismatch tests/unit/daemon/test_daemon_cli.py::test_ensure_fts_startup_readiness_rebuilds_when_triggers_missing tests/unit/storage/test_fts_bloat_invariants.py::test_conversation_replacement_purges_fts_when_delete_triggers_missing tests/unit/storage/test_fts_bloat_invariants.py::test_messages_fts_deletion_consistency_with_external_content -q→ 6 passedpython -m mypy polylogue/daemon/cli.py polylogue/storage/conversation_replacement.py tests/unit/daemon/test_daemon_cli.py tests/unit/storage/test_fts_bloat_invariants.py→ successruff format ... && ruff check ...→ all checks passeddevtools render-all --check→ OKdevtools verify --quick→ exit_code 0, total_duration_s 35.58