Repository navigation
fix(search): ground FTS freshness in invariants - #1500
Conversation
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 54 minutes and 44 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: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughEmpty-string message text is excluded from FTS indexable-row counts across SQL helpers, trigger generation, and invariant snapshots. Daemon startup now bases FTS readiness on an executable invariant snapshot instead of structural checks, rebuilding FTS if the snapshot indicates staleness and recording the invariant state for durable verification. ChangesFTS Freshness via Invariant Snapshots
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 78545de9e7
ℹ️ 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".
Daemon startup no longer records a durable FTS ready row from structural table and trigger checks alone. It now records the exact FTS invariant snapshot and rebuilds before serving search when the invariant is stale. Align the message indexable-row definition with the actual FTS projection by excluding empty message text unless content blocks, tool input, or metadata provide searchable content. Closes #1499
78545de to
5aa1ae6
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@polylogue/storage/fts/fts_lifecycle.py`:
- Around line 872-873: The no-content-block rebuild branches still use the
legacy WHERE text IS NOT NULL predicate which allows empty-string texts to be
counted/inserted, so update those SQL fragments to use the same empty-text
invariant as the rest of the code: replace occurrences of "WHERE text IS NOT
NULL" in the no-content-block rebuild SQL (the SELECT/COUNT and any INSERT ...
SELECT clauses) with "WHERE NULLIF(text, '') IS NOT NULL" so they ignore
empty-string text; search for the SQL fragments in
polylogue/storage/fts/fts_lifecycle.py (the no-content-block rebuild branches
around the existing NULLIF usage) and make the replacement in each branch (the
three spots noted).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5d0f06d8-b6ac-48ca-95ef-02cfe30dabe1
📒 Files selected for processing (6)
polylogue/daemon/cli.pypolylogue/storage/fts/fts_lifecycle.pypolylogue/storage/fts/sql.pypolylogue/storage/sqlite/schema_ddl_archive.pytests/unit/daemon/test_daemon_cli.pytests/unit/storage/test_retrieval_readiness_laws.py
Summary: Make live ingest maintain FTS freshness as a write-side invariant instead of relying on trigger timing alone. Problem: After exact startup readiness landed in #1500, the production archive still drifted during live catch-up. With the daemon stopped, exact invariants showed 10,414 missing message FTS rows and 3,777 missing action-event FTS rows. The missing message rows were block-only messages whose searchable text lives in content_blocks; live full/append ingest had opted out of conversation-scoped repair unless triggers were suspended, and explicit repair flags were ignored when triggers existed. Solution: Treat repair_message_fts/repair_action_fts as literal write-effect requests, make live full and append ingest request conversation-scoped message/action repairs for changed conversations, refresh trigger definitions before stale-startup rebuilds, and make exact invariant snapshots read one stable transaction. Verification: pytest tests/unit/archive/test_write_gateway.py tests/unit/daemon/test_daemon_cli.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_retrieval_readiness_laws.py tests/unit/storage/test_perf_rescue_1314.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_ingest_batch_wal_checkpoint.py tests/unit/storage/test_fts_trigger_lifecycle.py -q (87 passed); devtools verify --quick (exit_code 0); pre-push devtools verify --quick (exit_code 0); production archive targeted repair reported all FTS surfaces ready with zero missing/excess/duplicates. Closes #1501
polylogue-gibn1, decisive: instrumented the sole consumer of summary.fts_repair_session_ids (_commit_sync_ingest_side_effects) and it never printed across five sessions and sixty messages in the failing convergence-evidence test. The repair is nested inside `if transaction_started`, so a route with an externally managed transaction skips FTS repair along with every other post-write side effect. Eliminated: repair_message_fts (defaults True everywhere, no daemon override), the repair queue itself (content_changed appends unconditionally), the invariant reader, and the triggers. Three independent places each assume another will populate the index: replay defers the reinsert, ingest-side repair never runs, and the path-scoped convergence check is a hardcoded `return False`. Read the #1498 cascade retro as CLAUDE.md requires; its closed list names the adjacent history (#1462, #1469, #1472, #1500, #1502), several of which narrowed FTS repair to avoid redundant work. Those PR bodies are the place to start. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWcPJJJvuF25CqVwTFgSQC
|
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
Daemon startup now grounds the durable FTS freshness ledger in exact executable invariants instead of structural table/trigger checks. If startup observes a stale FTS surface, it rebuilds before search is served. The message indexable-row definition now matches the actual FTS projection by excluding empty
messages.textunless content blocks/tool input/metadata contribute searchable content.Problem
During the schema-v9 live re-ingest, the daemon recorded
messages_fts=readywithsource_rows=0,indexed_rows=0on a fresh DB. Catch-up then inserted over a million messages while the readiness ledger still said ready, so search readiness could trust a stale durable row. Direct live evidence before repair showed 1,313,271 indexable message rows versus 818,824messages_fts_docsizerows.Solution
_ensure_fts_startup_readiness()now recordsfts_freshness_statefromfts_invariant_snapshot_sync()and rebuilds when the invariant is stale. The startup path still restores missing triggers and rebuilds for the SIGKILL/bulk-suspend failure mode.The invariant and trigger projection now agree that empty message text is not searchable content. This fixed the live false-stale result after rebuild: with the corrected definition, the partial live DB reported
messages_fts|ready|...|743090|743090|0|0|0|.Closes #1499
Verification
pytest tests/unit/daemon/test_daemon_cli.py -q→ 19 passedpytest tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_health_contract.py tests/unit/storage/test_perf_rescue_1314.py -q→ 41 passedpytest tests/unit/daemon/test_daemon_cli.py tests/unit/storage/test_retrieval_readiness_laws.py -q→ 25 passedpython - <<'PY' ... _ensure_fts_startup_readiness() ... PYagainst the live partial DB → first run rebuilt in 186.188s; after the empty-text fix, exact startup readiness completed in 21.788s and recorded all FTS surfaces ready.devtools verify --quick→ pass, 34.42sSummary by CodeRabbit
Release Notes