Skip to content

fix(coding-agent): count edit occurrences in the matched space - #1648

Closed
yuzhiyang1 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
yuzhiyang1:fix/edit-diff-occurrence-counting
Closed

fix(coding-agent): count edit occurrences in the matched space#1648
yuzhiyang1 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
yuzhiyang1:fix/edit-diff-occurrence-counting

Conversation

@yuzhiyang1

@yuzhiyang1 yuzhiyang1 commented Aug 22, 2026

Copy link
Copy Markdown

applyEditsToNormalizedContent matched oldText exactly (via fuzzyFindText's exact-match path) but always counted occurrences after normalizeForFuzzyMatch. If the file contained text that normalizes to the same string as oldText (e.g. both it’s and it's are present), a unique exact match was rejected with "Found 2 occurrences".

Occurrences are now counted in the same space the match was found in: exact matching counts in the original content, fuzzy matching counts in normalized content. Also avoids String.split("") blowups when oldText normalizes to an empty string.

Added unit tests covering: unique exact match not rejected by normalization collisions, fuzzy duplicates still rejected, and genuine exact duplicates still rejected.

Note

Fix edit tool to count occurrences in the matched space

Fixes duplicate-occurrence detection in applyEditsToNormalizedContent so it counts in the same space as the initial match. When the match used fuzzy normalization, both content and oldText are normalized before counting; otherwise exact substring counting is used on the original text. countOccurrences now returns 0 for empty oldText.

Risk: a fuzzy match that has multiple occurrences in normalized space will still be rejected, so edits relying on fuzzy matching against near-duplicate text may now fail where they previously succeeded.

Macroscope summarized 32c1a81.

@github-actions

Copy link
Copy Markdown

Hi @yuzhiyang1, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/PrimeIntellect-ai/prime-agent/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Aug 22, 2026
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