fix(chat): prevent message loss after cancel via newTask fallback
cancel 任务后,handleSendMessage 的三分支路由(messages.length===0 / clineAsk 有值 / isTaskRunning)会全部 miss:cancel 后 Controller 走 resumeTaskFromHistory,此时既没有 pending ask(clineAsk===undefined), 任务也不在 streaming(isTaskRunning===false),三条分支都不命中, messageSent 保持 false,用户输入的消息被静默丢弃,输入框不清空、 UI 看起来像卡死,只能 reload 窗口才能恢复。 修复:在三分支之后加兜底——当 messageSent 仍为 false(说明任务处于 不确定状态,最常见就是 cancel 后的死区)时,用 newTask 新开任务承载 用户输入,确保消息永远不会被吞掉。 注意:这只是消除"消息被吞"的症状。cancel 清理不彻底的根因 (VscodeTerminalProcess 缺少 terminate()、abort 流程卡住)仍需单独处理。
This commit is contained in:
1 parent
a8496114b0
commit
e9959269ee
1 file changed
+19
@@ -116,6 +116,25 @@ export function useMessageHandlers(messages: ClineMessage[], chatState: ChatStat
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: no branch matched, which means the task is in an
|
||||
// indeterminate state (most commonly after cancelling a task —
|
||||
// there is no pending ask and the task is not streaming, so the
|
||||
// three branches above all miss). Previously the message was
|
||||
// silently dropped here, leaving the input intact and the UI
|
||||
// appearing frozen (only a window reload recovered it). Instead,
|
||||
// start a new task with the user's input so the message is never
|
||||
// lost.
|
||||
if (!messageSent) {
|
||||
await TaskServiceClient.newTask(
|
||||
NewTaskRequest.create({
|
||||
text: messageToSend,
|
||||
images,
|
||||
files,
|
||||
}),
|
||||
)
|
||||
messageSent = true
|
||||
}
|
||||
|
||||
// Only clear input and disable UI if message was actually sent
|
||||
if (messageSent) {
|
||||
setInputValue("")
|
||||
|
||||
Reference in new issue
Block a user