Skip to content

Commit 0245c48

Browse files
ericdalloeca-agent
andcommitted
Fix /resume broken for OpenAI chats
Three root causes fixed: - Nil reasoning text during replay: message-content->chat-content unconditionally emitted reasonText with nil text when OpenAI reasoning had no :thinking events (e.g. redacted). Now conditionally includes reasonText only when text is non-nil. - Prompt-id lost after chat replacement: the resume command replaced the entire chat map, losing the current prompt-id. finish-chat-prompt!'s supersession guard then rejected the transition to idle, leaving the UI stuck in "thinking" state. Now restores prompt-id after replacement. - UI not cleared before replay: resumed messages were appended on top of existing ones. Now sends chat-cleared before replaying, matching the rollback-chat pattern, and re-sends statusChanged :running so the client properly tracks the loading→finished lifecycle. Closes #400 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca <git@eca.dev>
1 parent 67ccc01 commit 0245c48

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
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 `/resume` broken for OpenAI chats: handle nil reasoning text during replay, preserve prompt-id after chat replacement, and clear UI before replaying messages. #400
6+
57
## 0.124.2
68

79
- Fix OpenAI Responses API tool calls not executing when streaming response returns empty output, and fix spurious retries caused by stale tool-call state with Copilot encrypted IDs. #398

src/eca/features/chat.clj

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,19 @@
186186
:name "web_search"
187187
:arguments {}
188188
:error false}}])
189-
"reason" [{:role :assistant
190-
:content {:type :reasonStarted
191-
:id (:id message-content)}}
192-
{:role :assistant
193-
:content {:type :reasonText
194-
:id (:id message-content)
195-
:text (:text message-content)}}
196-
{:role :assistant
197-
:content {:type :reasonFinished
198-
:id (:id message-content)
199-
:total-time-ms (:total-time-ms message-content)}}]
189+
"reason" (cond-> [{:role :assistant
190+
:content {:type :reasonStarted
191+
:id (:id message-content)}}]
192+
(:text message-content)
193+
(conj {:role :assistant
194+
:content {:type :reasonText
195+
:id (:id message-content)
196+
:text (:text message-content)}})
197+
true
198+
(conj {:role :assistant
199+
:content {:type :reasonFinished
200+
:id (:id message-content)
201+
:total-time-ms (:total-time-ms message-content)}}))
200202
"compact_marker" [{:role :system
201203
:content {:type :text
202204
:text (if (:auto? message-content)
@@ -852,6 +854,9 @@
852854
(let [{:keys [type on-finished-side-effect] :as result} (f.commands/handle-command! command args chat-ctx)]
853855
(case type
854856
:chat-messages (do
857+
(when (:clear-before? result)
858+
(messenger/chat-cleared (:messenger chat-ctx) {:chat-id (:chat-id chat-ctx) :messages true})
859+
(messenger/chat-status-changed (:messenger chat-ctx) {:chat-id (:chat-id chat-ctx) :status :running}))
855860
(doseq [[chat-id {:keys [messages title]}] (:chats result)]
856861
(let [new-chat-ctx (assoc chat-ctx :chat-id chat-id)]
857862
(send-chat-contents! messages new-chat-ctx)

src/eca/features/commands.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,11 @@
413413
(let [chat (get chats selected-chat-id)]
414414
(swap! db* assoc-in [:chats chat-id] chat)
415415
(swap! db* update-in [:chats chat-id] dissoc :prompt-finished? :auto-compacting? :compacting?)
416+
(swap! db* assoc-in [:chats chat-id :prompt-id] (:prompt-id chat-ctx))
416417
(swap! db* update-in [:chats] #(dissoc % selected-chat-id))
417418
(db/update-workspaces-cache! @db* metrics)
418419
{:type :chat-messages
420+
:clear-before? true
419421
:chats {chat-id {:title (:title chat)
420422
:messages (concat [{:role "system" :content [{:type :text :text (str "Resuming chat: " selected-chat-id)}]}]
421423
(:messages chat))}}})))

0 commit comments

Comments
 (0)