Repository navigation
perf(schemas): skip byte-identical raws in full-corpus schema-generate - #3589
Conversation
|
Warning Review limit reached
Next review available in: 27 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 Plus Run ID: 📒 Files selected for processing (3)
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 |
Problem: polylogue-el374 reported a real 30M-sample codex full-corpus schema-generate run degrading from ~28 units/s to ~1.0 units/s over the course of the run (~28x slowdown), not explained by the earlier ReplayableRecordSamples.__bool__ fix (#3546). Live profiling against the production archive (source.db, read-only) walking the real extract_record_samples_from_raw_content -> extract_schema_units_from_payload -> ObservationJournal.append_unit path showed the degradation is bursty, driven by hitting a small number of 50-540MB single-raw JSONL files (multiple seconds to stream-decode each, counted as one "unit"), not a monotonic accumulation bug. Of codex-session's 9155 raw_sessions rows (71.67GB), only 7378 have distinct blob_hash values: 1764 blob_hash values are shared by 2+ raw_ids, and keeping one raw_id per unique blob_hash reclaims 23.83GB (33.2% of codex's total bytes) with zero information loss, since byte-identical content produces byte-identical schema-inference output by construction. 19 of the 20 largest codex raws (400-540MB each) are exact-duplicate content of each other. Other origins show the same pattern at smaller scale (claude-code-session 13.4%, chatgpt-export 18.2%, claude-ai-export 38.0% of bytes are duplicate blob content). Checked and rejected filtering by revision_authority='quarantined' instead: only 1533 of 5203 quarantined codex raws (6.9GB of 49.1GB) have a resolved logical_source_key with a confirmed byte_proven sibling (provably-superseded duplicates); the remaining 3670 (42.2GB) simply have logical_source_key IS NULL, i.e. the column default for content the separately-tracked raw-authority-convergence backlog hasn't reconciled yet, not a proof of duplication. Filtering on that column would silently drop real, potentially schema-unique content. Solution: _iter_schema_units_from_db (polylogue/schemas/sampling_db.py) now tracks a per-run seen_blob_hashes set and skips any row whose blob_hash was already processed earlier in the same scan, recording an "intentionally_excluded" / "duplicate_blob_content" terminal outcome instead of decoding it again. This is independent of and orthogonal to revision_authority lineage reconciliation. Verification: added tests/unit/core/test_sampling.py::TestLoadSamplesFromDb::test_schema_observation_skips_duplicate_blob_content (two raw_sessions rows sharing one blob_hash -> exactly one SchemaUnit plus correct terminal outcomes for both rows). devtools test tests/unit/core/test_sampling.py: 42 passed, 1 pre-existing unrelated failure (test_schema_observation_records_included_and_decode_failed_raws, root-caused and filed separately as polylogue-kmqwm -- a test-isolation gap where iter_schema_units() falls through to scanning the real ~/.codex/sessions directory when DB content isn't schema-eligible; reproduces identically with this change reverted). devtools verify --quick: green. Ref polylogue-el374 Co-Authored-By: Claude <[email protected]>
…ow-up Ref polylogue-el374 Co-Authored-By: Claude <[email protected]>
0fa8d32 to
ceb028a
Compare
Summary
Fixes a real, measured cause of the ~28x units/s degradation reported in polylogue-el374 during a 30M-sample codex full-corpus schema-generate run:
_iter_schema_units_from_db(polylogue/schemas/sampling_db.py) had no dedup by content hash, so everyraw_idsharing ablob_hashwith an earlier row got independently re-decoded, including a handful of 400-540MB duplicate JSONL files.Problem
PR #3546 fixed a real class of redundant full-file rescans (the
ReplayableRecordSamples.__bool__fix), but that did not explain the production degradation. Live, read-only profiling against the production archive'ssource.db(never mutated), replaying the realextract_record_samples_from_raw_content -> extract_schema_units_from_payload -> ObservationJournal.append_unitpath used bycollect_cluster_analysis, showed the slowdown is bursty rather than monotonic: early raws are small (sub-30ms each), then the scan hits a run of 50-540MB single-file raws that each take multiple seconds to stream-decode while counting as one "unit" -- collapsing the units/s metric whenever the scan is inside one of these.Measured on the live archive: codex-session has 9155
raw_sessionsrows but only 7378 distinctblob_hashvalues -- 1764 hash values are shared by 2+raw_ids, and keeping oneraw_idper unique hash reclaims 23.83GB (33.2% of codex's 71.67GB total) with zero information loss, since byte-identical content produces byte-identical schema-inference output. 19 of the 20 largest codex raws (400-540MB each) are exact-duplicate content of each other. The same pattern holds at smaller scale for other origins (claude-code-session 13.4%, chatgpt-export 18.2%, claude-ai-export 38.0% of bytes are duplicate blob content).I also checked and rejected filtering by
revision_authority='quarantined'(the bead's original hypothesis, referencing prior findings from u19l). Of codex's 5203 quarantined raws (49.1GB), only 1533 (6.9GB) have a resolvedlogical_source_keywith a confirmedbyte_provensibling (provably-superseded duplicates) -- the remaining 3670 (42.2GB) simply havelogical_source_key IS NULL, i.e. the column default for content the separately-tracked raw-authority-convergence backlog (u19l/lb39z/hjpx/lkrc/t93b) hasn't reconciled yet, not proof of duplication. Filtering on that column would silently drop real, potentially schema-unique content. blob_hash-based dedup is strictly safer: a mathematical proof of identical content, independent of that lineage-reconciliation axis.Solution
_iter_schema_units_from_dbnow tracks a per-runseen_blob_hashes: set[bytes]and skips (recording anintentionally_excluded/duplicate_blob_contentterminal outcome, no decode work) any row whoseblob_hashwas already processed earlier in the same scan.Verification
tests/unit/core/test_sampling.py::TestLoadSamplesFromDb::test_schema_observation_skips_duplicate_blob_content: tworaw_sessionsrows sharing oneblob_hashproduce exactly oneSchemaUnitplus correct terminal outcomes for both rows.devtools test tests/unit/core/test_sampling.py: 42 passed. 1 pre-existing, unrelated failure (test_schema_observation_records_included_and_decode_failed_raws) reproduces identically with this change reverted -- root-caused and filed separately as polylogue-kmqwm (a test-isolation gap:iter_schema_units()falls through to scanning the real~/.codex/sessionsdirectory when DB content isn't schema-eligible).devtools verify --quick: green (also ran automatically via the pre-push hook).Ref polylogue-el374