fix(pre-proc-checks): deployed checks should precede cost/ratelimit increments" (#2250)

This commit is contained in:
Vikhyath Mondreti
2025-12-08 20:04:21 -08:00
committed by GitHub
parent 3ce2788562
commit b7a1e8f5cf
5 changed files with 18 additions and 17 deletions

View File

@@ -364,7 +364,7 @@ describe('Chat Identifier API Route', () => {
error: {
message: 'Workflow is not deployed',
statusCode: 403,
logCreated: true,
logCreated: false,
},
})

View File

@@ -69,7 +69,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
let preprocessError: NextResponse | null = null
try {
preprocessError = await checkWebhookPreprocessing(foundWorkflow, foundWebhook, requestId)
// Test webhooks skip deployment check but still enforce rate limits and usage limits
// They run on live/draft state to allow testing before deployment
preprocessError = await checkWebhookPreprocessing(foundWorkflow, foundWebhook, requestId, {
isTestMode: true,
})
if (preprocessError) {
return preprocessError
}

View File

@@ -134,7 +134,7 @@ async function executeWebhookJobInternal(
const loggingSession = new LoggingSession(
payload.workflowId,
executionId,
payload.provider || 'webhook',
payload.provider,
requestId
)

View File

@@ -228,26 +228,18 @@ export async function preprocessExecution(
const workspaceId = workflowRecord.workspaceId || providedWorkspaceId || ''
// ========== STEP 2: Check Deployment Status ==========
// If workflow is not deployed and deployment is required, reject without logging.
// No log entry or cost should be created for calls to undeployed workflows
// since the workflow was never intended to run.
if (checkDeployment && !workflowRecord.isDeployed) {
logger.warn(`[${requestId}] Workflow not deployed: ${workflowId}`)
await logPreprocessingError({
workflowId,
executionId,
triggerType,
requestId,
userId: workflowRecord.userId || userId,
workspaceId,
errorMessage: 'Workflow is not deployed. Please deploy the workflow before triggering it.',
loggingSession: providedLoggingSession,
})
return {
success: false,
error: {
message: 'Workflow is not deployed',
statusCode: 403,
logCreated: true,
logCreated: false,
},
}
}

View File

@@ -494,12 +494,17 @@ export async function verifyProviderAuth(
/**
* Run preprocessing checks for webhook execution
* This replaces the old checkRateLimits and checkUsageLimits functions
*
* @param isTestMode - If true, skips deployment check (for test webhooks that run on live/draft state)
*/
export async function checkWebhookPreprocessing(
foundWorkflow: any,
foundWebhook: any,
requestId: string
requestId: string,
options?: { isTestMode?: boolean }
): Promise<NextResponse | null> {
const { isTestMode = false } = options || {}
try {
const executionId = uuidv4()
@@ -510,7 +515,7 @@ export async function checkWebhookPreprocessing(
executionId,
requestId,
checkRateLimit: true, // Webhooks need rate limiting
checkDeployment: true, // Webhooks require deployed workflows
checkDeployment: !isTestMode, // Test webhooks skip deployment check (run on live state)
workspaceId: foundWorkflow.workspaceId,
})