fix: cap max passage length to prevent cascading window merges#67
Merged
Conversation
Post-classification validation showed context extraction producing 3,037-char average passages (10x prior runs) due to cascading window merges in large entries. Long passages cause proximity-based classifiers (corrective, decisive) to degrade to random co-occurrence. Adds max_passage_sentences config (default 6) that splits over-long merged ranges at sentence boundaries, with per-chunk term re-evaluation. Review Agent fixes applied: - W-1: Pre-compute lowercased sentences in collect_terms_in_range (perf) - W-2: Document triggering_terms re-evaluation semantics - N-1: Simplify cap=0 guard to .max(1) - N-2: Remove dead dedup() call - N-3: Add debug_assert for chunk bounds
There was a problem hiding this comment.
Pull request overview
Adds a configurable cap on extracted passage length (in sentences) to prevent oversized merged windows, keeping passage granularity aligned with classifier calibration.
Changes:
- Introduces
max_passage_sentencesonExtractionConfig(default6). - Splits merged extraction ranges into sentence-boundary chunks when they exceed the cap.
- Re-evaluates
triggering_termsper split chunk and drops chunks with no matching terms; adds tests for the new behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
C1: Document chunk discard behavior and context_window interaction C2: Restore dedup() in collect_terms_in_range for defensive duplicate handling C3: Expand debug_assert to check start bounds and start <= end invariant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
max_passage_sentencestoExtractionConfig(default: 6)Context
Post-classification validation (#49) showed passage length explosion (309 → 3,037 chars avg) causing corrective (19% → 42.5%) and decisive (2% → 17.5%) false positive spikes. The classifiers are calibrated for ~300-char passages — this fix restores that granularity.
Review
Test plan
extract_over_cap_splits_into_multiple_passages)extract_cap_zero_emits_single_sentence_passages)extract_split_re_evaluates_triggering_terms_per_chunk)extract_split_discards_chunks_without_matching_terms)