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.
14dd03e896Ben Brandt committed on 9/29/2026, 10:51:49 AM· committed by GitHubparent12f79c0
3 files changedLine totals unavailable