Skip to content

fix(daemon): keep exact FTS scans out of startup - #1451

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

Sinity merged 1 commit into
masterfrom
feature/fix/daemon-startup-fts-scan

Conversation

@Sinity

@Sinity Sinity commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

Keep daemon startup and search request paths from performing surprise exact FTS invariant scans. Startup now restores obvious FTS structure, records the durable freshness state as unknown or stale when exact repair is pending, and lets the ambient repair loop own full invariant scans after HTTP/status surfaces have bound.

Problem

The deployed aba8d6d3 build regressed under the real archive: polylogued.service logged daemon started but did not bind :8765/:8766, while the process sat in disk sleep and read ~25 GB before the freshness table had even been created. Systemd showed ~6.4 GB cgroup memory, but /proc/$pid/status showed RSS under 1 GB and memory.stat showed the bulk was file cache, so this was SQLite/FTS read amplification charged to the service rather than pure Python heap growth.

Solution

Startup no longer runs fts_invariant_snapshot_sync() for existing populated FTS indexes. It performs bounded structural checks, restores missing triggers, rebuilds only when the FTS table is missing or empty, and records freshness ledger state for request handlers. Search readiness now trusts a ready ledger row, and if the ledger explicitly says unknown/stale, it performs only a cheap structural probe and refuses stale search rather than launching an exact scan from a request path. The ambient FTS repair loop gets a short initial delay so HTTP can bind first, skips exact work when the ledger is ready and structure is still sound, and uses a smaller SQLite cache/mmap profile for exact repair.

Verification

  • pytest tests/unit/daemon/test_daemon_cli.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/unit/storage/test_fts5.py::test_search_with_empty_fts_rows_raises_descriptive_error tests/unit/core/test_query_retrieval_candidates.py -q → 25 passed in 0.96s
  • pytest tests/unit/daemon/test_metrics_endpoint.py tests/unit/storage/test_fts5.py::test_search_without_fts_table_raises_descriptive_error tests/unit/storage/test_fts5.py::test_search_with_empty_fts_rows_raises_descriptive_error tests/unit/core/test_query_retrieval_candidates.py -q → 16 passed in 0.41s
  • ruff format --check polylogue/storage/fts/freshness.py polylogue/storage/fts/fts_lifecycle.py polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py → 4 files already formatted
  • ruff check polylogue/storage/fts/freshness.py polylogue/storage/fts/fts_lifecycle.py polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py → All checks passed
  • mypy polylogue/storage/fts/freshness.py polylogue/storage/fts/fts_lifecycle.py polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py → Success: no issues found in 4 source files
  • devtools verify --quick → exit_code 0, total_duration_s 45.54
  • pre-push devtools verify --quick → exit_code 0, total_duration_s 35.62

Ref #1447

Startup must restore FTS structure and publish enough freshness state for request handlers, but it cannot pay the full archive invariant scan before HTTP/status surfaces bind. Live deployment showed that path reading tens of GB and charging gigabytes of file cache to the daemon cgroup before the service accepted connections.

This makes startup structural-only for existing FTS indexes, records unknown/stale freshness when exact repair is pending, keeps request-time search from launching a surprise full scan when the daemon ledger is non-ready, and lets the ambient repair loop own exact invariant work with a smaller SQLite cache profile.

Ref #1447
@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 34 minutes and 43 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: 05e3e6b1-0b6b-4547-8b1c-6a1cbe202de6

📥 Commits

Reviewing files that changed from the base of the PR and between aba8d6d and cebd234.

📒 Files selected for processing (4)
  • polylogue/daemon/cli.py
  • polylogue/storage/fts/freshness.py
  • polylogue/storage/fts/fts_lifecycle.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/daemon-startup-fts-scan

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 9136558 into master May 23, 2026
6 checks passed
@Sinity
Sinity deleted the feature/fix/daemon-startup-fts-scan branch May 23, 2026 20:18

@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: cebd234b69

ℹ️ 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/storage/fts/fts_lifecycle.py Resolved
Sinity added a commit that referenced this pull request May 23, 2026
Summary

Bound daemon catch-up ingestion into serial chunks by file count and source bytes. The daemon still scans and converges the full source set; it no longer sends every changed startup file into one huge parse/write batch.

Problem

Live validation after #1451 showed catch-up ingesting 310 changed files / 460.8 MB as one unit. That single batch drove the daemon back to the 6 GiB cgroup high line, accumulated swap, created high IO PSI, and produced a 172s slow write for a large Codex session.

Solution

Catch-up now chunks needed paths with bounded defaults: 50 files or 64 MiB of source bytes per batch. Chunks are ingested serially and preserve full convergence scope.

Verification

- pytest tests/unit/sources/test_live_watcher.py::test_catch_up_uses_bulk_cursor_records tests/unit/sources/test_live_watcher.py::test_catch_up_processes_pre_existing_files tests/unit/sources/test_live_catchup_planning.py -q → 4 passed in 0.26s
- ruff format/check on touched files passed
- mypy polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py → Success
- devtools verify --quick → exit_code 0, total_duration_s 34.47
- pre-push devtools verify --quick → exit_code 0, total_duration_s 34.27
- GitHub Analyze, CodeQL, GitGuardian, build(runtime), build(distroless) passed

Ref #1447
@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.

  • 73.F070 / P2: fixed-already at the checked revision: polylogue/storage/fts/fts_lifecycle.py:602-607 derives readiness from the actual canonical FTS relation rather than returning false for a stored unknown/stale telemetry state. A healthy index is not kept unavailable solely because the daemon did not replace an unknown freshness marker.

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