Repository navigation
fix(daemon): keep exact FTS scans out of startup - #1451
Conversation
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
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
💡 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".
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
|
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
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
unknownorstalewhen exact repair is pending, and lets the ambient repair loop own full invariant scans after HTTP/status surfaces have bound.Problem
The deployed
aba8d6d3build regressed under the real archive:polylogued.serviceloggeddaemon startedbut 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/statusshowed RSS under 1 GB andmemory.statshowed 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 areadyledger row, and if the ledger explicitly saysunknown/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.96spytest 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.41sruff 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 formattedruff 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 passedmypy 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 filesdevtools verify --quick→ exit_code 0, total_duration_s 45.54devtools verify --quick→ exit_code 0, total_duration_s 35.62Ref #1447