From 11c878d8c5cd32e4f917aae73b741206bcd6f018 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 14 Apr 2026 19:05:03 +0000 Subject: [PATCH 1/2] fix(api): Restore chat workflow response headers Restore the safer BotID handling in /api/chat so missing verification headers do not block legitimate browsers. Pass x-workflow-run-id when creating the streaming response so WorkflowChatTransport consistently receives the workflow resume header it requires. Fixes WEBVITALS-2Y 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 593d655c353d7d5db20d51eac5f421e907707671 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 14 Apr 2026 19:06:25 +0000 Subject: [PATCH 2/2] fix(api): Format chat route fix Apply the repository formatter to the /api/chat regression fix so lint output reflects only pre-existing repository issues. Refs WEBVITALS-2Y 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 }, );