From 28bbe315aaece8e599952221293a40593d4be74a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 18 Apr 2026 09:03:49 +0000 Subject: [PATCH 1/2] fix(api): Restore workflow run header on chat stream The chat API regressed to mutating the streaming response after creation, which left WorkflowChatTransport without the workflow resume header it expects on the initial response. Restore the earlier Vercel-only BotID guard and provide x-workflow-run-id when creating the stream response so reconnects can continue instead of failing with a client-side fetch error. Fixes WEBVITALS-2W Co-Authored-By: Claude Co-authored-by: Sergiy Dybskiy --- app/api/chat/route.ts | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index b621e6d..a5b7a79 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -5,17 +5,26 @@ import { start } from "workflow/api"; import { analysisWorkflow } from "@/workflows/analysis"; export async function POST(request: Request) { - const botIdResult = await checkBotId(); - Sentry.logger.debug("BotID check result", { - isBot: botIdResult.isBot, - userAgent: request.headers.get("user-agent"), - }); - if (botIdResult.isBot) { - Sentry.logger.warn("BotID check failed", { - isBot: botIdResult.isBot, - userAgent: request.headers.get("user-agent"), - }); - return new Response("Access Denied", { status: 403 }); + if (process.env.VERCEL_ENV === "production") { + try { + const botIdResult = await checkBotId(); + Sentry.logger.debug("BotID check result", { + isBot: botIdResult.isBot, + userAgent: request.headers.get("user-agent"), + }); + if (botIdResult.isBot) { + Sentry.logger.warn("BotID check failed", { + isBot: botIdResult.isBot, + userAgent: request.headers.get("user-agent"), + }); + return new Response("Access Denied", { status: 403 }); + } + } catch (error) { + Sentry.logger.warn("BotID check threw exception", { + error: error instanceof Error ? error.message : String(error), + userAgent: request.headers.get("user-agent"), + }); + } } const analysisStartTime = Date.now(); @@ -113,11 +122,12 @@ export async function POST(request: Request) { "webvitals.run_id": run.runId, }); - const response = createUIMessageStreamResponse({ + return createUIMessageStreamResponse({ + headers: { + "x-workflow-run-id": run.runId, + }, stream: run.readable, }); - response.headers.set("x-workflow-run-id", run.runId); - return response; } catch (error) { const durationMs = Date.now() - analysisStartTime; From 85be3f5d0e84291ce27c32f97e44a425a7db01b6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 18 Apr 2026 09:05:57 +0000 Subject: [PATCH 2/2] fix(api): Format chat workflow header fix Apply the repository formatter to the chat workflow regression fix so lint output reflects baseline repository issues instead of this patch. Refs WEBVITALS-2W Co-Authored-By: Claude Co-authored-by: Sergiy Dybskiy --- app/api/chat/route.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index a5b7a79..e48cb54 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -134,8 +134,7 @@ export async function POST(request: Request) { span.setAttributes({ "webvitals.outcome": "failed", "webvitals.duration_ms": durationMs, - "webvitals.error": - error instanceof Error ? error.message : "Unknown", + "webvitals.error": error instanceof Error ? error.message : "Unknown", }); Sentry.metrics.count("webvitals.analysis.completed", 1, { @@ -179,8 +178,7 @@ export async function POST(request: Request) { return Response.json( { error: "Failed to process chat request", - details: - error instanceof Error ? error.message : "Unknown error", + details: error instanceof Error ? error.message : "Unknown error", }, { status: 500 }, );