fix: stop thinking timer when reply is aborted (#11794)

Fixes #11772
When user stops the reply after thinking is complete but text is still
streaming, all blocks in STREAMING status are now updated to PAUSED,
which properly stops the thinking timer.

Signed-off-by: Calvin <calvinvwei@gmail.com>
This commit is contained in:
Calvin Wade 2025-12-11 16:25:31 +08:00 committed by GitHub
parent c52a2dbc48
commit 6b25fbb901
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import i18n from '@renderer/i18n'
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService' import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
import { NotificationService } from '@renderer/services/NotificationService' import { NotificationService } from '@renderer/services/NotificationService'
import { estimateMessagesUsage } from '@renderer/services/TokenService' import { estimateMessagesUsage } from '@renderer/services/TokenService'
import { updateOneBlock } from '@renderer/store/messageBlock'
import { selectMessagesForTopic } from '@renderer/store/newMessage' import { selectMessagesForTopic } from '@renderer/store/newMessage'
import { newMessagesActions } from '@renderer/store/newMessage' import { newMessagesActions } from '@renderer/store/newMessage'
import type { Assistant } from '@renderer/types' import type { Assistant } from '@renderer/types'
@ -104,6 +105,25 @@ export const createBaseCallbacks = (deps: BaseCallbacksDependencies) => {
blockManager.smartBlockUpdate(possibleBlockId, changes, blockManager.lastBlockType!, true) blockManager.smartBlockUpdate(possibleBlockId, changes, blockManager.lastBlockType!, true)
} }
// Fix: 更新所有仍处于 STREAMING 状态的 blocks 为 PAUSED/ERROR
// 这修复了停止回复时思考计时器继续运行的问题
const currentMessage = getState().messages.entities[assistantMsgId]
if (currentMessage) {
const allBlockRefs = findAllBlocks(currentMessage)
const blockState = getState().messageBlocks
for (const blockRef of allBlockRefs) {
const block = blockState.entities[blockRef.id]
if (block && block.status === MessageBlockStatus.STREAMING && block.id !== possibleBlockId) {
dispatch(
updateOneBlock({
id: block.id,
changes: { status: isErrorTypeAbort ? MessageBlockStatus.PAUSED : MessageBlockStatus.ERROR }
})
)
}
}
}
const errorBlock = createErrorBlock(assistantMsgId, serializableError, { status: MessageBlockStatus.SUCCESS }) const errorBlock = createErrorBlock(assistantMsgId, serializableError, { status: MessageBlockStatus.SUCCESS })
await blockManager.handleBlockTransition(errorBlock, MessageBlockType.ERROR) await blockManager.handleBlockTransition(errorBlock, MessageBlockType.ERROR)
const messageErrorUpdate = { const messageErrorUpdate = {