Skip to content

Commit 86d260a

Browse files
committed
Fix stopping a prompt corruping other cases of chat
1 parent 4801084 commit 86d260a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix stopping a prompt corruping other cases of chat.
6+
57
## 0.116.1
68

79
- Fix stopping a prompt corrupting chat history with empty content blocks, causing subsequent API errors.

src/eca/features/chat.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,13 @@
560560
:text (str "API limit reached. Tokens: "
561561
(json/generate-string (:tokens msg)))})
562562
(lifecycle/finish-chat-prompt! :idle (dissoc chat-ctx :on-finished-side-effect)))
563-
:finish (let [response-text @received-msgs*]
563+
:finish (let [response-text @received-msgs*
564+
stopping? (identical? :stopping (get-in @db* [:chats chat-id :status]))]
564565
(when-not (string/blank? response-text)
565566
(add-to-history! {:role "assistant"
566567
:content [{:type :text :text response-text}]}))
567-
(if (and (not (string/blank? response-text))
568+
(if (and (not stopping?)
569+
(not (string/blank? response-text))
568570
(or (:premature? msg)
569571
(truncated-response? response-text))
570572
(not (:auto-continued? chat-ctx))
@@ -717,7 +719,9 @@
717719
(trigger-auto-compact! chat-ctx all-tools user-messages))
718720
(let [partial-text @received-msgs*
719721
transient-error? (contains? #{:overloaded :premature-stop} error-type)
720-
can-auto-continue? (and (or transient-error?
722+
stopping? (identical? :stopping (get-in @db* [:chats chat-id :status]))
723+
can-auto-continue? (and (not stopping?)
724+
(or transient-error?
721725
(string/includes? (or message "") "idle timeout"))
722726
(not (:auto-continued? chat-ctx))
723727
(not (:on-finished-side-effect chat-ctx))

0 commit comments

Comments
 (0)