Repository navigation
perf(daemon): avoid virtual FTS status counts - #1431
Conversation
Use FTS5 docsize shadow tables for daemon health and convergence readiness counts so production status paths do not scan the virtual FTS table on multi-million-message archives.\n\nVerification:\n- pytest tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_convergence_stages.py -q --tb=short\n- mypy polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py\n- ruff format --check polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py\n- ruff check polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py\n- timeout 10 python - <<'PY' ... daemon_status_payload() ... PY
📝 WalkthroughWalkthroughThis PR changes how the daemon measures FTS (Full-Text Search) index coverage across convergence stages, CLI periodic checks, and health monitoring. Instead of counting rows in FTS virtual tables ( ChangesFTS docsize measurement across daemon checks
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 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 |
Check for missing FTS triggers before ensure_fts_index_sync recreates them. Otherwise startup can restore the trigger DDL but skip the rebuild needed after writes landed while sync triggers were absent.\n\nVerification:\n- 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_when_triggers_missing tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_convergence_stages.py -q --tb=short\n- mypy polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_cli.py\n- ruff format --check polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_cli.py\n- ruff check polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_cli.py
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfc1ecc2e0
ℹ️ 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".
Summary Fix daemon FTS readiness and repair when FTS docsize shadow tables contain orphan rows, not only missing rows. Startup, periodic convergence, and daemon status now treat source/docsize count inequality in either direction as drift. Problem The live archive after #1431 had restored triggers but still showed docsize overcounts: messages_fts_docsize and action_events_fts_docsize exceeded their source tables by hundreds of thousands of rows. The old repair predicates only rebuilt on undercounts, so overcount corruption was reported as healthy. Solution The daemon now compares message FTS against indexable message rows and action FTS against action events, rebuilding on mismatch. FTS status projection moved into a dedicated module with explicit count and coverage fields, and CLI status renders those fields instead of inferring a missing percentage. A regression test recreates orphan docsize rows by deleting source rows while the delete trigger is absent. Verification - pytest focused daemon/status suite: 27 passed - mypy focused daemon/status suite: success - ruff format/check focused files: passed - devtools verify-file-budgets: clean - devtools render-all --check: passed - devtools verify-topology: passed - pre-push devtools verify --quick: passed, 36.52s - PR checks: CodeQL, containers, Pages Preview, GitGuardian passed
|
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
Use FTS5 docsize shadow tables for daemon status, health, and convergence readiness counts, and fix startup trigger-drift recovery so missing FTS sync triggers cause a rebuild instead of restore-only.
Problem
After deploying #1430,
polylogue --plain statusstill timed out against the real archive. The direct CLI fallback had already been moved tomessages_fts_docsize, but/api/statusstill called daemon health, whose medium FTS readiness check usedCOUNT(*) FROM messages_fts. The same virtual-table count pattern also remained in periodic convergence and global FTS-stage fallback paths.Live inspection also showed all six production FTS sync triggers were absent and docsize counts had drifted above source table counts. Startup intended to repair this, but it called
ensure_fts_index_sync()before checking for missing triggers; that recreated triggers and erased the evidence before the rebuild branch ran.Solution
polylogue/daemon/health.pynow usesmessages_fts_docsizefor FTS row counts and treats a missing docsize table as degraded.polylogue/daemon/convergence_stages.pyandpolylogue/daemon/cli.pyuse the same shadow-table count for global FTS readiness/rebuild checks.Startup readiness now checks for missing FTS triggers before calling
ensure_fts_index_sync(). When trigger drift is found, it restores triggers and rebuilds FTS in the same startup pass.Verification
pytest tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_convergence_stages.py -q --tb=short→ 35 passedpytest 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_when_triggers_missing tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_convergence_stages.py -q --tb=short→ 38 passedmypy polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_cli.py→ Successruff format --check polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_cli.py→ passedruff check polylogue/daemon/health.py polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py tests/unit/daemon/test_health_check_paths.py tests/unit/daemon/test_daemon_cli.py→ passedtimeout 10 python - <<'PY' ... daemon_status_payload() ... PYagainst the real archive → returned successfullydevtools verify --quick→ pass, 35.11s on latest commit