Skip to content

Collapse repeated comments and enforce document size limits - #5

Merged
Llewellynvdm merged 1 commit into
mainfrom
claude/large-files-git-storage-d01nud
Aug 12, 2026
Merged

Collapse repeated comments and enforce document size limits#5
Llewellynvdm merged 1 commit into
mainfrom
claude/large-files-git-storage-d01nud

Conversation

@Llewellynvdm

@Llewellynvdm Llewellynvdm commented Aug 12, 2026

Copy link
Copy Markdown
Member

Summary

This change optimizes commentary storage by deduplicating comments attached to verse ranges and adds safeguards to prevent oversized documents from being published. SWORD commentaries attach a single comment to a verse range but report it once per verse in that range, leading to massive duplication. The fix stores each distinct comment once, anchored at the lowest verse it covers, with a verses array listing all verses it applies to.

Key Changes

  • Comment deduplication: Refactored _chapter_entries() to collapse identical comments across verse ranges into a single entry with a verses array, reducing storage by 9-10x for typical commentaries
  • Document size enforcement: Added enforce_document_ceiling() utility that fails the build immediately when a generated document exceeds configurable limits (default 95 MB), preventing rejected pushes hours later
  • Schema simplification: Removed redundant name and anchor object fields from commentary entries; osis is now a direct property. Updated schema to reflect the new verses field and document the deduplication behavior
  • Storage metrics: Added comprehensive storage block to metadata tracking source vs. published entry counts, byte sizes at each level, and repetition_ratio to measure deduplication effectiveness
  • CLI and config: Added --max-document-bytes flag to control the ceiling (0 disables), with environment variable override support
  • Test coverage: Added tests validating range comment collapse, distinct comment preservation, chapter boundary handling, reference union across ranges, and document size limit enforcement
  • Validation: Enhanced build validation to ensure no text repeats within a chapter and entries are anchored at their lowest verse

Implementation Details

  • The collapse groups comments by text content within chapter boundaries, preserving chapter document independence
  • References from repeated comments are unioned so a range carrying different references across verses keeps all of them
  • write_composed_json() now returns the written document size for ceiling enforcement
  • Both CommentaryWriter and DictionaryWriter accept max_document_bytes parameter
  • Build pipeline collects storage metrics into the report for visibility into module sizes and deduplication ratios

A SWORD commentary attaches one comment to a verse range, and the extractor
reports that same text once for every verse in the range. Writing an entry per
verse stored the identical paragraph dozens of times: an exposition of a psalm
reappeared under all 176 verses of Psalm 119, and the whole-commentary documents
reached 481 MB for Matthew Henry and 306 MB for FreAug without carrying any more
text than the source held. That is what the publication push was rejected for.

Each distinct comment is now published once, anchored at the lowest verse it
covers, with `verses` listing every verse it applies to when that is more than
one. Nothing is dropped: every verse the source commented on still resolves to
its comment, and resolving one is a single rule -- an entry covers `verses` when
that member is present and `verse` alone when it is not. Grouping stops at the
chapter boundary so a chapter document still stands alone, and references from
every verse in a range are unioned onto the published entry rather than taken
from whichever verse happened to be seen first.

Entries also lose `name` and `anchor`. Both only restated values already present
on the entry or its chapter: `name` was the book name with `chapter:verse`, and
`anchor` repeated `book`, `chapter`, and `verse` verbatim. `osis` stays, as a
plain member, because it is the source module's own key rather than a restatement.

The build now measures itself instead of leaving this to be guessed at.
metadata.json carries a `storage` block reporting source against published bytes,
the repetition ratio the collapse removed, and what each of the three levels
costs; the build report collects the same per module, so a CI run reports it.

No generated document may exceed --max-document-bytes, 95 MB by default and just
under the 100 MB a Git remote refuses. The build now fails naming the offending
file rather than producing a tree that is rejected at push time hours later.
@Llewellynvdm
Llewellynvdm merged commit e226642 into main Aug 12, 2026
14 of 15 checks passed
@Llewellynvdm
Llewellynvdm deleted the claude/large-files-git-storage-d01nud branch August 12, 2026 09:15
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