Skip to content

Commit b8bafd1

Browse files
committed
fix(chat): drop interrupted partial assistant text on cancel; ensure backend removes in-flight say:"text" so UI hydration doesn’t retain it; all tests passing
1 parent ac57bd0 commit b8bafd1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/core/task/Task.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,14 +2025,28 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
20252025
await this.diffViewProvider.revertChanges() // closes diff view
20262026
}
20272027

2028-
// if last message is a partial we need to update and save it
2029-
const lastMessage = this.clineMessages.at(-1)
2030-
2031-
if (lastMessage && lastMessage.partial) {
2032-
// lastMessage.ts = Date.now() DO NOT update ts since it is used as a key for virtuoso list
2033-
lastMessage.partial = false
2034-
// instead of streaming partialMessage events, we do a save and post like normal to persist to disk
2035-
console.log("updating partial message", lastMessage)
2028+
// Remove partial streaming messages (text and reasoning) when stream is aborted
2029+
// to match main branch behavior where interrupted streaming text doesn't persist
2030+
while (this.clineMessages.length > 0) {
2031+
const lastMessage = this.clineMessages[this.clineMessages.length - 1]
2032+
2033+
if (lastMessage && lastMessage.partial) {
2034+
// Remove partial text and reasoning messages that were being streamed
2035+
if (
2036+
lastMessage.type === "say" &&
2037+
(lastMessage.say === "text" || lastMessage.say === "reasoning")
2038+
) {
2039+
this.clineMessages.pop()
2040+
console.log(`[abortStream] removed partial ${lastMessage.say} message`)
2041+
continue
2042+
}
2043+
2044+
// For other partial messages (like tool asks), finalize them instead of removing
2045+
lastMessage.partial = false
2046+
console.log(`[abortStream] finalized partial ${lastMessage.type} message`)
2047+
}
2048+
2049+
break
20362050
}
20372051

20382052
// Update `api_req_started` to have cancelled and cost, so that

0 commit comments

Comments
 (0)