# agent_ui: Guard follow-up sends from stale send results \(\#64917\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 14dd03e89676e7fe74bc205001bfb32c8cfc3952

Requested commit: 14dd03e89676e7fe74bc205001bfb32c8cfc3952

Commit: 14dd03e89676e7fe74bc205001bfb32c8cfc3952

Tree: bf9fbd1d831ec62babdbcd2a2986a62e2e57755f

Author: Ben Brandt

Committer: GitHub

## Message

```
agent_ui: Guard follow-up sends from stale send results (#64917)

Keep an older agent send's response from mutating the UI state of a
newer started turn.

After cancel/send, the old RPC response may still be outstanding. The
core already guards its own turn completion, but the view previously
cleared `in_flight_prompt` on every successful response and displayed
every returned error, even when a successor was running.

- Apply prompt cleanup, following-state refresh, and response errors
inside one view update guarded by the existing turn generation.
- Clear the previous displayed error again at actual turn start. This
covers an old error arriving while the successor's contents are still
resolving, without starting turn timing early.
- Preserve current-send error visibility, prompt recovery,
generation-protected timer cleanup, and per-send completion telemetry.
Superseded failures are debug-logged rather than shown on the newer
turn.
- Add a test-only controlled prompt-response gate and one regression
covering late success/error, deferred preparation, current success/error
cleanup, and timer ownership.

The guarantee starts when the successor reaches `start_turn`.
Cancellation alone does not invalidate the view generation; an old error
can appear while successor content is preparing, but cannot carry into
that new turn.

Release Notes:

- agent: Fixed stale agent responses clearing a newer prompt or showing
errors from an earlier send.
```

## Parents

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

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