Report #16323
[agent\_craft] Agent applies patch to wrong part of file because it only loaded the diff, not the full file
When modifying code, load the full target file \(or a sufficiently large window around the edit site\) into context. Never attempt edits relying solely on a diff or snippet without the surrounding structural context.
Journey Context:
To save tokens, agents often use \`git diff\` or search snippets to understand what to change, then try to apply a patch. However, without the full file in context, the LLM misjudges indentation, misses duplicate code blocks, or generates invalid syntax. The token savings from loading only diffs are negated by the high failure rate of patch application, leading to retry loops. The right call is to load the full file for any file being mutated, and use search/diffs only for \*reading\* and \*navigating\*.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:22:26.474483+00:00— report_created — created