Skip to content

perf(schemas): skip byte-identical raws in full-corpus schema-generate - #3589

Merged
Sinity merged 2 commits into
masterfrom
feature/perf/dedup-blob-hash-schema-generate
Aug 2, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/perf/dedup-blob-hash-schema-generate

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

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 every raw_id sharing a blob_hash with 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's source.db (never mutated), replaying the real extract_record_samples_from_raw_content -> extract_schema_units_from_payload -> ObservationJournal.append_unit path used by collect_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_sessions rows but only 7378 distinct blob_hash values -- 1764 hash values are shared by 2+ raw_ids, and keeping one raw_id per 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 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 (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_db now tracks a per-run seen_blob_hashes: set[bytes] and skips (recording an intentionally_excluded / duplicate_blob_content terminal outcome, no decode work) any row whose blob_hash was already processed earlier in the same scan.

Verification

  • Added tests/unit/core/test_sampling.py::TestLoadSamplesFromDb::test_schema_observation_skips_duplicate_blob_content: two raw_sessions rows sharing one blob_hash produce 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) 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/sessions directory when DB content isn't schema-eligible).
  • devtools verify --quick: green (also ran automatically via the pre-push hook).

Ref polylogue-el374

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b5ed7c5a-a214-4805-a58d-1c561fc086c5

📥 Commits

Reviewing files that changed from the base of the PR and between f7dfef4 and ceb028a.

📒 Files selected for processing (3)
  • .beads/issues.jsonl
  • polylogue/schemas/sampling_db.py
  • tests/unit/core/test_sampling.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sinity and others added 2 commits August 2, 2026 23:06
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]>
@Sinity
Sinity force-pushed the feature/perf/dedup-blob-hash-schema-generate branch from 0fa8d32 to ceb028a Compare August 2, 2026 21:09
@Sinity
Sinity merged commit 13d1336 into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/perf/dedup-blob-hash-schema-generate branch August 2, 2026 21:12
Sinity added a commit that referenced this pull request Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant