fix(citations): honor the errs tolerance cap in CitationMixin fuzzy span matching - #2463
Closed
lntutor wants to merge 1 commit into
Closed
fix(citations): honor the errs tolerance cap in CitationMixin fuzzy span matching#2463lntutor wants to merge 1 commit into
lntutor wants to merge 1 commit into
Conversation
…atching _get_span escalates the allowed regex edit distance in a loop whose guard (errs_ <= errs) is checked before the increment, so it runs one extra search at e<=errs+1. A substring_quote up to 6 edits from any source span (one beyond the default errs=5 cap) is therefore accepted and silently rewritten to that unrelated context substring, instead of being dropped as not-found -- weakening the citation verification the mixin exists to provide. Change the guard to errs_ < errs so the final search runs at exactly e<=errs; quotes within errs edits still match. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
Collaborator
|
Consolidated and shipped in #2495. Closing this focused patch as superseded; thank you for the contribution. |
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.
What's broken
CitationMixin._get_spanescalates the allowed regex edit distance in a loop whose guard is evaluated before the increment:When
errs_ == errs(5) the body runs once more, bumpingerrs_to 6 and searching with{e<=6}. So the effective fuzzy tolerance iserrs + 1 = 6— a hallucinatedsubstring_quotethat is 6 edits from any real source span is accepted and silently rewritten to that unrelated context substring, instead of being dropped as "not found":This weakens the citation verification the mixin exists to provide.
Fix
Change the guard to
errs_ < errsso the final search runs at exactly{e<=errs}. Quotes withinerrsedits still match.Tests
Adds
tests/dsl/test_citation.py(within-tolerance matches; beyond-tolerance dropped). The existing citation coverage intests/coverage/test_dsl_small_coverage.py— which relies on a legitimate 1-edit match — stays green (16). Distinct from #2430 (regex-escape crash), which leaves the loop bound untouched.