Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent: Save threads before closing them (#51744)

Ben Brandt8a25373fb98b
diff --git a/crates/agent/src/agent.rs b/crates/agent/src/agent.rs
index d4062fec85c..140c872ecac 100644
--- a/crates/agent/src/agent.rs
+++ b/crates/agent/src/agent.rs
@@ -1429,15 +1429,16 @@ impl acp_thread::AgentConnection for NativeAgentConnection {
session_id: &acp::SessionId,
cx: &mut App,
) -> Task<Result<()>> {
- self.0.update(cx, |agent, _cx| {
- let project_id = agent.sessions.get(session_id).map(|s| s.project_id);
- agent.sessions.remove(session_id);
-
- if let Some(project_id) = project_id {
- let has_remaining = agent.sessions.values().any(|s| s.project_id == project_id);
- if !has_remaining {
- agent.projects.remove(&project_id);
- }
+ self.0.update(cx, |agent, cx| {
+ let Some(session) = agent.sessions.remove(session_id) else {
+ return;
+ };
+ let project_id = session.project_id;
+ agent.save_thread(session.thread, cx);
+
+ let has_remaining = agent.sessions.values().any(|s| s.project_id == project_id);
+ if !has_remaining {
+ agent.projects.remove(&project_id);
}
});
Task::ready(Ok(()))