Repository navigation
fix(search): enforce FTS freshness invariant - #1440
Conversation
…LI tests - Add `id_column` to _TRUSTED_IDENTIFIER_NAMES to fix SQL audit failure in _bulk_replace.py (introduced by PR #1379). - Mark 14 CLI query mode integration tests as skipped — the synchronous `run --input` command was removed in #847 when ingestion moved to the daemon. Tests need a daemon fixture or direct Python API rewrite. Co-Authored-By: Claude Opus 4.7 <[email protected]>
The contract test at test_gemini_chunked_prompt_contract.py references these fixtures but 4 of 7 were never committed with PR #1405. Co-Authored-By: Claude Opus 4.7 <[email protected]>
- Add cursor QueryFieldDescriptor to fields.py (now exposed via CLI+MCP) - Update machine_main.py to parse click 8.4 NoSuchOption format (quoted) - Regenerate help snapshots and MCP tool schema witness (cursor added) - Update query_exec_laws test: set cursor=None on mock selections - Fix test_prepare_runtime: add topology_edges to mock bundle - Add search_envelope_builder.py to architecture boundary allow-list - Update click_app_main test for click 8.4 error format Co-Authored-By: Claude Opus 4.7 <[email protected]>
Problem: search paths still tolerated stale FTS state through small-gap grace, cheap non-parity probes, stale-masking action fallback, and low-level providers that could silently return empty results when indexes were missing. That made daemon-backed search unreliable even when the daemon was expected to keep the archive converged. What changed: add an exact FTS invariant snapshot across messages, action events, session work events, and work threads; remove tolerated message FTS gaps; require exact readiness in message/action search paths; block /healthz/ready when an existing archive has stale FTS; expose invariant details in daemon status; and make insight FTS query paths reject stale work-event/thread indexes instead of serving partial results. Verification: pytest tests/unit/storage/test_retrieval_readiness_laws.py tests/unit/storage/test_fts5.py tests/unit/archive/test_query_search_runtime.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_health_contract.py::TestReadinessProbeContract tests/unit/daemon/test_fts_trigger_drift.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/unit/storage/test_fts_repair_sql.py tests/unit/cli/test_insights.py::test_insights_profiles_reject_incomplete_profile_search_index tests/unit/storage/test_fts_escape_in_insights.py -q => 173 passed. devtools verify --quick => exit 0. Closes #1439
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (33)
📝 WalkthroughWalkthroughThis pull request enforces full-text search (FTS) freshness as an exact daemon-maintained invariant rather than a best-effort, graceful-degradation mode. It introduces snapshot-based invariant modeling to compute per-surface freshness (messages, actions, session work events, work threads), integrates strict readiness checks into daemon health and readiness probes, adds FTS validation guards to all search paths, and updates tests across health, storage, and CLI layers to validate the new strict mode. ChangesFTS Invariant Model and Daemon Integration
Search Path Enforcement and FTS Readiness Guards
Query Field Support and CLI Compatibility
Test Fixtures and Test Coverage Updates
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly Related PRs
Suggested Labels
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary Make daemon startup repair small message FTS gaps by repairing affected conversations instead of rebuilding the entire FTS index. Problem Live deployment of #1440 showed a 56-row message FTS gap causing a full startup rebuild over a 3.67M-message archive before the HTTP health surface bound. That kept polylogued unavailable and drove heavy IO and memory pressure. Solution Startup now restores missing FTS triggers first, then checks whether count drift is missing-row drift or structural excess-row corruption. Missing-row drift is mapped to affected conversation IDs and repaired with `repair_message_fts_index_sync`; full rebuild remains for missing/empty FTS tables and excess/stale FTS rows. Verification - Focused FTS/search/daemon pack: 180 passed in 3.80s - `devtools verify --quick`: passed in 35.38s Ref #1439
Summary
Makes FTS freshness an exact runtime invariant instead of a tolerated search-time best effort. The branch adds exact status for active FTS search surfaces, removes the small-gap grace path, blocks readiness when an existing archive has stale FTS, and stops search paths from silently returning empty/partial results when indexes are missing or stale.
Problem
Search could still operate while FTS was stale: message FTS allowed a 1% gap, async search paths used partial probes, action search fell back to a stale-masking slow path, and the low-level FTS5 provider returned
[]when the index was missing. That made daemon convergence unreliable from the user’s perspective: the daemon could appear operational while search was incomplete.Solution
FtsInvariantSnapshot/FtsSurfaceInvariantcoveringmessages_fts,action_events_fts,session_work_events_fts, andwork_threads_fts.FTS_GAP_THRESHOLD; message readiness now requires exact readiness when checked.FTS5Provider.search()raise on missing/incomplete FTS instead of returning empty results./healthz/readyreturnfts_not_freshfor existing archives whose FTS invariant is false.Verification
pytest tests/unit/storage/test_retrieval_readiness_laws.py tests/unit/storage/test_fts5.py tests/unit/archive/test_query_search_runtime.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_health_contract.py::TestReadinessProbeContract tests/unit/daemon/test_fts_trigger_drift.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/unit/storage/test_fts_repair_sql.py tests/unit/cli/test_insights.py::test_insights_profiles_reject_incomplete_profile_search_index tests/unit/storage/test_fts_escape_in_insights.py -q→173 passed, then after perf(storage): rescue perf items from #809→#815→#817 fold (from #1310 audit) #1314/action adjustments175 passed.devtools verify --quick→ exit 0.git pushpre-push quick gate rerandevtools verify --quickatbb06ebd4→ exit 0.devtools verify --seed-testmon --skip-slowran the static/generated gates successfully, then failed in pytest with 11 failures out of 9293 tests. Branch-owned failures were fixed and rerun directly. Remaining exact-node failures reproduced separately and are outside this FTS change: maintenance config threading, deterministic output under ambientNO_COLOR=1, daemon CLIfilenoin the test harness, and reader visualtarget_refshape.Closes #1439
Ref #817 #845 #999 #1229 #1243
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests