Repository navigation
perf(daemon): targeted FTS repair in archive convergence, not full rebuild (#1851) - #1895
Conversation
…build (#1851) Problem: the archive (split-file) FTS convergence paths (_archive_fts_execute / _execute_many / _execute_sessions) computed the changed session ids for a source path but then ignored them and called _archive_rebuild_messages_fts → rebuild_fts_index_sync, a FULL delete-all + re-insert of every message row in the corpus. So a single small append re-indexed the entire FTS index — ~14 MiB of writes per live-ingest batch regardless of payload size (~1000x amplification for small appends). The legacy monolith path already did targeted repair; the archive path never got the equivalent. What changed: add _archive_repair_sessions_fts(conn, session_ids) which uses the existing targeted primitive repair_message_fts_index_sync (per-session delete+insert of messages_fts rows, the same one the legacy path uses) and marks the surface ready, falling back to the full rebuild only when scope is unknown (no session ids). Route all three archive FTS execute paths through it. Correctness: messages_fts stays complete for the repaired sessions (_archive_fts_needs_repair returns False after), readiness/freshness state is updated via the existing _mark_message_fts_ready_after_targeted_repair, and the unknown-scope fallback preserves the full-rebuild behavior. No durability or raw-evidence change. Scope (partial, #1851): this lands slice 5 (the concrete write reduction) and its regression tests. The formal write-byte measurement artifact (slices 1-2/4 — deterministic fixture + page/WAL attribution + benchmark script) is a follow-up; the amplification source is already attributed here by code. Verification: devtools test tests/unit/daemon/test_convergence_stages.py → 28 passed (2 new: targeted-path-taken / full-rebuild-not-called, and unknown-scope fallback); adjacent FTS tests (test_fts_global_repair, test_fts5, test_fts_repair_sql) green; devtools verify --quick exit 0. (One unrelated test_status --json subprocess test flaked only in a mixed-file batch — passes isolated and in-file; pre-existing #1878-class cross-test stdout pollution, not this diff.) Ref #1851 Co-Authored-By: Claude <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughIntroduces ChangesTargeted session FTS repair
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
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: 09c970350b
ℹ️ 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".
…1900) ## Summary Adds `devtools ingest-amplification-probe` — a deterministic, host-independent measurement of per-tier write bytes per live-ingest batch, establishing the post-fix baseline for #1851 (slices 1-2/4). Additive tooling; no production ingest/daemon/storage code touched. ## Problem #1851 wanted the amplification not just fixed (#1895) but **measured and attributed**, with a repeatable artifact comparable across PRs. There was no such measurement. ## Solution `devtools/ingest_amplification_probe.py` (new) bootstraps a fresh 5-tier archive in an env-isolated temp dir (`XDG_DATA_HOME` + `POLYLOGUE_ARCHIVE_ROOT` — never touches real data), builds a deterministic synthetic corpus, ingests N single-session append batches through the existing public `parse_sources_archive` path (read-only use), and after each batch attributes bytes via `PRAGMA page_count * page_size` + WAL size per tier DB plus the blob store. Emits a stable JSON report (per-batch + per-tier deltas, amplification ratios, per-component shares). Registered as a `CommandSpec`. **Key finding:** on the `parse_sources_archive` path the raw payload is not materialized to source.db/blob (only a 32-byte hash + small rows) — the full blob is written by the daemon's lease path. So this probe measures the parsed-index durable footprint vs raw wire payload (~0.8–1.0× post-fix, 100% in index.db); `blob_store` is kept as an attributed component (shows 0 here rather than hiding it). ## Verification ``` devtools test tests/unit/devtools/test_ingest_amplification_probe.py # 5 passed devtools test test_command_catalog test_cli_wrapper # 11 passed devtools verify --quick # exit 0 ``` Deterministic: two runs produce byte-identical JSON. Ref #1851 --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
|
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
Kills the live-ingest write amplification: the archive FTS convergence paths now repair only the changed sessions'
messages_ftsrows instead of re-indexing the entire corpus on every batch.Problem
_archive_fts_execute/_archive_fts_execute_many/_archive_fts_execute_sessions(the split-file archive runtime path) computed the changedsession_idsfor a source path, then ignored them and called_archive_rebuild_messages_fts→rebuild_fts_index_sync— a full delete-all + re-insert of every message row in the corpus. A one-message append re-indexed the whole FTS index → ~14 MiB of writes per batch regardless of payload (~1000× amplification for small appends). The legacy monolith path already did targeted repair (_repair_changed_session_fts); the archive path never got the equivalent.Solution
_archive_repair_sessions_fts(conn, session_ids)uses the existing targeted primitiverepair_message_fts_index_sync(per-session delete+insert ofmessages_ftsrows) and_mark_message_fts_ready_after_targeted_repair, falling back to the full rebuild only when scope is unknown (no ids). All three archive FTS execute paths route through it.Correctness preserved:
_archive_fts_needs_repairreturns False after targeted repair (index complete for the changed sessions), readiness/freshness state is updated through the existing helper, and the unknown-scope fallback keeps the full-rebuild behavior. No durability/raw-evidence change.Verification
New tests:
test_fts_stage_uses_targeted_repair_not_full_rebuild(spies that the targeted primitive is called andrebuild_fts_index_syncis not, whilemessages_ftsstays complete) andtest_archive_repair_sessions_fts_falls_back_to_full_rebuild_without_ids. One unrelatedstatus --jsonsubprocess test flaked only in a mixed-file batch (passes isolated + in-file; pre-existing #1878-class cross-test stdout pollution).Ref #1851
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests