## 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

```text
agent's patch applier broke with error on windows line endings in the model file
```

## Steps

1. Detect the line endings: inspect the file for carriage returns. Expected: confirmed CRLF.
2. Normalize a working copy to LF for the patch operation. Expected: the patch context matches.
3. Apply the patch to the normalized copy. Expected: the edit applies cleanly.
4. Convert the patched file back to CRLF. Expected: the original style is preserved.
5. Verify the file (diff it, and run `dbt parse` if 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
