Repository navigation
fix(daemon): bound live catch-up ingest batches - #1452
Conversation
Catch-up still scans and converges the full source set, but it no longer sends every changed file into one parse/write batch. The live archive showed 310 changed files and 460 MB being ingested as a single unit, driving high RSS, cgroup file cache, WAL churn, and IO PSI. Chunk catch-up work by file count and source bytes while preserving scope. Each chunk is ingested serially, so all files still converge but large startup catch-up releases parser/write state between bounded batches. Ref #1447
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 18 minutes and 11 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 (2)
✨ 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 |
## Summary Reduce the remaining live catch-up write amplification for huge single-session files. Live append/full-ingest paths now avoid redundant message FTS repair when active triggers already maintained FTS rows, while large full-ingest batches deliberately suspend triggers inside the ingest transaction and repair the changed conversations once before commit. ## Problem After #1452 bounded catch-up into file chunks, live validation still showed a single 221 MB Codex session with 31,417 messages spending 314 seconds in `slow_write`, driving severe host IO pressure. The batch was bounded, but the single-conversation write path was still monolithic and FTS-heavy. The code also had a latent suspended-trigger transaction bug: `_process_ingest_batch_sync` dropped FTS triggers before `BEGIN IMMEDIATE`, so a suspended bulk path could fail with `sqlite3.OperationalError: cannot start a transaction within a transaction`. ## Solution - Add a `repair_message_fts` switch to the canonical archive write effects path, matching the existing `repair_action_fts` control. - Keep conservative defaults for ordinary archive writes. - Make live append ingest opt out of redundant message/action FTS repair because FTS triggers are active for those row writes. - Make live full ingest suspend FTS triggers for raw records at or above 32 MiB, then force message/action FTS repair once before commit. - Move sync trigger suspension inside `BEGIN IMMEDIATE` and add `mark_stale=False` for transaction-scoped suspension so an already-ready freshness ledger is not falsely degraded by a transaction that repairs before commit. Synthetic local probe on a temporary archive with a 12k-message conversation: - active triggers + post-write message repair: `0.292s` - suspended triggers + one message repair: `0.143s` This does not claim the production 31k-message case is solved completely; it removes a known FTS write-amplification layer and fixes the transaction bug. The next live daemon run should verify residual parse/write/insight cost against the real 221 MB session. ## Verification - `pytest tests/unit/archive/test_write_gateway.py tests/unit/sources/test_live_batch_support.py tests/unit/pipeline/test_ingest_batch.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/unit/storage/test_fts_bloat_invariants.py -q` → `51 passed in 1.16s` - `python -m mypy polylogue/archive/write_effects.py polylogue/pipeline/services/ingest_batch/_core.py polylogue/sources/live/batch.py polylogue/sources/live/append_ingest.py polylogue/storage/fts/fts_lifecycle.py tests/unit/archive/test_write_gateway.py tests/unit/sources/test_live_batch_support.py` → `Success: no issues found in 7 source files` - `devtools verify --quick` → PASS, `exit_code: 0`, `total_duration_s: 34.63` - pre-push `devtools verify --quick` → PASS, `exit_code: 0`, `total_duration_s: 35.15` `devtools verify` reached pytest-testmon and was stopped after `785.8s` because the affected selector expanded to effectively the full serial suite (`9297` JUnit testcases recorded, `failures=0`, `skipped=2`) and was still running at 99%. That behavior is the existing verification-efficiency problem being tracked separately; I did not restart another broad pytest loop for this small branch. Ref #1447.
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 just no longer sends every changed startup file into one huge parse/write batch.
Problem
Live validation after deploying #1451 showed the next resource failure clearly: startup catch-up planned 310 changed files / 460.8 MB and ingested them as one unit. That single batch pushed the daemon back to the systemd 6 GiB high line, accumulated swap, drove 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. The first chunk preserves the whole catch-up queued/skipped context; later chunks report their own bounded sizes.
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.26sruff format --check polylogue/sources/live/watcher.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_catchup_planning.py→ 3 files already formattedruff check polylogue/sources/live/watcher.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_catchup_planning.py→ All checks passedmypy polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py→ Success: no issues found in 2 source filesdevtools verify --quick→ exit_code 0, total_duration_s 34.47devtools verify --quick→ exit_code 0, total_duration_s 34.27Ref #1447