fix: make DocumentCleaner pick repeated substrings deterministically #13967
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 312 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.344
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #13967"
general
weight: 0.35
1AbdullahButt
Related Issues
Proposed Changes:
With
remove_repeated_substrings=True,DocumentCleanerremoves the longest substring shared by the pages. When several shared substrings are equally long,max()over thesetof candidates returns whichever comes first in set iteration order, which depends on string hash randomization. So the same document can be cleaned differently in separate Python processes, and since the cleaned content changes, so does the document ID. Re-indexing the same files then gives different content and IDs, and duplicate checks miss them.Ties are now broken by the candidate's position in the first page, so the substring that appears first is removed every time. Behaviour is unchanged when there is a single longest candidate.
How did you test it?
New test
test_remove_repeated_substrings_breaks_ties_deterministically: eight equally long header candidates, and the one that appears first must be removed. Without the change it fails for all 10PYTHONHASHSEEDvalues I tried (0–9); with it, it passes for all of them.test/components/preprocessors/test_document_cleaner.pypasses (31 tests);ruff checkandruff format --checkare clean.Notes for the reviewer
The change is limited to the
max()key in_find_longest_common_ngram. The release note is kept to one line.This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.