From d7ff91760f969d4e9fa84323ed88900c3309263e Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:03:24 +0800 Subject: [PATCH] fix(agents): Keep a deleted task from being saved again A save that ran after delete (from the turn ending or the agent exiting) wrote the task file back, so the task returned on the next load. Deleting now marks the task under the lock that saving holds. --- crates/ide-agent/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ide-agent/src/lib.rs b/crates/ide-agent/src/lib.rs index c62073bf..c276076f 100644 --- a/crates/ide-agent/src/lib.rs +++ b/crates/ide-agent/src/lib.rs @@ -191,6 +191,8 @@ struct Task { dirty: Mutex>, flush_scheduled: AtomicBool, stderr: Mutex>, + /// Set by `delete`; held while saving, so a late save can't bring the file back. + deleted: Mutex, } impl AgentManager { @@ -519,6 +521,7 @@ impl AgentManager { blocking(move || worktree::remove(&root, &cwd)).await?; } self.tasks.write().remove(id); + *task.deleted.lock() = true; let _ = std::fs::remove_file(self.shared.paths.store_dir.join(format!("{id}.json"))); self.shared.emit(AgentEvent::Removed { id: id.to_owned() }); Ok(()) @@ -568,6 +571,7 @@ impl Task { dirty: Mutex::new(BTreeSet::new()), flush_scheduled: AtomicBool::new(false), stderr: Mutex::new(VecDeque::new()), + deleted: Mutex::new(false), }) } @@ -604,6 +608,10 @@ impl Task { }) }; let path = self.shared.paths.store_dir.join(format!("{}.json", self.id)); + let deleted = self.deleted.lock(); + if *deleted { + return; + } if let Err(e) = bytes.map_err(|e| e.to_string()).and_then(|b| write_file(&path, &b)) { tracing::warn!("saving agent task {}: {e}", self.id); }