Skip to content

fix(filesystem): apply LF edit_file text to CRLF files - #4933

Open
jaeminbird wants to merge 1 commit into
docker:mainfrom
jaeminbird:fix/edit-file-crlf
Open

jaeminbird wants to merge 1 commit into
docker:mainfrom
jaeminbird:fix/edit-file-crlf

Conversation

@jaeminbird

Copy link
Copy Markdown
Contributor

Git for Windows defaults to core.autocrlf=true, so checked-out files are CRLF. read_file returns them with \r\n, but models send LF-only oldText, so every multi-line edit_file fails with "old text not found" and the agent rewrites the whole file or gives up.

ApplyEdits now retries a missed edit with the file's CRLF endings, applied to oldText and newText together so the file stays CRLF. It only kicks in after an exact miss, when the file has CRLF and oldText has a newline and no CR; LF files and exact matches are unchanged, and the TUI preview uses the same path.

TestFilesystemTool_EditFileCRLF fails on main and passes here (4 controls); golangci-lint is clean.

Files checked out with CRLF (Git for Windows' default core.autocrlf) are
read back to the model with CRLF, but models send LF-only oldText, so
every multi-line edit failed with "old text not found". When oldText
isn't found, retry with the file's CRLF line endings, applied to oldText
and newText alike, so the edit applies and the file keeps CRLF. The
change is in ApplyEdits, so the TUI's edit preview matches what is
written.
@jaeminbird
jaeminbird requested a review from a team as a code owner November 14, 2026 03:27
Copilot AI balanced review requested due to automatic review settings November 14, 2026 03:27

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@aheritier aheritier added area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Nov 14, 2026

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

area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants