## 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
1 file changedLine totals unavailable