Skip to content

fix(daemon): target startup FTS gap repair - #1441

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/targeted-fts-startup-repair
May 23, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/targeted-fts-startup-repair

Conversation

@Sinity

@Sinity Sinity commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

Make daemon startup repair small FTS gaps by repairing only the conversations with missing message FTS rows instead of rebuilding the entire archive FTS index. Full rebuild remains for missing/empty FTS tables and structural excess-row corruption.

Problem

Live deployment of #1440 showed the daemon detecting a 56-row message FTS gap in a 3.67M-message archive and starting a full FTS rebuild before binding the HTTP health surface. That consumed ~21GB reads, ~9GB writes, peaked at the 6G memory-high boundary, left the daemon not listening on 8765/8766, and drove IO PSI severe.

Solution

Startup now distinguishes missing-row drift from structural corruption. When messages_fts_docsize is behind conversation_stats, it locates affected messages.conversation_id values via the missing rowids and runs repair_message_fts_index_sync for those conversations. Missing triggers are restored first and then flow through the same freshness repair path. Excess/stale FTS docsize rows still fall back to a full rebuild because external-content FTS rows cannot be safely deleted without the source row.

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_repairs_missing_message_rows tests/unit/daemon/test_daemon_cli.py::test_ensure_fts_startup_readiness_rebuilds_when_triggers_missing tests/unit/cli/test_query_exec.py::test_query_plan_action_retrieval_lane_rejects_unready_action_read_model tests/unit/storage/test_perf_rescue_1314.py::test_search_conversation_hits_does_not_count_fts_index 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 — 180 passed in 3.80s
  • devtools verify --quick — passed in 35.38s

Ref #1439

@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 41 minutes and 16 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: c33490ac-631f-4f18-8ff7-70142f4e4b17

📥 Commits

Reviewing files that changed from the base of the PR and between 39c636d and 68227a5.

📒 Files selected for processing (2)
  • polylogue/daemon/cli.py
  • tests/unit/daemon/test_daemon_cli.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/targeted-fts-startup-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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68227a5664

ℹ️ 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".

Comment thread polylogue/daemon/cli.py Resolved
@Sinity
Sinity merged commit 81024be into master May 23, 2026
6 checks passed
@Sinity
Sinity deleted the feature/fix/targeted-fts-startup-repair branch May 23, 2026 15:36
Sinity added a commit that referenced this pull request May 23, 2026
Problem: live deployment of #1441 still showed polylogued scanning the FTS shadow tables before binding health sockets. On the production archive a docsize count took about 19s, join probes ran beyond 30s, and the daemon read hundreds of MB/s while peaking at the 6G cgroup limit.

Solution: keep daemon startup to cheap structural FTS checks only: missing table, missing triggers, and completely empty message FTS while source messages exist. Exact FTS freshness scans stay out of the pre-listen path. Regression tests now reject startup COUNT/JOIN probes over messages_fts_docsize, and faulthandler setup tolerates runner streams without fileno.

Verification: focused daemon/FTS pytest pack passed with 154 tests; devtools verify --quick passed locally and again in the pre-push hook. GitHub CodeQL, container builds, and GitGuardian passed.

Closes #1442
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 62.F030 / P1: stale at the checked revision: The separate action-event FTS surface is no longer part of the current index contract. The combined FTS trigger inventory is exclusively BLOCKS_FTS_TRIGGER_DDL at polylogue/storage/fts/sql.py:219, and readiness publishes only messages_fts at polylogue/daemon/fts_status.py:180; there is no current action_events_fts surface for the old startup branch to leave stale.

Only the rows listed above are dispositioned. Held findings remain open.

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