Repository navigation
perf(sources): parse byte-identical raw rows once per (blob_hash, source_path) - #3151
Conversation
…rce_path) Problem: 17% of the live archive's newest-only bytes (8.7GB of 52.1GB) are byte-identical duplicate blobs stored under multiple raw rows — e.g. one 442MB codex rollout acquired 8 times within 2.3 seconds during an acquisition stampede (8 raw rows, same blob_hash, same source_path) — and census parsed every row independently, paying the full decode for identical bytes each time. The blob store already dedups storage by hash; the parse layer did not. What changed: _parse_retained_raws groups its batch by (blob_hash, source_path), parses one representative per group through the existing sequential/pool machinery (_parse_unique_retained_raws), and fans the outcome out to duplicate rows with each row's own revision_kind re-attached from its descriptor. source_path stays in the dedup key deliberately: some parsers derive identity from the path (e.g. beads workspace-scoped native ids), so cross-path duplicates of the same bytes still parse separately. Exceptions fan out to all rows of the failed group. Verification: devtools test tests/unit/sources/test_revision_backfill.py (29 passed). New tests: dedup grouping with per-row revision_kind fan-out + cross-path isolation, and exception fan-out. Anti-vacuity via patch-revert (not stash — refs/stash is shared across worktrees): both fail on pre-fix code. devtools verify --quick exit 0. Current write_raw_payload is idempotent for identical (payload, path) — verified by probe — so new stampedes cannot recreate the shape; this covers the historical rows. Ref polylogue-869u Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 13 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 (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 |
… by blob_hash (#3234) ## Summary Two fixes in the revision-authority census area, sharing the raw-materialization footprint: - **polylogue-52l2**: stop an isolated later-discovered raw from silently becoming the permanently accepted content for a logical identity that already has known ambiguous/quarantined siblings. - **polylogue-869u**: dedup census parse by `blob_hash` across `source_path` for providers whose parse identity is byte-content-only, avoiding redundant full parses of byte-identical duplicate blobs. ## Problem ### polylogue-52l2 `classify_raw_revision_cohort` classifies a byte-prefix chain from whichever `raw_sessions` rows currently carry `revision_kind='full'` for a `logical_source_key` — not against the complete sibling population for that identity. Retiring an ambiguous sibling to membership governance (`replace_raw_membership_census(..., retire_full_revision_governance=True)`, what the backfill/live-watcher callers do once a cohort is decided ambiguous) nulls that raw's `raw_sessions.logical_source_key`, so it disappears from the query. A THIRD raw for the same identity, discovered afterward (e.g. a re-acquired browser-capture snapshot), is then evaluated completely alone: `classify_historical_full_revision_streams` unconditionally accepts a one-member stream as a byte-proven baseline (no sibling to prove a byte prefix against), so the isolated raw permanently becomes the accepted session content — an outcome that depends on incremental discovery order, not on which content is actually correct. Reproduced directly against `ArchiveStore` (`tests/unit/storage/test_revision_replay.py`), mirroring the live incremental watcher's own call sequence (`sources/live/batch.py`: `bind_raw_revision` then `classify_raw_revision_cohort`, no census-phase re-derivation in between). The equivalent two-call scenario through `backfill_historical_revision_evidence` does NOT reproduce: its census phase unconditionally re-parses every still-unindexed raw and its connected-component selection expansion reunites retired siblings by shared membership evidence before classification runs — protections the live incremental path lacks. This class of bug is closely related to (but distinct from) the head-collision fixes in #3204/#3205/#3211 that landed in the last 48h; those addressed head-handoff precedence and cohort absorption for an *already-established* head, not this isolated-singleton acceptance path. ### polylogue-869u Live evidence (2026-07-19, `source.db`): the newest-revision-per-`logical_source_key` population is 87,177 rows / 52.1 GiB, but only 85,066 DISTINCT `blob_hash` values / 43.4 GiB — the same bytes (e.g. one 442MB codex computer-use rollout) recur under up to 8 different `logical_source_key`s / source paths, from re-acquisition or re-export. The existing dedup (#3151, `_parse_retained_raws`) only collapses rows sharing BOTH `blob_hash` AND `source_path`, so this whole cross-path duplicate population — 8.7GB / 17% of newest-only bytes — still paid a full parse per row. ## Solution ### polylogue-52l2 (`polylogue/storage/sqlite/archive_tiers/archive.py`, `polylogue/sources/revision_backfill.py`, `polylogue/sources/live/batch.py`, `polylogue/archive/revision_authority.py`) - New `ArchiveStore.raw_membership_retired_full_revision_siblings()`: finds `raw_session_memberships` rows for a `logical_source_key` whose `raw_membership_census.detail` matches the (now shared) `HISTORICAL_NON_PREFIX_GOVERNANCE_DETAIL` marker written at retirement — survives the `raw_sessions.logical_source_key` NULL-out. - `classify_raw_revision_cohort` refuses the byte-chain path entirely whenever this identity has retired sibling evidence, so the caller's existing "no accepted chain" fallback (`convertible_full_revision_raw_ids`) folds the newly-discovered raw into membership governance instead, where the real prefix-based classifier weighs every known sibling together, rather than silently establishing a wrong permanent head. - Unified the two `retire_full_revision_governance` call sites' previously-divergent detail strings onto one shared constant so the guard recognizes retirement from either path. - **Deferred** (named, not hidden): once an identity's retired siblings are recognized, nothing in the LIVE incremental watcher path (unlike offline backfill) currently re-unites them with the new raw for a real membership decision — it fails closed instead (logs a warning, surfaces as failed), correctly never establishing wrong content, but requiring a later offline backfill/repair pass to resolve the identity fully. Also out of scope: PR #3204 already tracks a known, separate limitation (a content-ahead capture yielding to a byte-kind chain head) as polylogue-nfl5. ### polylogue-869u (`polylogue/sources/revision_backfill.py`) `_parse_retained_raws`' grouping key now drops `source_path` for a new `_PATH_INDEPENDENT_PARSE_PROVIDERS` allowlist (ChatGPT, Claude web/Code, Codex, Gemini/Gemini CLI, Grok, Drive) — those parsers derive session identity purely from payload bytes. Providers whose parse DOES depend on `source_path` keep the original `(blob_hash, source_path)` key: Beads derives workspace-scoped native ids from `source_path`, Antigravity's brain-metadata mode and Hermes' ATOF/ATIF/verification-evidence modes derive `profile_root` from `source_path`. `Provider.UNKNOWN` stays path-scoped out of caution. ## Verification - `devtools test tests/unit/storage/test_revision_replay.py tests/unit/sources/test_revision_backfill.py tests/unit/storage/test_raw_retention.py tests/property/test_sql_injection_boundary.py` → 160 passed. - New regression `test_isolated_later_raw_does_not_override_known_ambiguous_cohort` fails on unmodified master (asserts `accepted_raw_ids == ()` but gets the isolated raw's id) and passes after the 52l2 fix. - `mypy --strict` clean on all four touched modules. - `devtools verify --quick` → exit 0. - **Dedup receipt (869u)**: synthetic corpus of 40 distinct ~300KB Codex payloads, each duplicated across 5 different source paths (200 raw rows, mirroring the live re-acquisition-stampede shape), measured via real `_parse_retained_raw` invocation counts: - before (`blob_hash`+`source_path` key): 200 parse calls, 0.516s wall clock - after (`blob_hash` key, safe providers): 40 parse calls, 0.104s wall clock - 160 avoided parse calls (80% reduction on this corpus). Note: the task brief also asked to run `tests/unit/storage/test_no_string_interpolated_sql.py` explicitly after any `archive.py` edit. That file does not exist in this repo (grepped for "interpolated" and "hardcoded.*line" repo-wide, no match) — ran `tests/property/test_sql_injection_boundary.py` as the closest existing analog instead (40 passed). ## AC matrix **polylogue-52l2** - Isolated-singleton acceptance over a known-ambiguous cohort: **satisfied** — guarded in `classify_raw_revision_cohort`, proven by a failing-then-passing regression test. - Cross-tick reunification of retired siblings with a new raw in the LIVE incremental path: **deferred** — currently fails closed (no wrong content, but no automatic resolution either); needs a follow-up to fold retired-but-known siblings back into a real membership decision at the live-watcher call site, analogous to what offline backfill already does via `convertible_full_revision_raw_ids`. - Direct-seed order-reversal for `source_outage_interval_events`/`capture_gap_events` (bead's "related, separately-confirmed finding"): **not addressed** — out of this PR's footprint (`_write_parsed_precedence_result` in the excluded `archive_tiers/write.py`); still needs its own investigation pass as the bead notes. **polylogue-869u** - Byte-identical blobs parsed at most once per parser fingerprint, per identity-relevant path scope: **satisfied** for the `_PATH_INDEPENDENT_PARSE_PROVIDERS` allowlist; path-dependent providers (Beads/Antigravity/Hermes/Unknown) intentionally keep path-scoped dedup. - Measured corpus receipt with parse-call counts and wall-clock before/after: **satisfied** — see Verification above. - No identity regression for source_path-dependent parsers, test covers the Beads workspace case: **satisfied** — `test_parse_retained_raws_preserves_path_scoped_dedup_for_path_dependent_providers`. Ref polylogue-52l2, polylogue-869u Co-Authored-By: Claude <[email protected]> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved handling of historical revision governance during archive classification and replay. * Enhanced retained-data processing to safely deduplicate identical content across paths where supported. * **Bug Fixes** * Prevented later isolated revisions from overriding previously identified ambiguous revision groups. * Preserved path-specific handling for providers whose results depend on source paths. * **Tests** * Added coverage for cross-path deduplication and ambiguous revision classification scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <[email protected]>
…3494) ## Summary Two beads, one branch: (1) a P1 correctness-of-contract bug fix — a resumable rebuild pass's deadline is now checked *between* REPLAY-phase cohorts, not only after the whole page's replay call returns — and (2) the small remaining slice of a P2 observability bead, a durable "selection phase" timing on every rebuild receipt. ## Problem **polylogue-uhgm** (P1): live recovery evidence — operation `3f8fa7b0` configured `pass_deadline_ms=300000` (5 minutes), yet 100-row pages ran roughly 8-9 minutes, because `rebuild_index_from_source` (`maintenance/rebuild_index.py`) checked elapsed time only *after* `replay_source(...)` — the whole page's census + every cohort + planner-stats refresh — returned. A page can also expand into a much larger authority cohort, making the overshoot unbounded in the worst case. The advertised bounded-pass contract was not enforced at the work boundary. **polylogue-6mvg** (P2, remaining slice): a live full index rebuild spent ~86s of one CPU core selecting which raws to replay before the inactive generation held a single session, and nothing durable recorded where that time went. Most of this bead's original scope (planner stats #3141, byte-skip #3146, batched commits #3147, pool floor #3149, dedup #3151) had already shipped via sibling beads; the bead's own notes call out durable phase-timing telemetry — specifically a selection-phase breakdown — as the one still-unowned piece. ## Solution - `polylogue/sources/revision_backfill.py`: `backfill_historical_revision_evidence` gains an optional `deadline_check: Callable[[], None] | None` parameter, called at the top of every REPLAY-phase cohort iteration (both the byte-cohort and membership-cohort loops) — between cohorts, not only after the whole call returns. New `RebuildDeadlineExceededError` is the expected interrupt signal. - `polylogue/maintenance/replay.py`: threads `deadline_check` through unchanged to `backfill_historical_revision_evidence`. - `polylogue/maintenance/rebuild_index.py`: - Builds a `_check_pass_deadline` closure from the resumable transaction's `pass_deadline_ms`, wired only when a durable transaction exists (never for non-resumable `--raw-id`/`--only-missing`/`--max-blob-mb` selections, matching existing validation). - Catches `RebuildDeadlineExceededError` around the `replay_source()` call. On interrupt it deliberately does **not** advance the transaction's cursor/processed counters — the next pass re-derives from the exact same source-order position, safe by the existing content-hash idempotency invariant (re-applying an already-committed cohort is a no-op upsert, never a duplicate) and consistent with the crash-recovery contract an open replay batch already has. - The deferred receipt's `replay` dict is zero-shaped like a normal replay dict (not a bare marker), so every existing consumer that indexes replay-dict keys unconditionally (the daemon-mode CLI text formatter, the daemon HTTP route's raw `receipt.to_dict()` response) keeps working. - `RebuildPassCost.selection_s` (polylogue-6mvg) extends the *existing* timings vocabulary — the same `RebuildPassCost`/`timings_s` shape every other phase (`parse_s`/`apply_s`, the `terminal.*` stages from polylogue-o56w) already uses — rather than inventing a parallel one. Measured around `next_raw_page` (resumable path) and `select_rebuild_raw_ids` (one-shot path), threaded into all three receipt-building call sites (deadline-interrupt, deferred/paused post-hoc, final materialized). **Alternatives rejected:** proactive page-sizing against a throughput estimate (checks only *before* a page starts, so still misses a mid-page-expanding cohort — the exact worst case the bead names) and per-raw interruption inside `apply_raw_revision_replay` itself (would interrupt mid-transaction-write, risking corruption of the owned-inactive- generation state). Both were flagged and deliberately deferred in the bead's own prior investigation as too risky for the intended scope. ## Conflict avoidance note for the merge conductor `polylogue/sources/revision_backfill.py` is flagged as owned by another live lane. This PR's addition there is the smallest possible: one new exception class, one new optional parameter, and two `if deadline_check is not None: deadline_check()` call sites at the top of the two existing cohort loops — no other line touched. The branch was rebased onto current `master` (`90d4df67e`, which includes the sibling lane's `polylogue-5q2u` lineage-order replay change, `_lineage_aware_replay_order`); the rebase conflict was exactly the loop header line and was resolved by keeping the new `ordered_logical_keys` iteration and re-adding the `deadline_check()` call — verified with a fresh test run post-rebase. ## Acceptance-criteria matrix **polylogue-uhgm:** - "A transaction with a short pass deadline stops before starting work that would exceed its remaining budget, commits a valid cursor, and reports deadline deferral." — **Satisfied.** `test_rebuild_index_deadline_stops_mid_page_and_resumes_without_omission_or_duplication`. - "Restarting resumes exactly at the next source-order raw/cohort with no duplicates or omissions." — **Satisfied** (by construction: the cursor is never advanced on interrupt, and resumption re-derives from the identical keyset position; idempotent re-application makes any redone cohort safe). Proven end-to-end by the same test (interrupted pass → resume → exact final session count). - "A deliberately slow/expanded cohort proves the deadline is checked inside production replay work rather than only after the outer call returns." — **Satisfied.** `test_deadline_check_invoked_between_replay_cohorts_not_only_after_return` proves the interrupt fires after exactly one cohort durably commits (not zero, not all three) at the direct `backfill_historical_revision_evidence` boundary. - "Final terminal readiness checks remain exact and either have their own bounded receipt or are explicitly separately scheduled." — **Unchanged**: no terminal-stage code was touched; `terminal.*` timings (polylogue-o56w) remain as before. **polylogue-6mvg** (remaining slice only — full bead AC already satisfied by sibling beads per its own 2026-07-19/27 notes): - Durable selection-phase timing receipt — **Satisfied.** `RebuildPassCost.selection_s` / `terminal_timings_s["selection_s"]`, present on every receipt shape (deferred, paused, replayed). - Cohort/parse/write/insight phase timings — **Already delivered** by prior work (`stage_timings_s` from `revision_backfill.py`, `parse_s`/`apply_s` split, `terminal.*` stages) — not re-touched here. - Daemon catch-up shares the improvement — **Satisfied by construction**: `daemon/bulk_rebuild.py`'s `run_daemon_bulk_rebuild_pass` returns the exact same `RebuildIndexReceipt` from the same `rebuild_index_from_source_sync` engine, so both the deadline fix and the selection-phase timing apply automatically with zero daemon-side changes needed. ## Anti-vacuity - Deadline fix: production caller is `rebuild_index_from_source_sync` (the real offline/daemon rebuild engine, no reimplementation). The mutation that makes `test_deadline_check_invoked_between_replay_cohorts_not_only_after_return` fail is moving the `deadline_check()` calls out of the cohort loops back to a single call after `backfill_historical_revision_evidence` returns (the pre-fix bug shape) — the mock would then never be called before the function's own natural completion. The mutation that makes `test_rebuild_index_deadline_stops_mid_page_and_resumes_without_omission_or_duplication` fail is either reverting to the post-hoc-only check (the fake clock would never interrupt anything mid-replay, so the first pass would report `status="replayed"` instead of `"deferred"`) or advancing the transaction's cursor on interrupt (the resumed pass would then skip or duplicate a raw, and the final session count would not equal 3). - Phase timing: production caller is the same `rebuild_index_from_source_sync`. The mutation that makes `test_rebuild_index_phase_timing.py`'s two tests fail is reverting `selection_elapsed_s`'s measurement or its `selection_s=selection_elapsed_s` threading — the `"selection_s"` key would then be absent from `receipt.timings_s` (a dict-key assertion failure, not merely a zero value). ## Verification ``` python -m devtools test tests/unit/maintenance/test_rebuild_index_deadline.py \ tests/unit/maintenance/test_rebuild_index_phase_timing.py \ tests/unit/daemon/test_bulk_rebuild_ownership.py \ tests/unit/cli/test_archive_maintenance_cli.py \ tests/unit/daemon/test_route_contracts.py \ tests/unit/maintenance/test_rebuild_index_bulk_build.py \ tests/unit/maintenance/test_rebuild_index_ownership.py \ tests/unit/maintenance/test_rebuild_index_selection.py \ tests/unit/maintenance/test_rebuild_parse_apply_split.py \ tests/unit/storage/test_index_generation.py # 212 passed python -m devtools verify --quick # exit_code: 0, all 18 steps ok ``` **Known pre-existing failure, unrelated to this branch** — filed as `polylogue-s0ug`: `tests/unit/storage/test_incremental_rebuild_equivalence.py::test_incremental_restart_and_fresh_generation_rebuild_are_equivalent` fails deterministically on current `origin/master` (`90d4df67e`) in isolation, introduced by `0d27e3da7` (#3484, tightened Codex CONTINUATION lineage evidence) landing after this branch was cut — the test's hand-built fixture predates that tightening. `git diff origin/master...HEAD` for this branch touches neither `codex.py`, `revision_backfill.py`'s classification logic, nor that test file, confirming it is not caused by this change. Not run: `devtools verify` (full testmon suite) — the coordinator directed a synchronous quick-gate + focused-test path instead of the backgrounded testmon seed, since a fresh worktree has no testmon seed to run the default affected-selection path against. Ref polylogue-uhgm Ref polylogue-6mvg Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
_parse_retained_rawsnow groups its batch by(blob_hash, source_path), parses one representative per group, and fans the outcome out to duplicate rows (with each row's ownrevision_kindre-attached). Byte-identical raw rows — 17% of the live archive's newest-only bytes — stop paying repeated full parses.Problem
Live evidence (2026-07-19, source.db): newest-revision-per-logical-key = 87,177 rows / 52.1GB, but only 85,066 distinct
blob_hashes / 43.4GB — 8.7GB of parse work is byte-identical duplicates. Worst case: one 442MB codex rollout acquired 8 times within 2.3 seconds (acquisition stampede; 8 raw rows, same blob, same path), each row fully parsed by census. The blob store dedups storage by hash; the parse layer did not.Solution
_parse_retained_rawsbecomes a dedup wrapper: group by(blob_hash, source_path), delegate representatives to_parse_unique_retained_raws(the previous body, unchanged sequential/pool logic including the perf(sources): sequential parse below aggregate pool floor, stop worker churn #3149 amortization floor), fan out outcomes.source_pathstays in the key deliberately — some parsers derive identity from the path (beads workspace-scoped native ids), so cross-path duplicates of the same bytes still parse separately. Exceptions fan out to every row of the failed group.write_raw_payloadis idempotent for identical (payload, path) — verified by probe — so new stampedes can't recreate the shape; this covers the historical rows and any future writer regression.Verification
devtools test tests/unit/sources/test_revision_backfill.py— 29 passed.test_parse_retained_raws_dedupes_identical_blob_and_path(parse-call sequence is exactly one per distinct (blob, path); duplicate rows get their ownrevision_kind; different path with same bytes still parses) andtest_parse_retained_raws_fans_out_exceptions_to_duplicate_rows. Anti-vacuity via patch-revert of the implementation file (notgit stash—refs/stashis shared across worktrees): both fail on pre-fix code (2 failed).devtools verify --quick— exit 0.Ref polylogue-869u
🤖 Generated with Claude Code
https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ