Repository navigation
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found:
This appears to be addressing the same issue as PR #32216. Both PRs are fixing Unicode normalization in the apply_patch function to handle canonically-equivalent characters (NFC vs NFD). PR #31847 likely predates PR #32216 and may already be addressing the same root cause. You should check the state of PR #31847 to see if it's been merged or if PR #32216 should be based on that work. |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Summary
apply_patchfails withFailed to find expected lines in <file>when the file on disk and the model's context lines are canonically-equivalent Unicode but different byte sequences (NFC vs NFD). None of the 4 existingseekSequencepasses handle combining-character equivalence, so any NFD content on disk is permanently unpatchable — the model re-reads, retries, fails, and burns tokens in a loop.Root cause
seekSequence(packages/opencode/src/patch/index.ts) had 4 passes:normalizeUnicode+ trim — butnormalizeUnicodeonly maps smart quotes / dashes / ellipsis / NBSP; it never normalizes combining characters.A file with decomposed
й(иU+0438 + U+0306) can never match a patch containing precomposedй(U+0439), even though the strings are canonically equivalent. Models essentially always emit NFC.Fix
A 5th pass after pass 4 that normalizes both sides to NFC before comparing:
This is safe: NFC normalization followed by exact equality only matches strings Unicode defines as the same text — no false positives. (Approach proposed by the issue reporter.)
Test plan
й), and a negative case (no false match)packages/opencodepatch suite: 23/23 passpatch/index.ts(the only typecheck error ondevis a pre-existing, unrelated one insrc/bus/global.ts)Fixes #31651