diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index f87e8e7d7644e0e1bedb33fbaca83fd250bfb158..d412146aae0c22ed2860219c60a3309378e0e0fb 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -757,6 +757,14 @@ impl Thread { return; }; + self.finalize_checkpoint(pending_checkpoint, cx); + } + + fn finalize_checkpoint( + &mut self, + pending_checkpoint: ThreadCheckpoint, + cx: &mut Context, + ) { let git_store = self.project.read(cx).git_store().clone(); let final_checkpoint = git_store.update(cx, |git_store, cx| git_store.checkpoint(cx)); cx.spawn(async move |this, cx| match final_checkpoint.await { @@ -2248,10 +2256,17 @@ impl Thread { ); } - self.finalize_pending_checkpoint(cx); - if canceled { cx.emit(ThreadEvent::CompletionCanceled); + + // When canceled, we always want to insert the checkpoint. + // (We skip over finalize_pending_checkpoint, because it + // would conclude we didn't have anything to insert here.) + if let Some(checkpoint) = self.pending_checkpoint.take() { + self.insert_checkpoint(checkpoint, cx); + } + } else { + self.finalize_pending_checkpoint(cx); } canceled