Skip to content

fix(core): preserve CRLF in patch updates - #56128

Open
Parker-Fawcett wants to merge 3 commits into
anomalyco:devfrom
Parker-Fawcett:patch-crlf
Open

Parker-Fawcett wants to merge 3 commits into
anomalyco:devfrom
Parker-Fawcett:patch-crlf

Conversation

@Parker-Fawcett

@Parker-Fawcett Parker-Fawcett commented Oct 16, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #54605

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Preserve CRLF when the patch tool updates a uniformly CRLF file. Patch.derive uses the source newline for splitting and joining, and terminates trailing blank lines so they survive reconstruction. LF and mixed-ending files retain their existing behavior.

How did you verify your code works?

  • Both patch suites: 95 tests, 1,900 passes across randomized/repeated runs and a run alongside the full Core suite. Three trailing-blank-line regressions fail on the previous PR commit and pass now.
  • ACP permission tests: 5 pass. Formatting and bun run check pass, including lint and all 35 typechecks.
  • Full Core: 6,632 pass, 43 skip, 7 fail. The seven shell failures match those reproduced on the untouched baseline with system Bash 3.2.57.

Screenshots / recordings

N/A — file content behavior.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the bug. I reproduced #54605 end to end with a simulated model calling the patch tool on a CRLF file. On the base, the patched lines came back as LF and the untouched line stayed CRLF. With this PR, every line stays CRLF. The new tests pass, and the six CRLF derive cases and the CRLF+BOM move test fail on the base. packages/util type-checks.

The public API is unchanged: this only changes what Patch.derive writes.

I found nothing blocking. The patch parser already strips \r from hunk lines, so splitting on \r\n can't produce a doubled \r, and context matching still works. Files with mixed line endings behave as before, so patched lines there are still written as LF; that's a reasonable scope for this fix. The nine-case test.each table is more than a 6-line fix needs. A CRLF replacement, a CRLF file with no final newline, and the unchanged LF and mixed-file cases would cover it, and the other cases could be dropped.

Fixes #45926

Before

After

This branch has not been deployed

No deployments
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.

Opencode v2: Tool Patch messes up line endings in Windows

1 participant