Skip to content

fix(daemon): repair FTS overcount drift - #1432

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/daemon-status-fts-repair
May 23, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/daemon-status-fts-repair

Conversation

@Sinity

@Sinity Sinity commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes daemon FTS readiness and repair when the FTS docsize shadow tables contain orphan rows, not only missing rows. The live archive showed triggers restored after startup repair but messages_fts_docsize and action_events_fts_docsize still exceeded their source tables, so the existing undercount-only predicates treated corrupted FTS state as healthy.

Problem

After deploying #1431, the real archive had all six FTS triggers restored but still reported:

  • messages: 3,668,083 vs messages_fts_docsize: 3,794,513
  • action_events: 1,734,882 vs action_events_fts_docsize: 1,813,973
  • orphan docsize rows: 184,096 message rows and 199,604 action rows

The daemon's global FTS repair only rebuilt when indexed count was lower than source count. Interrupted rebuild/delete paths can leave overcounts, which are just as invalid and keep status/search readiness misleading.

Solution

  • Treat FTS source/docsize count inequality in either direction as global FTS drift.
  • Compare message FTS against indexable messages (text IS NOT NULL) rather than all messages.
  • Make startup and periodic convergence rebuild on count mismatch, not only empty/undercount states.
  • Move daemon FTS status projection to polylogue.daemon.fts_status and expose explicit count/coverage fields.
  • Render CLI daemon status from reported coverage instead of inventing a missing percentage.
  • Add a regression test that creates orphan docsize rows by deleting source rows with the delete trigger absent.
  • Keep the focused mypy slice clean for the optional journald binding import.

Verification

  • pytest tests/unit/daemon/test_daemon_status.py 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_fts_global_repair.py tests/unit/daemon/test_convergence_stages.py tests/unit/cli/test_status.py::TestNoArchiveStatus::test_daemon_status_uses_reported_fts_coverage_pct -q --tb=short → 27 passed
  • mypy --no-incremental polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py polylogue/daemon/status.py polylogue/daemon/fts_status.py polylogue/daemon/notification_backends/journald.py polylogue/cli/commands/status.py tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_fts_global_repair.py tests/unit/cli/test_status.py → success
  • ruff format --check ... → passed
  • ruff check ... → passed
  • devtools verify-file-budgets → clean
  • devtools render-all --check → passed
  • devtools verify-topology → passed
  • pre-push devtools verify --quick → passed, 36.52s

Detect FTS docsize overcounts as corruption, not readiness. Startup and periodic convergence now rebuild when indexed counts differ from source counts in either direction, and daemon status reports real FTS coverage fields instead of making the CLI infer a missing percentage.\n\nAlso keeps the focused mypy slice clean for the journald optional binding import.\n\nVerification:\npytest 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_fts_global_repair.py tests/unit/daemon/test_convergence_stages.py tests/unit/cli/test_status.py::TestNoArchiveStatus::test_daemon_status_uses_reported_fts_coverage_pct -q --tb=short\nmypy polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py polylogue/daemon/status.py polylogue/daemon/notification_backends/journald.py polylogue/cli/commands/status.py tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_fts_global_repair.py tests/unit/cli/test_status.py\nruff format --check polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py polylogue/daemon/status.py polylogue/daemon/notification_backends/journald.py polylogue/cli/commands/status.py tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_fts_global_repair.py tests/unit/cli/test_status.py\nruff check polylogue/daemon/convergence_stages.py polylogue/daemon/cli.py polylogue/daemon/status.py polylogue/daemon/notification_backends/journald.py polylogue/cli/commands/status.py tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_fts_global_repair.py tests/unit/cli/test_status.py
@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 29 minutes and 10 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 858060be-ae2c-494c-9b20-ed7922738776

📥 Commits

Reviewing files that changed from the base of the PR and between a148aee and a36aaf3.

📒 Files selected for processing (12)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/cli/commands/status.py
  • polylogue/daemon/cli.py
  • polylogue/daemon/convergence_stages.py
  • polylogue/daemon/fts_status.py
  • polylogue/daemon/notification_backends/journald.py
  • polylogue/daemon/status.py
  • tests/unit/cli/test_status.py
  • tests/unit/daemon/test_daemon_cli.py
  • tests/unit/daemon/test_daemon_status.py
  • tests/unit/daemon/test_fts_global_repair.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/perf/daemon-status-fts-repair

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit c88d3be into master May 23, 2026
7 checks passed
@Sinity
Sinity deleted the feature/perf/daemon-status-fts-repair branch May 23, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant