mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-02 13:30:26 +01:00
agent_ui: Persist the most recently selected agent, not whichever write finishes last (#61147)
# Objective `test_select_agent_action_updates_visible_draft` (added in #60452) is order-dependent: it passes at seed 0, which CI runs, but fails on others (e.g. 7, 11). Any unrelated change that schedules one extra task shifts the deterministic test scheduler enough to flip it at seed 0 too — which is how it surfaced, while working on #61009. The bug it exposes is real and pre-existing (same class as #61142): `set_selected_agent_and_persist` fires a detached write of the global last-used agent each time it's called. Activating the draft persists the default agent while selecting one persists the choice, and with several writes in flight the one that finishes last wins — so the default can clobber the user's selection, which then loses it on the next launch. ## Solution Chain the writes so they land in call order and the most recent selection is the one left persisted. ## Testing - `test_select_agent_action_updates_visible_draft` now runs 30 seeds to cover both orderings. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed the agent panel occasionally forgetting the selected agent --------- Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
This commit is contained in:
@@ -1174,6 +1174,7 @@ pub struct AgentPanel {
|
||||
_project_subscription: Subscription,
|
||||
zoomed: bool,
|
||||
pending_serialization: Option<Task<Result<()>>>,
|
||||
persist_selected_agent_task: Task<()>,
|
||||
new_user_onboarding: Entity<AgentPanelOnboarding>,
|
||||
new_user_onboarding_upsell_dismissed: AtomicBool,
|
||||
selected_agent: Agent,
|
||||
@@ -1567,6 +1568,7 @@ impl AgentPanel {
|
||||
focus_handle: cx.focus_handle(),
|
||||
context_server_registry,
|
||||
draft_thread: None,
|
||||
persist_selected_agent_task: Task::ready(()),
|
||||
retained_threads: HashMap::default(),
|
||||
terminals: HashMap::default(),
|
||||
pending_terminal_spawn: None,
|
||||
@@ -1927,13 +1929,12 @@ impl AgentPanel {
|
||||
self.serialize(cx);
|
||||
}
|
||||
|
||||
cx.background_spawn({
|
||||
self.persist_selected_agent_task = cx.background_spawn({
|
||||
let kvp = KeyValueStore::global(cx);
|
||||
async move {
|
||||
write_global_last_used_agent(kvp, agent).await;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
});
|
||||
}
|
||||
|
||||
/// Sets the panel's selected agent without opening the panel or focusing
|
||||
@@ -11499,7 +11500,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
#[gpui::test(iterations = 25)]
|
||||
async fn test_select_agent_action_updates_visible_draft(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
let fs = FakeFs::new(cx.executor());
|
||||
|
||||
Reference in New Issue
Block a user