From 60da4460fbc38ad3ced669e59d7658bca8d76d30 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 9 Apr 2026 23:02:21 -0700 Subject: [PATCH] Constrain draft ID with a global instead of an atomic usize --- crates/agent_ui/src/agent_panel.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 2a77f2c5efa8c87d0e1e4eb85d7842725794be20..7b51d97941966509bd32406c135abd8607322c5c 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -56,7 +56,7 @@ use extension_host::ExtensionStore; use fs::Fs; use gpui::{ Action, Animation, AnimationExt, AnyElement, App, AsyncWindowContext, ClipboardItem, Corner, - DismissEvent, Entity, EntityId, EventEmitter, ExternalPaths, FocusHandle, Focusable, + DismissEvent, Entity, EntityId, EventEmitter, ExternalPaths, FocusHandle, Focusable, Global, KeyContext, Pixels, Subscription, Task, UpdateGlobal, WeakEntity, prelude::*, pulsating_between, }; @@ -594,15 +594,21 @@ fn build_conflicted_files_resolution_prompt( } /// Unique identifier for a sidebar draft thread. Not persisted across restarts. -/// IDs are globally unique across all AgentPanel instances. +/// IDs are globally unique across all AgentPanel instances within the same app. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct DraftId(pub usize); -static NEXT_DRAFT_ID: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); +#[derive(Default)] +struct DraftIdCounter(usize); + +impl Global for DraftIdCounter {} impl DraftId { - fn next() -> Self { - Self(NEXT_DRAFT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) + fn next(cx: &mut App) -> Self { + let counter = cx.default_global::(); + let id = counter.0; + counter.0 += 1; + Self(id) } } @@ -1324,7 +1330,7 @@ impl AgentPanel { /// Creates a new empty draft thread and stores it. Returns the DraftId. /// The draft is NOT activated — call `activate_draft` to show it. pub fn create_draft(&mut self, window: &mut Window, cx: &mut Context) -> DraftId { - let id = DraftId::next(); + let id = DraftId::next(cx); let workspace = self.workspace.clone(); let project = self.project.clone();