Skip to content

agent: Handle out of order old_text/new_text in edit file tool - #55894

Merged
bennetbo merged 13 commits into
mainfrom
edit-tool-fix-out-of-order-new-old-text
May 7, 2026
Merged

agent: Handle out of order old_text/new_text in edit file tool#55894
bennetbo merged 13 commits into
mainfrom
edit-tool-fix-out-of-order-new-old-text

Conversation

@bennetbo

@bennetbo bennetbo commented May 6, 2026

Copy link
Copy Markdown
Member

In the case where the model would respond with new_text before old_text, we would just emit an empty old_text, because the parsing layer was operating under the assumption that old_text occurs before new_text.

We now hold back new text chunks if we receive them first, and only emit them once old_text is complete.

In addition to that we also need to handle the case where the first chunk contains old_text and new_text. In that case we don't know which one of the two fields have finished streaming, since we can't rely on the ordering anymore. Therefore we hold back all events until we receive the full edit, and emit a single OldTextChunk (done = true) and a single NewTextChunk (done = true)

Closes #55398

Release Notes:

  • agent: Fixed an issue where editing would sometimes fail for specific models (Deepseek v4)

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 6, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label May 6, 2026
@bennetbo
bennetbo marked this pull request as draft May 6, 2026 15:47
@bennetbo
bennetbo marked this pull request as ready for review May 6, 2026 17:59
@bennetbo
bennetbo requested a review from benbrandt May 6, 2026 18:05
@bennetbo
bennetbo added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit 42017bc May 7, 2026
32 checks passed
@bennetbo
bennetbo deleted the edit-tool-fix-out-of-order-new-old-text branch May 7, 2026 09:02
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…ndustries#55894)

In the case where the model would respond with `new_text` before
`old_text`, we would just emit an empty `old_text`, because the parsing
layer was operating under the assumption that `old_text` occurs before
`new_text`.

We now hold back new text chunks if we receive them first, and only emit
them once old_text is complete.

In addition to that we also need to handle the case where the first
chunk contains `old_text` and `new_text`. In that case we don't know
which one of the two fields have finished streaming, since we can't rely
on the ordering anymore. Therefore we hold back all events until we
receive the full edit, and emit a single OldTextChunk (done = true) and
a single NewTextChunk (done = true)

Closes zed-industries#55398

Release Notes:

- agent: Fixed an issue where editing would sometimes fail for specific
models (Deepseek v4)
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…ndustries#55894)

In the case where the model would respond with `new_text` before
`old_text`, we would just emit an empty `old_text`, because the parsing
layer was operating under the assumption that `old_text` occurs before
`new_text`.

We now hold back new text chunks if we receive them first, and only emit
them once old_text is complete.

In addition to that we also need to handle the case where the first
chunk contains `old_text` and `new_text`. In that case we don't know
which one of the two fields have finished streaming, since we can't rely
on the ordering anymore. Therefore we hold back all events until we
receive the full edit, and emit a single OldTextChunk (done = true) and
a single NewTextChunk (done = true)

Closes zed-industries#55398

Release Notes:

- agent: Fixed an issue where editing would sometimes fail for specific
models (Deepseek v4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

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

2 participants