From fdf6c4a8aa3ea3fe475a6d7226b64667c40b1527 Mon Sep 17 00:00:00 2001 From: aadamgough Date: Sun, 4 Jan 2026 11:18:03 -0800 Subject: [PATCH 1/3] save before deployment fix --- apps/sim/app/api/webhooks/trigger/[path]/route.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/sim/app/api/webhooks/trigger/[path]/route.ts b/apps/sim/app/api/webhooks/trigger/[path]/route.ts index 549ce6a78d..0aafa8f84d 100644 --- a/apps/sim/app/api/webhooks/trigger/[path]/route.ts +++ b/apps/sim/app/api/webhooks/trigger/[path]/route.ts @@ -123,6 +123,15 @@ export async function POST( return authError } + const isGrainVerificationRequest = + foundWebhook.provider === 'grain' && (!body || Object.keys(body).length === 0 || !body.type) + if (isGrainVerificationRequest) { + logger.info( + `[${requestId}] Grain verification request detected - returning 200 for reachability test` + ) + return NextResponse.json({ status: 'ok', message: 'Webhook endpoint verified' }) + } + let preprocessError: NextResponse | null = null try { preprocessError = await checkWebhookPreprocessing(foundWorkflow, foundWebhook, requestId) From a6295a31d220cfea07ac251a57112bc1002d8e41 Mon Sep 17 00:00:00 2001 From: aadamgough Date: Sun, 4 Jan 2026 11:44:07 -0800 Subject: [PATCH 2/3] moved to helper --- .../app/api/webhooks/trigger/[path]/route.ts | 11 +++---- apps/sim/lib/webhooks/processor.ts | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/apps/sim/app/api/webhooks/trigger/[path]/route.ts b/apps/sim/app/api/webhooks/trigger/[path]/route.ts index 0aafa8f84d..9cdff87dc5 100644 --- a/apps/sim/app/api/webhooks/trigger/[path]/route.ts +++ b/apps/sim/app/api/webhooks/trigger/[path]/route.ts @@ -5,6 +5,7 @@ import { checkWebhookPreprocessing, findWebhookAndWorkflow, handleProviderChallenges, + handleProviderReachabilityTest, parseWebhookBody, queueWebhookExecution, verifyProviderAuth, @@ -123,13 +124,9 @@ export async function POST( return authError } - const isGrainVerificationRequest = - foundWebhook.provider === 'grain' && (!body || Object.keys(body).length === 0 || !body.type) - if (isGrainVerificationRequest) { - logger.info( - `[${requestId}] Grain verification request detected - returning 200 for reachability test` - ) - return NextResponse.json({ status: 'ok', message: 'Webhook endpoint verified' }) + const reachabilityResponse = handleProviderReachabilityTest(foundWebhook, body, requestId) + if (reachabilityResponse) { + return reachabilityResponse } let preprocessError: NextResponse | null = null diff --git a/apps/sim/lib/webhooks/processor.ts b/apps/sim/lib/webhooks/processor.ts index b197a8ef18..7cc6380856 100644 --- a/apps/sim/lib/webhooks/processor.ts +++ b/apps/sim/lib/webhooks/processor.ts @@ -121,6 +121,37 @@ export async function handleProviderChallenges( return null } +/** + * Handle provider-specific reachability tests that occur AFTER webhook lookup. + * + * This function should be called after findWebhookAndWorkflow() but before + * checkWebhookPreprocessing() to allow verification requests to bypass deployment checks. + * + * @param webhook - The webhook record from the database + * @param body - The parsed request body + * @param requestId - Request ID for logging + * @returns NextResponse if this is a verification request, null to continue normal flow + */ +export function handleProviderReachabilityTest( + webhook: any, + body: any, + requestId: string +): NextResponse | null { + const provider = webhook?.provider + + if (provider === 'grain') { + const isVerificationRequest = !body || Object.keys(body).length === 0 || !body.type + if (isVerificationRequest) { + logger.info( + `[${requestId}] Grain reachability test detected - returning 200 for webhook verification` + ) + return NextResponse.json({ status: 'ok', message: 'Webhook endpoint verified' }) + } + } + + return null +} + export async function findWebhookAndWorkflow( options: WebhookProcessorOptions ): Promise<{ webhook: any; workflow: any } | null> { From 240a27f5eebc5693d660a8a6aa7805cd9abc74d7 Mon Sep 17 00:00:00 2001 From: aadamgough Date: Sun, 4 Jan 2026 11:45:00 -0800 Subject: [PATCH 3/3] removed comment --- apps/sim/lib/webhooks/processor.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/sim/lib/webhooks/processor.ts b/apps/sim/lib/webhooks/processor.ts index 7cc6380856..96cf01b8f3 100644 --- a/apps/sim/lib/webhooks/processor.ts +++ b/apps/sim/lib/webhooks/processor.ts @@ -124,9 +124,6 @@ export async function handleProviderChallenges( /** * Handle provider-specific reachability tests that occur AFTER webhook lookup. * - * This function should be called after findWebhookAndWorkflow() but before - * checkWebhookPreprocessing() to allow verification requests to bypass deployment checks. - * * @param webhook - The webhook record from the database * @param body - The parsed request body * @param requestId - Request ID for logging