# agent: Handle out of order old_text/new_text in edit file tool \(\#55894\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/42017bcad2631b6bafef52942899b4989d2c0c72)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 42017bcad2631b6bafef52942899b4989d2c0c72

Requested commit: 42017bcad2631b6bafef52942899b4989d2c0c72

Commit: 42017bcad2631b6bafef52942899b4989d2c0c72

Tree: f6c85a7c7492b6e19f731610f1e4fdbc08bd73ed

Author: Bennet Bo Fenner

Committer: GitHub

## Message

```
agent: Handle out of order old_text/new_text in edit file tool (#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 #55398

Release Notes:

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

## Parents

- [7fcc4ba3438e3ea8a2d1c436090a88fc8c853b6c](https://git.cafe/gitcafe/zed/commit/7fcc4ba3438e3ea8a2d1c436090a88fc8c853b6c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/42017bcad2631b6bafef52942899b4989d2c0c72?format=markdown)
