Skip to content

Commit cb47895

Browse files
committed
Fix prompt cache invalidation warning after clearing chat
Also add missing line break after "Prompt stopped" message. Closes #530
1 parent 9aebefe commit cb47895

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

CHANGELOG.md

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

33
## Unreleased
44

5+
- Fix prompt cache invalidation warning after clearing the chat and changing model. #530
6+
- Fix missing line break after "Prompt stopped" message when followed by another system message.
7+
58
## 0.147.0
69

710
- Granular shell/git approve & remember by command + subcommand (e.g. `git checkout`) instead of whole tool; details carry breakdown, approval keys and remembered state. #153

src/eca/features/chat.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@
18851885
:parent-chat-id (db/parent-chat-id @db* chat-id)}]
18861886
(when-not silent?
18871887
(lifecycle/send-content! chat-ctx :system {:type :text
1888-
:text "\nPrompt stopped"}))
1888+
:text "\nPrompt stopped\n"}))
18891889

18901890
;; Handle each active tool call
18911891
(doseq [[tool-call-id _] (tc/get-active-tool-calls @db* chat-id)]
@@ -1925,8 +1925,12 @@
19251925
(swap! db* update-in [:chats chat-id]
19261926
(fn [chat]
19271927
(cond-> chat
1928+
;; A cleared chat is a fresh conversation: drop the prompt cache
1929+
;; so the next prompt rebuilds the system prompt silently instead
1930+
;; of warning about an invalidated cache that no longer exists. #530
19281931
messages (-> (assoc :messages [])
1929-
(dissoc :tool-calls :last-api :usage :task)))))
1932+
(dissoc :tool-calls :last-api :usage :task
1933+
:prompt-cache :last-editor-state)))))
19301934
(messenger/chat-cleared messenger {:chat-id chat-id :messages messages})
19311935
(db/update-workspaces-cache! @db* metrics)))
19321936

test/eca/features/chat_test.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@
11981198
{:role :assistant :content {:type :toolCalled :id "call-3" :name "ro_tool_3" :arguments {}
11991199
:outputs [{:type :text :text "RO tool call 3 result"}]}}
12001200
{:role :system :content {:type :progress :state :running :text "Generating"}}
1201-
{:role :system :content {:type :text :text "\nPrompt stopped"}}
1201+
{:role :system :content {:type :text :text "\nPrompt stopped\n"}}
12021202
{:role :system :content {:type :progress :state :finished}}
12031203
{:role :assistant :content {:type :toolCallRejected :id "call-2" :name "ro_tool_2" :arguments {} :reason :user}}
12041204
{:role :assistant :content {:type :toolCallRejected :id "call-1" :name "ro_tool_1" :arguments {} :reason :user}}]}
@@ -1656,6 +1656,23 @@
16561656
(is (= 2 @build-calls*) "Next message rebuilds the system prompt")
16571657
(is (empty? (system-prompt-notices)) "Explicit sync rebuild does not notify"))))))
16581658

1659+
(deftest clear-chat-resets-prompt-cache-test
1660+
(testing "Clearing a chat drops the prompt cache so a model switch does not warn (#530)"
1661+
(h/reset-components!)
1662+
(let [mocks {:all-tools-mock (constantly [])
1663+
:api-mock (fn [{:keys [on-message-received]}]
1664+
(on-message-received {:type :finish}))}
1665+
{:keys [chat-id]} (prompt! {:message "Hi" :model "openai/gpt-5.2"} mocks)]
1666+
(is (some? (get-in (h/db) [:chats chat-id :prompt-cache])))
1667+
(f.chat/clear-chat {:chat-id chat-id :messages true} (h/db*) (h/messenger) (h/metrics))
1668+
(is (nil? (get-in (h/db) [:chats chat-id :prompt-cache]))
1669+
"Clearing messages drops the prompt cache")
1670+
(swap! (h/db*) update :models #(merge % {"anthropic/claude-opus-4" {:tools true}}))
1671+
(h/reset-messenger!)
1672+
(prompt! {:message "Fresh" :chat-id chat-id :model "anthropic/claude-opus-4"} mocks)
1673+
(is (empty? (system-prompt-notices))
1674+
"No prompt cache invalidation notice on an empty chat"))))
1675+
16591676
(deftest prompt-cache-key-includes-agent-test
16601677
(testing "sync-or-async-prompt! receives prompt-cache-key scoped by active agent"
16611678
(h/reset-components!)

0 commit comments

Comments
 (0)