From ec7d28648a84e7c375f61ebaa5175d78e577c05d Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Sat, 5 Apr 2025 09:34:23 -0300 Subject: [PATCH] agent: Fix thread summary generation (#28143) #28102 introduced a bug where thread summaries wouldn't get generated because they would get set to the default title instead of `None`. Not adding a release note because the bug didn't make it to Preview. Release Notes: - N/A --- crates/agent/src/thread.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index 2f49d5ad71..cd88c5e483 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -391,17 +391,20 @@ impl Thread { self.summary.clone().unwrap_or(Self::DEFAULT_SUMMARY) } - pub fn set_summary(&mut self, summary: impl Into, cx: &mut Context) { - let summary = summary.into(); - let old_summary = self.summary_or_default(); - - self.summary = if summary.is_empty() { - Some(Self::DEFAULT_SUMMARY) - } else { - Some(summary) + pub fn set_summary(&mut self, new_summary: impl Into, cx: &mut Context) { + let Some(current_summary) = &self.summary else { + // Don't allow setting summary until generated + return; }; - if Some(old_summary) != self.summary { + let mut new_summary = new_summary.into(); + + if new_summary.is_empty() { + new_summary = Self::DEFAULT_SUMMARY; + } + + if current_summary != &new_summary { + self.summary = Some(new_summary); cx.emit(ThreadEvent::SummaryChanged); } }