← Back to Pull requests

fix: make DocumentCleaner pick repeated substrings deterministically #13967

Open
unknown opened this pull request with 312 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 27, 2026 10:18 UTC
Author

Related Issues

  • No existing issue; found while cleaning PDFs whose pages share several header lines of the same length.
  • Proposed Changes:

    With remove_repeated_substrings=True, DocumentCleaner removes the longest substring shared by the pages. When several shared substrings are equally long, max() over the set of 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 10 PYTHONHASHSEED values I tried (0–9); with it, it passes for all of them. test/components/preprocessors/test_document_cleaner.py passes (31 tests); ruff check and ruff format --check are 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

  • I have read the contributors guidelines and the code of conduct.

  • I have updated the related issue with new insights and changes.

  • I have added unit tests and updated the docstrings.

  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.

  • I have documented my code.

  • I have added a release note file, following the contributors guidelines.

  • I have run pre-commit hooks and fixed any issue.
  • Diff: 312 lines (+234 / -78) across 3 files Reviewer: 1AbdullahButt Review duration: 1248m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.3% (MEDIUM) · Higher = larger blast radius
    40.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.5% · Safe to merge
    21.5%