agent_ui: Replace stale draft thread when selected agent changes - #54023
Merged
Merged
Conversation
ensure_draft() cached the draft thread and returned it on subsequent calls without checking whether its agent matched the current selected_agent. This meant that when a user switched to a different agent (e.g. via the toolbar menu or by navigating to a thread with a different agent), the sidebar's + button and NewThread action would still return the old draft with the wrong agent. Now ensure_draft() compares the cached draft's agent against the desired agent and discards the stale draft when they differ — unless the draft has user-typed content in the editor, in which case it is preserved to avoid losing work.
The test panicked on Linux CI with 'no state of type fs::GlobalFs exists' because the global Fs wasn't registered. This is needed when ensure_draft discards a stale draft and creates a new agent thread.
eholk
force-pushed
the
fix-default-external-agent-on-new-thread
branch
from
April 16, 2026 04:44
04d6564 to
5632216
Compare
Specify f32 literal suffixes for float arguments passed to taffy's length() and fr() functions. These implicit f64-to-f32 conversions are being phased out by rustc (rust-lang/rust#154024) and already cause hard errors on some nightly builds in the wasm target.
Member
|
@zed-industries/approved |
Contributor
|
🍒💥 Cherry-pick did not succeed |
Contributor
Author
|
/cherry-pick preview |
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 16, 2026
) ## 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
eholk
added a commit
that referenced
this pull request
Apr 16, 2026
) ## 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
G36maid
pushed a commit
to G36maid/zed
that referenced
this pull request
Apr 29, 2026
…-industries#54023) ## 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
kathbigra
pushed a commit
to kathbigra/zed
that referenced
this pull request
May 10, 2026
…-industries#54023) ## 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
Zenor27
pushed a commit
to Zenor27/zed
that referenced
this pull request
Jul 4, 2026
…-industries#54023) ## 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
jonx
pushed a commit
to jonx/zed-aros
that referenced
this pull request
Jul 17, 2026
…-industries#54023) ## 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
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
…-industries#54023) ## 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
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.
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: