agent's patch applier broke with error on windows line endings in the model file
Teaches an agent to handle CRLF line endings when patching dbt model files by detecting them, normalizing for the edit, and preserving the original style. Use when patches fail on files with Windows line endings. Not for files with Unix endings.
TL;DR
The model file uses Windows (CRLF) line endings, and the patch applier expected Unix (LF), so context lines did not match. The agent should detect the line ending style, normalize to LF for patching, apply the edit, and convert back to CRLF to preserve the file's original style.
Error
agent's patch applier broke with error on windows line endings in the model fileSteps
- Detect the line endings: inspect the file for carriage returns. Expected: confirmed CRLF.
- Normalize a working copy to LF for the patch operation. Expected: the patch context matches.
- Apply the patch to the normalized copy. Expected: the edit applies cleanly.
- Convert the patched file back to CRLF. Expected: the original style is preserved.
- Verify the file (diff it, and run
dbt parseif it is a model or config). Expected: the edit is live and the file is valid.
When to use
- Patch application fails on files with CRLF line endings.
- Mixed-OS teams where some files have Windows endings.
When not to use
- Files with LF endings (patches apply normally).
- The patch itself is wrong (fix the patch content).
Tool compatibility
- Any patch tool; line-ending detection via file inspection.
Variant phrasings
Patch reports "context mismatch" on a Windows file
The invisible carriage returns are the mismatch; normalize first.
Git shows the whole file changed after an agent edit
Line-ending conversion without preservation; convert back to keep diffs minimal.
Why it happens
Patch context matching is byte-exact, and CRLF files have an extra byte per line that LF-authored patches lack. The mismatch is invisible in most editors, so the failure looks mysterious.
Edge cases
- Mixed line endings in one file are worse; normalize the whole file to one style and note it.
- Configure git's line-ending handling (
.gitattributes) so the repo has a declared standard. - Prefer normalizing the repo to LF once, with team agreement, over per-patch conversions forever.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_3McF7Sq-zuTq4jkZOiW98Q