Repository navigation
perf(storage): enable guard-gated bulk FTS on daemon live-ingest and materialization paths - #3259
Conversation
…materialization paths Problem: #3152 (polylogue-crd8) built the byte-identical bulk-FTS guard for prefix-tail re-extraction but wired it only into the offline rebuild path, leaving daemon live ingest and repair_raw_materialization on per-row trigger mode out of conservatism. Live counterexample 2026-07-22: a whale session rewrite held the daemon writer >1h at 260GB of reads with zero commits (per-deleted-row action_pairs/delegation re-derivation — the meoz pathology on the write path). The t93b whale pass routes through the same backfill call and would detonate identically on its 6.33GB component. What changed: bulk_fts=True at the two daemon chokepoints — the live ingest write (_core.py) and the materialization backfill call (repair.py). Byte-identity is already proven by tests/unit/storage/ test_bulk_fts_prefix_reextract.py (mode-on vs mode-off equality, guard never leaks, anti-vacuity no-op-reinsert proof). Ref polylogue-crd8 Ref polylogue-t93b Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ
|
Warning Review limit reached
Next review available in: 10 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ 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: 205c9017bf
ℹ️ 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".
…guard
Problem: polylogue-v6i3 gated the blocks_command_trigram_{ai,ad,au}
trigger bodies on the same fts-bulk-session-write guard row the
messages_fts triggers use, but _bulk_fts_session_guard only performed
the explicit session-scoped delete/re-insert for messages_fts and its
identity ledger. With bulk_fts now enabled on daemon live paths, a
guarded prefix delete left stale external-content trigram postings for
the deleted blocks -- later trigram-driven LIKE queries raise
"fts5: missing row N from content table". (Codex review P1 on this PR.)
What changed: session-scoped trigram 'delete' (while the doomed rows
still exist -- external-content FTS5 needs the OLD text) at guard entry,
filtered to indexed rowids via the docsize shadow table, and a
session-scoped repopulate of surviving tool_use blocks in the finally.
Parity test now runs tool_use blocks through both modes and asserts
identical trigram content plus zero ghost postings; a dedicated
regression test fails with 1 ghost posting when the bracketing is
removed (verified).
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ
… aborting the batch Problem: the daemon's raw-authority frontier convergence calls inspect_quarantined_accepted_raws in chunks; its blob-budget check raised a batch-fatal RuntimeError when ANY target exceeded the 256 MiB per-target retained-blob limit. Live incident 2026-07-22 (first cycle after the #3259 deploy): one 298 MB codex whale raw (0a2517ba9224b6733...) aborted the ENTIRE frontier pass every cycle -- 42s of work, then error, nothing on the frontier converged. Same fail-closed-blocks-whales family as polylogue-t93b. What changed: _validate_quarantined_raw_repair_blob_budget becomes _partition_quarantined_raw_repair_blob_budget -- oversized targets come back as typed ineligible QuarantinedAcceptedRawRepairItems (reason names the byte counts), aggregate-budget overflow defers the tail of the batch with a retryable reason, and everything else proceeds to inspection. The memory-safety guarantee is unchanged: excluded targets are decided before any retained blob is loaded. inspect_quarantined_accepted_raws returns items in input order with excluded targets merged in. Ref polylogue-t93b (whale-convergence family), polylogue-yla8. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ
… aborting the batch (#3261) ## Summary The raw-authority frontier convergence pass no longer dies wholesale when a whale raw exceeds the quarantine-repair blob budget: oversized targets come back as typed ineligible items, aggregate overflow defers the batch tail, and every other target proceeds. ## Problem First convergence cycle after the #3259 deploy (2026-07-22 02:00:58, live journal): `RuntimeError: quarantined accepted raw repair exceeds the per-target retained-blob limit: 0a2517ba9224b6733…` — a single 298.4 MB codex raw (`codex:019d4eea-2068-7852-a2e4-4f4ce000abe7`) over the 256 MiB per-target cap. `inspect_quarantined_accepted_raws` validated the whole chunk with a batch-fatal raise, so `_converge_raw_authority_frontier` burned ~42s and aborted every cycle; nothing on the frontier could converge. Same fail-closed-blocks-whales family as polylogue-t93b (operator ruling: whales must converge through the daemon). ## Solution - `polylogue/storage/repair.py`: `_validate_quarantined_raw_repair_blob_budget` → `_partition_quarantined_raw_repair_blob_budget`, returning `(inspectable, excluded)` where excluded entries are typed `QuarantinedAcceptedRawRepairItem`s (`ineligible`, reason with byte counts; aggregate overflow → retryable `deferred:` reason). Memory-safety guarantee unchanged: exclusion is decided before any blob load. `inspect_quarantined_accepted_raws` merges excluded items back in input order. - `polylogue/storage/raw_reconciler.py`: the apply-side (`REFINE_QUARANTINE`, single authorized target) stays fail-closed — budget refusal raises there, since an authorized plan must not silently skip. The oversized whale target itself remains unrepaired-by-this-path by design; its escalation route is the t93b whale-pass family. ## Verification - `devtools test tests/unit/storage/test_quarantine_repair_budget.py` — 4 passed (oversized→typed-ineligible, aggregate-overflow→deferred tail, in-budget→all inspectable, missing-row passthrough). - `devtools verify --quick` — exit 0 (pre-push hook; mypy caught and drove the reconciler apply-side adaptation). Ref polylogue-t93b, polylogue-yla8. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Quarantined raw-data repair now continues processing eligible items when individual records exceed repair limits. * Oversized or deferred records are clearly reported as ineligible instead of causing the entire inspection to fail. * Repair processing preserves the original item order and provides specific deferral reasons. * **Tests** * Added coverage for per-record limits, aggregate budget overflow, fully eligible batches, and missing records. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Fable 5 <[email protected]>
…guard Problem (CodeRabbit #3263 P1): CREATE TRIGGER IF NOT EXISTS never replaces an existing same-name trigger, so an archive last rebuilt before the blocks_command_trigram_ad guard clause landed (#3259) keeps its old, ungated body forever -- reopening the archive does not upgrade it. delete_sessions's explicit trigram pre-delete plus its FTS_BULK_SESSION_WRITE_GUARD row assumed that guard is always honored; on such an archive the old trigger fires anyway during the block cascade and reissues an FTS5 'delete' command for a posting the explicit pre-delete already removed, which raises "database disk image is malformed" and rolls back the whole batch. Reproduced directly: a downgraded trigger (this PR's new test fixture) makes the pre-fix code fail with exactly that error. What changed: delete_sessions checks once, cheaply, whether the live blocks_command_trigram_ad trigger's sqlite_master SQL actually references derived_refresh_guard. When it does not, the method skips its own explicit trigram pre-delete and the FTS_BULK_SESSION_WRITE_GUARD row entirely, letting that same (ungated) trigger clean up trigram rows per-block during the cascade -- exactly the behavior this method had before the guard-gated optimization existed, so it stays correct (if unoptimized for trigram specifically) until the archive's next rebuild picks up the current trigger DDL. No schema-version bump needed: this is a runtime capability check, not a data migration. Verification: devtools test tests/unit/storage/test_bulk_delete_guarded.py (3 passed, including the new pre-guard-archive regression, confirmed to reproduce the exact reported error against the pre-fix code); devtools verify --quick (pass). Co-Authored-By: Claude <[email protected]>
…ntenance instead of per-row trigger detonation (#3263) ## Summary `ArchiveStore.delete_sessions` (the product bulk-delete API used by the CLI `delete` verb and `SessionDeleteActuator`) now wraps its whole batch in the same `derived_refresh_guard` rows the bulk session-write path already uses, and performs the derived FTS/trigram/action_pairs/delegation_facts maintenance explicitly, one pass, instead of relying on unsuppressed per-row triggers. ## Problem `delete_sessions` issued a plain per-session `DELETE FROM sessions`. `blocks_action_pairs_ad` (`storage/sqlite/archive_tiers/index.py`) fires once per deleted `blocks` row — both the explicit block cascade and the FK `ON DELETE CASCADE` from `messages`/`sessions` still invoke AFTER DELETE triggers per row — and each firing deletes+rebuilds the **entire session's** `action_pairs` via two window-function scans and re-derives `delegation_facts`. Live incident 2026-07-21: deleting 91 sessions ran 3h, 375GB reads, zero commit, before being killed. The bulk session-write path already suppresses this class of cost via `derived_refresh_guard` rows (`'session-write'`, `'fts-bulk-session-write'`), see `_bulk_fts_session_guard` in `write.py` (bead polylogue-crd8's fix for the analogous whale-lineage-prefix-delete stall). `delete_sessions` never set either guard. ## Solution `ArchiveStore.delete_sessions` (`polylogue/storage/sqlite/archive_tiers/archive.py`): 1. For each session id, explicit session-scoped deletes run first, while the `blocks` rows still exist (external-content FTS5 needs the OLD text to locate its postings): `messages_fts` / `messages_fts_identity` (`delete_session_rows_sql` / `delete_session_identity_rows_sql`) and `blocks_command_trigram` (`trigram_delete_session_rows_sql`, landed in #3259). 2. Both `derived_refresh_guard` rows are set for the whole batch — `'session-write'` (suppresses `blocks_action_pairs_a{i,d,u}` and the `delegation_facts` triggers) and `'fts-bulk-session-write'` (suppresses the `messages_fts`/`blocks_command_trigram` trigger bodies — redundant here since those rows are already gone by step 1, kept for guard-contract parity and defense-in-depth). 3. `action_pairs` and `delegation_facts` are explicitly cleared by session id — belt-and-suspenders alongside the `ON DELETE CASCADE` FKs those tables already carry against `sessions`/`blocks`; this keeps the post-condition legible without depending on cascade-ordering. 4. `DELETE FROM sessions` per id relies on indexed FK cascades (not per-row trigger logic) for physical `messages`/`blocks` tree removal; guard rows are cleared and the transaction commits once for the whole batch. This mirrors `_bulk_fts_session_guard`'s delete-then-guard-then-mutate shape. **Epoch triggers audit** (per bead's ask): `query_unit_frame_{sessions, messages,blocks}_delete` fire per deleted row, ungated by either guard. Left deliberately ungated — each firing is a single primary-key `UPDATE query_unit_frame_state SET epoch = epoch + 1 WHERE singleton = 1` against a one-row table (O(1) per row), not a window-function rebuild, so this was never implicated by the incident and folding a third guard in for a zero-measured cost isn't warranted. **Async path** (`repository/archive/writes/sessions.py` -> `delete_session_via_backend` -> `queries/sessions_writes.py`'s `delete_session_sql`): unaffected by this fix and left unchanged. It deletes **exactly one session per call/transaction** — there is no loop batching N session ids into a single transaction, so the "91 sessions in one transaction" incident shape does not reproduce there. (A single very-large session could still see a bounded version of the same per-block trigger cost for its own row count — that's the pre-existing, already-tracked crd8 concern for whale *writes*, not a bulk-*delete* regression, and out of this bead's scope.) ## Verification - `devtools test tests/unit/storage/test_bulk_delete_guarded.py tests/unit/storage/test_bulk_fts_prefix_reextract.py` -> `9 passed` - **Anti-vacuity proof**: `sqlite3.Connection.set_trace_callback` was tried first and rejected — it only reports the outer statement text (`DELETE FROM sessions ...`), never SQL executed *inside* a trigger body (verified empirically against a minimal repro). Instead, the new `test_delete_sessions_bulk_never_fires_unguarded_per_row_canary` installs canary triggers on `blocks` carrying the **exact same WHEN-clause guard conditions** as the real `blocks_action_pairs_ad` / `blocks_command_trigram_ad` triggers. With the fix reverted (`git stash` on `archive.py` only, canary test re-run), the canaries fire `{'session_write': 14, 'fts_bulk': 6}` for 2 sessions x 3 tool pairs each — i.e. the per-row rebuild machinery *would* have detonated. With the fix restored, both counts are `0`. What would make this test fail: removing or narrowing the scope of either `INSERT OR REPLACE INTO derived_refresh_guard(...)` call this PR adds. - `devtools verify --quick` -> `exit_code: 0` (ruff format/check, mypy --strict, `render all --check`, topology/layering/manifests/doc-commands/ docs-coverage/test-clock-hygiene/pytest-timeout-overrides/degrade-loudly) - `tests/unit/storage/test_archive_tiers_archive.py::test_exact_session_action_count_bounds_pairing_before_global_ranking` fails identically with the fix reverted (`git stash` on `archive.py` only) — confirmed pre-existing and unrelated to this change, not touched by this PR. - Not run: full `devtools verify --all` / broad directory pytest (repo convention is testmon-affected + focused files, not blanket runs). Ref polylogue-meoz. Relates to polylogue-crd8 (same `derived_refresh_guard` mechanism, different write path — whale prefix-delete during ingest vs. bulk session delete via the product API). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[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. |
|
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
Turns on the #3152 guard-gated bulk-FTS mode (byte-identical by its parity suite) at the two daemon chokepoints that still ran per-row trigger mode: the live ingest write and the raw-materialization backfill (which the t93b whale pass uses).
Problem
Live incident 2026-07-22: the freshly deployed daemon's writer sat >1 hour on one whale-session prefix-tail rewrite — 260 GB read, zero commits, zero log lines — because every deleted row fired the full action_pairs + delegation_facts re-derivation (same pathology family as polylogue-meoz, but on the WRITE path). The crd8 close had recorded "live path stays per-row by design (bounded per-session writes)" — this session is the live counterexample; whale sessions exist on the live path.
Solution
bulk_fts=Trueat_core.py'swrite_parsed_session_to_archivecall andrepair.py'sbackfill_historical_revision_evidencecall, with incident comments. No mechanism changes — the guard, parity proofs, and threading all exist since #3152.Verification
devtools test tests/unit/storage/test_bulk_fts_prefix_reextract.py→ 6 passed (the byte-identity + guard-never-leaks + anti-vacuity suite).devtools test tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_no_string_interpolated_sql.py→ 7 passed.devtools verify --quick→ exit 0.Ref polylogue-crd8
Ref polylogue-t93b
🤖 Generated with Claude Code
https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ