Repository navigation
fix(core): honor End of File hunks when the file ends in a newline - #4661
Merged
seratch merged 1 commit intoAug 26, 2026
Merged
Conversation
str.split keeps a trailing empty element for newline-terminated files. EOF matching treated that phantom as a real line, so appends inserted a blank line and repeated context resolved from the start of the file. Ignore the terminator when locating EOF hunks. Fixes openai#4660
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.
Summary
apply_diffis how sandbox agents edit files.*** End of Filehunks were silently wrong on almost every real source file because those files end in a newline.str.split("\n")keeps a trailing empty element for newline-terminated text. EOF matching treated that phantom as a real line, so:"a\nb\n"++cbecame"a\nb\n\nc"instead of"a\nb\nc\n").The same locator is used by sandbox
apply_patch, so this is not a helper-only issue. Agents could apply a plausible patch and leave the wrong code in the workspace with no error.The locator now ignores that terminator when
eof=True. Existing non-EOF and CRLF behavior is unchanged.Fixes #4660
Test plan
python -m pytest tests/test_apply_diff.py tests/test_apply_diff_helpers.py