Skip to content

agent: Fix edit file always failing when using DeepSeek v4 Pro - #55841

Closed
Alejandro-HUB wants to merge 3 commits into
zed-industries:mainfrom
Alejandro-HUB:#55398---edit_file-always-fails-when-using-DeepSeek-V4-Pro
Closed

agent: Fix edit file always failing when using DeepSeek v4 Pro#55841
Alejandro-HUB wants to merge 3 commits into
zed-industries:mainfrom
Alejandro-HUB:#55398---edit_file-always-fails-when-using-DeepSeek-V4-Pro

Conversation

@Alejandro-HUB

Copy link
Copy Markdown

Fix premature old_text finalization when model streams fields out of order

The streaming parser for the edit_file tool used new_text's
presence as a signal that old_text was complete, emitting it with
done: true. This fails when models stream JSON fields out of schema
order — specifically DeepSeek V4 Pro, which can emit new_text before
old_text has been fully received.

When this happens, old_text gets finalized as "" (the partial JSON
fixer closing an incomplete string), the real value arriving in later
chunks is silently ignored, and the fuzzy matcher finds no match.

The fix: only finalize old_text during streaming if actual content has
been emitted (old_text_emitted_len > 0) or the value is non-empty.
Empty old_text with new_text present is deferred to finalize_edits,
which has the complete data.

Release Notes:

  • Fixed edit_file tool failing with "Could not find matching text"
    when using DeepSeek V4 Pro

Closes #55398

@cla-bot

cla-bot Bot commented May 6, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @Alejandro-HUB on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label May 6, 2026
@Alejandro-HUB

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 6, 2026
@cla-bot

cla-bot Bot commented May 6, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@maxdeviant maxdeviant changed the title #55398 edit file always fails when using deep seek v4 pro agent: Fix edit file always failing when using DeepSeek v4 pro May 6, 2026
@maxdeviant maxdeviant changed the title agent: Fix edit file always failing when using DeepSeek v4 pro agent: Fix edit file always failing when using DeepSeek v4 Pro May 6, 2026
@SomeoneToIgnore SomeoneToIgnore added the area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features label May 6, 2026
…ile-always-fails-when-using-DeepSeek-V4-Pro
@benbrandt
benbrandt requested a review from bennetbo May 6, 2026 11:55
@bennetbo

bennetbo commented May 6, 2026

Copy link
Copy Markdown
Member

Hey, thanks for working on this and finding the cause of the issue. The code here does not work for the case where we receive both old_text and new_text in the same chunk. I made a PR to handle both cases (new_text appearing first, new_text appearing with old_text) here #55894, closing.

@bennetbo bennetbo closed this May 6, 2026
@Alejandro-HUB
Alejandro-HUB deleted the #55398---edit_file-always-fails-when-using-DeepSeek-V4-Pro branch May 6, 2026 18:58
@Alejandro-HUB

Copy link
Copy Markdown
Author

@bennetbo I see; I didn't consider the case where both are received in the same chunk. Excited to see your PR merged so that DeepSeek can operate as expected. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edit_file always fail with normal mode when using DeepSeek V4 Pro

3 participants