Skip to content

fix: allow patch format to create new files - #5911

Open
zhzjzz wants to merge 1 commit into
Aider-AI:mainfrom
zhzjzz:fix/patch-add-file-5875
Open

zhzjzz wants to merge 1 commit into
Aider-AI:mainfrom
zhzjzz:fix/patch-add-file-5875

Conversation

@zhzjzz

@zhzjzz zhzjzz commented Oct 26, 2026

Copy link
Copy Markdown

With --edit-format patch, an approved *** Add File currently leaves an empty file and fails with ADD Error: File already exists: the shared preparation step creates the file before PatchCoder checks for an existing target.

Track the approved ADD placeholders for each batch and allow the patch to fill them while they remain empty. Existing files, including empty files, are still rejected before preparation; permission is consumed on application and reset for the next batch. ADD dry-runs also avoid creating parent directories.

Add 15 regression tests covering the complete Coder.run() flow with a mocked response, Git staging, declined and ignored targets, existing-file protection, intervening writes, batch cleanup, direct application, normalized paths, and nested dry-runs.

Fixes #5875.

Validation on Windows with Python 3.12:

  • The full-run regression fails on the original code with the reported empty-file symptom and passes with this fix.
  • python -m pytest tests/basic/test_patch.py tests/basic/test_coder.py tests/basic/test_editblock.py -q — 82 passed, 35 subtests passed.
  • The issue's original litellm mock_response reproduction creates the expected file content without a real model request or API key.
  • python -m pre_commit run --files aider/coders/patch_coder.py tests/basic/test_patch.py — isort, black, flake8, and codespell passed.
  • git diff --check passed.

Track approved ADD placeholders during edit preparation so the patch coder can write their contents while preserving existing files. Avoid creating ADD directories during dry-run and cover the full run flow and lifecycle boundaries. Fixes Aider-AI#5875.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Hou KangLe seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: patch edit format cannot create new files: *** Add File fails with "File already exists" and leaves an empty file

2 participants