Repository navigation
fix(daemon): reduce large ingest FTS amplification - #1453
Conversation
Large live catch-up files were still paying per-row FTS trigger work and, for some paths, post-write conversation repair over the same changed rows. That kept one 31k-message Codex session in a long SQLite write window and continued to drive heavy IO pressure after file-batch chunking landed. This keeps the conservative archive write default, but lets live append/full-ingest paths distinguish trigger-maintained rows from explicit repair. Large full-ingest batches now suspend FTS triggers inside the ingest transaction, write rows, restore triggers, and repair the changed conversations once before commit. The suspended path no longer starts outside BEGIN, avoiding the existing transaction error and keeping rollback atomic. 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; 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; devtools verify --quick.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR adds independent control of full-text search repair behavior across the ingestion pipeline. FTS trigger suspension now supports optional stale-marking, archive write effects split message and action FTS repair into separate gates, ingest core orchestrates repairs based on suspension state, and full/append ingests use distinct strategies for when to repair. ChangesFTS Repair Control During Ingestion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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: f75e3e001e
ℹ️ 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".
|
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
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_syncdropped FTS triggers beforeBEGIN IMMEDIATE, so a suspended bulk path could fail withsqlite3.OperationalError: cannot start a transaction within a transaction.Solution
repair_message_ftsswitch to the canonical archive write effects path, matching the existingrepair_action_ftscontrol.BEGIN IMMEDIATEand addmark_stale=Falsefor 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:
0.292s0.143sThis 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.16spython -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 filesdevtools verify --quick→ PASS,exit_code: 0,total_duration_s: 34.63devtools verify --quick→ PASS,exit_code: 0,total_duration_s: 35.15devtools verifyreached pytest-testmon and was stopped after785.8sbecause the affected selector expanded to effectively the full serial suite (9297JUnit 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 by CodeRabbit
Performance Improvements
Bug Fixes
Tests