You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
apply_patch deletes the final blank line of files that end with one #42081
apply_patch deletes the final blank line of any file whose content ends with \n\n, even when the patch doesn't touch that line. The tool's own response confirms the unrequested change: it reports 2 deletions for a patch that asked for 1, and repeated edits keep eating one trailing newline each time.
Root cause: derive() in packages/core/src/patch.ts:71-81 uses the same test ("last array element is empty") for two different things. On the way in it pops the sentinel empty string produced by split("\n"); on the way out it checks updated.at(-1) !== "" to decide whether to push the sentinel back. When the file's last line is genuinely blank, the last element is still "" after popping, so the sentinel is never restored and one \n is lost. The legacy implementation has the same flaw (packages/opencode/src/patch/index.ts:314-327, under the comment "Ensure trailing newline").
Only LF files are affected (a CRLF file's last split element is "\r", not ""). Not the same as #37090 (CRLF→LF conversion) or #29124 (about adding a newline to files that lack one).
Disclosure: found and reproduced with AI assistance; I reviewed and verified every claim locally.
Activity
github-actions commentedon Oct 13, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.