apply_patch rejects multiple update blocks for the same file, which openai models try to do a lot
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
- Copilot Chat Extension Version: uncertain, says "built-in" but is current with 1.132.0
- VS Code Version: 1.132.0
- OS Version: Windows 11 Home, build 26200 (10.0.26200)
- Feature: Agent/Edit mode (panel/editAgent), using apply_patch
- Selected model: gpt-5.6-luna
Logs: I don't want to share the jsonl which has extensive private information. But I asked Copilot to examine its own logs and give me a cleaned subset, which I'll paste below.
Steps to Reproduce:
Once or twice every day, an agent will stop and complain that `apply_patch` was rejected because of multiple same-named files. Something like this..
```
*** Begin Patch
*** Update File: example.md
@@
-old text
+new text
*** Update File: example.md
@@
-another old text
+another new text
*** End Patch
```
The tool returns:
```text
Applying patch failed with error:
Update File Error: Duplicate Path:
```
The edits succeed when additional prompting has them submitted as separate `apply_patch` calls.
I have not noticed this with Anthropic models but seems to happen a lot with OpenAI, especially 5.6 Luna (also Terra, though less so). I don't know how to force it for a repro.
Expected behavior:
Multiple update blocks for the same file should be accepted when their edit regions do not overlap.
The implementation could group blocks by file, validate overlapping regions, and apply the non-overlapping edits in patch order. Erroring out seems an unnecessary and overly conservative hard-fail. A warning would be a lot more friendly to LLMs unaware of the underlying rule.
If regions overlap or cannot be safely ordered, the tool should report a specific conflict instead.
Impact - this forces Copilot to:
- Make multiple tool calls for one file
- Produce larger, harder-to-review contiguous patches
- Retry after an avoidable validation failure
- Risk combining unrelated edits incorrectly
This is particularly common when editing Markdown files with several independent sections. Also, I have a standing rule that tells agents to stop if they encounter problems (I prefer less "exploratory" AI behaviors for much of my work) and so when this patch problem occurs it always stops the entire agent flow for me.
Contributor guide
Assessment
This issue has not been assessed yet.