From dddbf53c659ef6132833d835890ae3c580d58a75 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Mon, 30 Mar 2026 16:06:30 -0700 Subject: [PATCH] fix(mothership): hang condition --- apps/sim/app/api/mothership/chat/stop/route.ts | 3 +++ apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/apps/sim/app/api/mothership/chat/stop/route.ts b/apps/sim/app/api/mothership/chat/stop/route.ts index 763ff9b2cfc..8eb5185ff1e 100644 --- a/apps/sim/app/api/mothership/chat/stop/route.ts +++ b/apps/sim/app/api/mothership/chat/stop/route.ts @@ -5,6 +5,7 @@ import { and, eq, sql } from 'drizzle-orm' import { type NextRequest, NextResponse } from 'next/server' import { z } from 'zod' import { getSession } from '@/lib/auth' +import { releasePendingChatStream } from '@/lib/copilot/chat-streaming' import { taskPubSub } from '@/lib/copilot/task-events' const logger = createLogger('MothershipChatStopAPI') @@ -58,6 +59,8 @@ export async function POST(req: NextRequest) { const { chatId, streamId, content, contentBlocks } = StopSchema.parse(await req.json()) + await releasePendingChatStream(chatId, streamId) + const setClause: Record = { conversationId: null, updatedAt: new Date(), diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts index 3b3511ab0f3..7b5c1cda635 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts @@ -1737,6 +1737,8 @@ export function useChat( } if (options?.error) { + pendingRecoveryMessageRef.current = null + setPendingRecoveryMessage(null) setMessageQueue([]) return }