From ba4545ceb5eadeb0bf05fbe2cee79ad54ecd6bcc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 27 Feb 2026 04:55:53 +0000 Subject: [PATCH] Fix send state set outside try-finally and remove redundant setSendPhase call Move sendInFlightRef.current and setSendPhase assignments inside the try block so that the finally block always resets them, preventing permanent send-lock if code between the assignments and the try block throws. Also removes the redundant setSendPhase('preparing-worktree') call that was already set identically before the try block. --- apps/web/src/components/ChatView.tsx | 67 ++++++++++++++-------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 64ac9e1bd3..3216ac201a 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1416,44 +1416,43 @@ export default function ChatView({ threadId }: ChatViewProps) { return; } - sendInFlightRef.current = true; - setSendPhase(baseBranchForWorktree ? "preparing-worktree" : "sending-turn"); - - const composerImagesSnapshot = [...composerImages]; - const messageIdForSend = newMessageId(); - const messageCreatedAt = new Date().toISOString(); - const optimisticAttachments = composerImagesSnapshot.map((image) => ({ - type: "image" as const, - id: image.id, - name: image.name, - mimeType: image.mimeType, - sizeBytes: image.sizeBytes, - previewUrl: image.previewUrl, - })); - setOptimisticUserMessages((existing) => [ - ...existing, - { - id: messageIdForSend, - role: "user", - text: trimmed, - ...(optimisticAttachments.length > 0 ? { attachments: optimisticAttachments } : {}), - createdAt: messageCreatedAt, - streaming: false, - }, - ]); - - setThreadError(threadIdForSend, null); - promptRef.current = ""; - setPrompt(""); - setComposerImages([]); - setComposerCursor(0); - setComposerHighlightedItemId(null); - let attemptedTurnStart = false; try { + sendInFlightRef.current = true; + setSendPhase(baseBranchForWorktree ? "preparing-worktree" : "sending-turn"); + + const composerImagesSnapshot = [...composerImages]; + const messageIdForSend = newMessageId(); + const messageCreatedAt = new Date().toISOString(); + const optimisticAttachments = composerImagesSnapshot.map((image) => ({ + type: "image" as const, + id: image.id, + name: image.name, + mimeType: image.mimeType, + sizeBytes: image.sizeBytes, + previewUrl: image.previewUrl, + })); + setOptimisticUserMessages((existing) => [ + ...existing, + { + id: messageIdForSend, + role: "user", + text: trimmed, + ...(optimisticAttachments.length > 0 ? { attachments: optimisticAttachments } : {}), + createdAt: messageCreatedAt, + streaming: false, + }, + ]); + + setThreadError(threadIdForSend, null); + promptRef.current = ""; + setPrompt(""); + setComposerImages([]); + setComposerCursor(0); + setComposerHighlightedItemId(null); + // On first message: lock in branch + create worktree if needed. if (baseBranchForWorktree) { - setSendPhase("preparing-worktree"); const newBranch = `codething/${crypto.randomUUID().slice(0, 8)}`; const result = await createWorktreeMutation.mutateAsync({ cwd: activeProject.cwd,