History

assistant panel: Fix pending completions not being cleaned up (#16201)

Turns out that you could always cancel a completion, even if it was already done and completed, because it was never cleaned up. Release Notes: - N/A

Thorsten Ball committed 2 years ago

Commit b7dcd4e1 parent 8b8335f1 file · +4 −3Browse files

Unified · Split

crates/assistant/src/context.rs+4−3
@@ -1713,6 +1713,8 @@ impl Context { · 1712 unmodified lines
1713 .insert_message_after(assistant_message.id, Role::User, MessageStatus::Done, cx)1713 .insert_message_after(assistant_message.id, Role::User, MessageStatus::Done, cx)
1714 .unwrap();1714 .unwrap();
1715 1715
1716 let pending_completion_id = post_inc(&mut self.completion_count);
1717
1716 let task = cx.spawn({1718 let task = cx.spawn({
1717 |this, mut cx| async move {1719 |this, mut cx| async move {
1718 let stream = model.stream_completion(request, &cx);1720 let stream = model.stream_completion(request, &cx);
@@ -1761,10 +1763,9 @@ impl Context { · 42 unmodified lines
1761 })?;1763 })?;
1762 smol::future::yield_now().await;1764 smol::future::yield_now().await;
1763 }1765 }
1764
1765 this.update(&mut cx, |this, cx| {1766 this.update(&mut cx, |this, cx| {
1766 this.pending_completions1767 this.pending_completions
1767 .retain(|completion| completion.id != this.completion_count);1768 .retain(|completion| completion.id != pending_completion_id);
1768 this.summarize(false, cx);1769 this.summarize(false, cx);
1769 })?;1770 })?;
1770 1771
@@ -1806,7 +1807,7 @@ impl Context { · 35 unmodified lines
1806 });1807 });
1807 1808
1808 self.pending_completions.push(PendingCompletion {1809 self.pending_completions.push(PendingCompletion {
1809 id: post_inc(&mut self.completion_count),1810 id: pending_completion_id,
1810 assistant_message_id: assistant_message.id,1811 assistant_message_id: assistant_message.id,
1811 _task: task,1812 _task: task,
1812 });1813 });