From e9959269ee5e41a7574aed32e8fac9954ee521a4 Mon Sep 17 00:00:00 2001 From: HybridTalentComputing <1316645276@qq.com> Date: Tue, 16 Jun 2026 20:56:58 +0800 Subject: [PATCH] fix(chat): prevent message loss after cancel via newTask fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 流程卡住)仍需单独处理。 --- .../chat-view/hooks/useMessageHandlers.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/webview-ui/src/components/chat/chat-view/hooks/useMessageHandlers.ts b/webview-ui/src/components/chat/chat-view/hooks/useMessageHandlers.ts index a59ac980..5215aa03 100644 --- a/webview-ui/src/components/chat/chat-view/hooks/useMessageHandlers.ts +++ b/webview-ui/src/components/chat/chat-view/hooks/useMessageHandlers.ts @@ -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("")