Skip to content

fix(daemon): bound FTS health probes - #1445

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/bounded-fts-health-probes
May 23, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/bounded-fts-health-probes

Conversation

@Sinity

@Sinity Sinity commented May 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Replace daemon FTS health/status readiness with bounded structural probes so /healthz/ready cannot scan the production archive while catch-up ingest is running.

Problem

#1443 fixed the startup path, but live verification showed /healthz/ready on the API socket still timed out. The route called fts_readiness_info(), which delegated to the exact FTS invariant snapshot. On the live archive, those count and anti-join probes over messages / messages_fts_docsize took tens of seconds and could make readiness unusable even though the daemon was already listening and converging.

Solution

polylogue/daemon/fts_status.py now uses sqlite_master-only structural checks for the daemon health/status surface: source table existence, FTS table existence, and expected trigger presence for each FTS surface. It reports coverage_exact=false so the payload is explicit that health readiness is not row-count proof. Exact FTS freshness remains enforced by the search/maintenance invariant paths rather than by the readiness endpoint.

The daemon status test now traces SQL and asserts the health readiness path does not issue COUNT(*) FROM messages, COUNT(*) FROM messages_fts_docsize, or FTS docsize joins.

Closes #1444

Verification

  • pytest tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_health_contract.py -q -> 30 passed
  • pytest tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_health_contract.py tests/unit/daemon/test_daemon_cli.py 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/storage/test_fts5.py -q -> 141 passed
  • devtools verify --quick -> exit_code 0, total_duration_s 37.18

Summary by CodeRabbit

Release Notes

  • Refactor
    • Refined full-text search readiness detection to use schema analysis instead of snapshot comparisons.
    • Modified readiness status metrics: coverage now reports simplified values and includes a precision indicator.

Review Change Stack

Health and status readiness reused the exact FTS invariant snapshot, which scans live FTS docsize tables and anti-joins messages. On the production archive those probes can take tens of seconds and make /healthz/ready time out while the daemon is otherwise serving and converging.

Replace that path with structural checks over sqlite_master: source table presence, FTS table presence, and trigger presence. Exact freshness remains an explicit search/maintenance invariant; readiness now reports coverage_exact=false instead of pretending these bounded probes are row-count proof.

Ref #1444
@coderabbitai

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 310280a4-37da-4a99-9bd5-18cd261c2577

📥 Commits

Reviewing files that changed from the base of the PR and between 9b9e105 and 70deebe.

📒 Files selected for processing (2)
  • polylogue/daemon/fts_status.py
  • tests/unit/daemon/test_daemon_status.py

📝 Walkthrough

Walkthrough

FTS readiness probing is refactored to use bounded schema checks instead of expensive snapshot sync and exact-count queries. The implementation adds structural table/trigger presence checks against sqlite_master, derives readiness flags from schema artifacts, and returns simplified metrics with coverage_exact set to False. Tests verify no COUNT(*) or docsize join queries are executed.

Changes

FTS Readiness Bounded Probing

Layer / File(s) Summary
Bounded structural schema probes and readiness computation
polylogue/daemon/fts_status.py
Introduces _FTS_SURFACES constant mapping FTS surface metadata (base/FTS table pairs and trigger names), adds _table_exists() and _triggers_present() helpers for bounded sqlite_master queries, and rewrites fts_readiness_info() to build a surfaces readiness map from schema presence checks. Returns payload with per-surface readiness flags, zero row/index metrics, and coverage_pct simplified to 100.0 or 0.0 with coverage_exact: False.
Test coverage for bounded structural probes
tests/unit/daemon/test_daemon_status.py
Test function renamed to reflect bounded probes rather than exact counts. SQL fixture adds action_events_fts_au trigger definition. Assertions verify readiness flags are True and coverage_exact is False, while recorded SQLite trace queries exclude COUNT(*), docsize, and anti-join patterns, confirming structural-probe-only behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #1444: Implements the fix for FTS readiness timing out under active ingest by switching from expensive COUNT(*) and snapshot-based probes to bounded structural table/trigger presence checks.

Possibly related PRs

  • Sinity/polylogue#1443: Both PRs refactor daemon FTS readiness logic away from expensive exact-count probing toward bounded structural checks and update tests to assert COUNT(*) queries are not executed.
  • Sinity/polylogue#1434: Both PRs modify fts_readiness_info() in polylogue/daemon/fts_status.py to replace COUNT-based exact logic with bounded structural probes.
  • Sinity/polylogue#554: Both PRs probe required SQLite schema artifacts (especially named FTS triggers via sqlite_master) to determine readiness and adjust tests accordingly.

Poem

🐰 No more slow counts through the FTS sprawl,
We probe the schema artifacts—that's all!
Tables and triggers, bounded and fleet,
Health checks complete in a quick heartbeat. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: bounding FTS health probes to prevent expensive operations during readiness checks.
Description check ✅ Passed The description covers all required template sections: Summary, Problem, Solution, Verification, and Changelog (explicitly skipped). It comprehensively explains the issue, implementation approach, and testing performed.
Linked Issues check ✅ Passed All objectives from #1444 are met: structural probes only (no COUNT/anti-joins), missing FTS states visible, exact checks preserved elsewhere, tests verify no problematic queries, and acceptance criteria are satisfied.
Out of Scope Changes check ✅ Passed All changes align with objectives: fts_status.py refactored for structural checks, test updated to verify no expensive queries, and function signature unchanged. No out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/bounded-fts-health-probes

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 1eafad9 into master May 23, 2026
5 of 6 checks passed
@Sinity
Sinity deleted the feature/fix/bounded-fts-health-probes branch May 23, 2026 17:16

@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: 70deebefc2

ℹ️ 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/fts_status.py Resolved
@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.

  • 63.F062 / P2: fixed-already at the checked revision: The status DTO construction now explicitly carries coverage_exact from the readiness payload at polylogue/daemon/status.py:3273, and its public projection includes readiness.coverage_exact at line 2317. Consumers no longer lose the qualifier during shaping.

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.

fix(daemon): keep FTS health readiness bounded under ingest

1 participant