agent_ui: Replace stale draft thread when selected agent changes (#54023) (cherry-pick to preview)#54079
Closed
zed-zippy[bot] wants to merge 1 commit intov0.233.xfrom
Closed
agent_ui: Replace stale draft thread when selected agent changes (#54023) (cherry-pick to preview)#54079zed-zippy[bot] wants to merge 1 commit intov0.233.xfrom
zed-zippy[bot] wants to merge 1 commit intov0.233.xfrom
Conversation
) ## Problem When creating a new agent thread from the sidebar's **+** button (or via the `NewThread` / `NewThreadInGroup` actions), the panel always returned the cached draft thread — even if the user had since switched to a different agent. This meant the new thread would use the wrong agent (typically the default Zed Agent instead of the last-used external agent). The root cause was in `ensure_draft()`: it cached the draft and returned it unconditionally on subsequent calls without checking whether its agent matched the current `selected_agent`. Meanwhile, **cmd-n from within the agent panel** dispatched `NewExternalAgentThread`, which calls `create_thread()` — this always creates a fresh thread with the correct `selected_agent`, so it worked fine. ## Fix `ensure_draft()` now compares the cached draft's agent against the desired agent. When they differ and the draft's editor is empty, the stale draft is discarded and a new one is created with the correct agent. If the draft has user-typed content, it is preserved to avoid losing work. ## Test Added `test_draft_replaced_when_selected_agent_changes` which verifies: 1. A draft created with `NativeAgent` gets replaced when `selected_agent` changes to a custom agent 2. The replacement draft uses the correct agent 3. Calling `activate_draft` again with the same agent reuses the cached draft (no unnecessary replacement) The test fails without the fix (returns the stale `NativeAgent` draft) and passes with it. Release Notes: - N/A
18 tasks
eholk
added a commit
that referenced
this pull request
Apr 16, 2026
We're doing another preview release today to get our latest parallel agents features out there. This PR is a rollup of all the changes we need to cherry pick. - [x] 7a26e48 from #54081 - [x] #54066 - [x] #53992 - [x] #54079 - [x] #54057 - [x] #54056 - [x] #54052 - [x] #53999 - [x] #54009 - [x] #53539 (already cherry picked as 25e02cb) - [x] #54070 - [x] #54053 - fix `run_tests.yml`: 67e92b5 - [x] #53979 - [x] #53884 - [x] #54067 - [x] #54014 (already on branch) - [x] #54030 (already on branch) - [x] #54094 Release Notes: - N/A --------- Co-authored-by: Lukas Wirth <me@lukaswirth.dev> Co-authored-by: Bennet Bo Fenner <bennet@zed.dev> Co-authored-by: Nathan Sobo <nathan@zed.dev> Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com> Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de> Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Co-authored-by: Neel <neel@zed.dev> Co-authored-by: Richard Feldman <richard@zed.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #54023 to preview
Problem
When creating a new agent thread from the sidebar's + button (or via
the
NewThread/NewThreadInGroupactions), the panel always returnedthe cached draft thread — even if the user had since switched to a
different agent. This meant the new thread would use the wrong agent
(typically the default Zed Agent instead of the last-used external
agent).
The root cause was in
ensure_draft(): it cached the draft and returnedit unconditionally on subsequent calls without checking whether its
agent
matched the current
selected_agent.Meanwhile, cmd-n from within the agent panel dispatched
NewExternalAgentThread, which callscreate_thread()— this alwayscreates a fresh thread with the correct
selected_agent, so it workedfine.
Fix
ensure_draft()now compares the cached draft's agent against thedesired agent. When they differ and the draft's editor is empty, the
stale draft is discarded and a new one is created with the correct
agent.
If the draft has user-typed content, it is preserved to avoid losing
work.
Test
Added
test_draft_replaced_when_selected_agent_changeswhich verifies:NativeAgentgets replaced whenselected_agentchanges to a custom agent
activate_draftagain with the same agent reuses the cacheddraft (no unnecessary replacement)
The test fails without the fix (returns the stale
NativeAgentdraft)and passes with it.
Release Notes: