Skip to content

Commit b7a1e8f

Browse files
fix(pre-proc-checks): deployed checks should precede cost/ratelimit increments" (#2250)
1 parent 3ce2788 commit b7a1e8f

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

apps/sim/app/api/chat/[identifier]/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ describe('Chat Identifier API Route', () => {
364364
error: {
365365
message: 'Workflow is not deployed',
366366
statusCode: 403,
367-
logCreated: true,
367+
logCreated: false,
368368
},
369369
})
370370

apps/sim/app/api/webhooks/test/[id]/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
6969

7070
let preprocessError: NextResponse | null = null
7171
try {
72-
preprocessError = await checkWebhookPreprocessing(foundWorkflow, foundWebhook, requestId)
72+
// Test webhooks skip deployment check but still enforce rate limits and usage limits
73+
// They run on live/draft state to allow testing before deployment
74+
preprocessError = await checkWebhookPreprocessing(foundWorkflow, foundWebhook, requestId, {
75+
isTestMode: true,
76+
})
7377
if (preprocessError) {
7478
return preprocessError
7579
}

apps/sim/background/webhook-execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function executeWebhookJobInternal(
134134
const loggingSession = new LoggingSession(
135135
payload.workflowId,
136136
executionId,
137-
payload.provider || 'webhook',
137+
payload.provider,
138138
requestId
139139
)
140140

apps/sim/lib/execution/preprocessing.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,18 @@ export async function preprocessExecution(
228228
const workspaceId = workflowRecord.workspaceId || providedWorkspaceId || ''
229229

230230
// ========== STEP 2: Check Deployment Status ==========
231+
// If workflow is not deployed and deployment is required, reject without logging.
232+
// No log entry or cost should be created for calls to undeployed workflows
233+
// since the workflow was never intended to run.
231234
if (checkDeployment && !workflowRecord.isDeployed) {
232235
logger.warn(`[${requestId}] Workflow not deployed: ${workflowId}`)
233236

234-
await logPreprocessingError({
235-
workflowId,
236-
executionId,
237-
triggerType,
238-
requestId,
239-
userId: workflowRecord.userId || userId,
240-
workspaceId,
241-
errorMessage: 'Workflow is not deployed. Please deploy the workflow before triggering it.',
242-
loggingSession: providedLoggingSession,
243-
})
244-
245237
return {
246238
success: false,
247239
error: {
248240
message: 'Workflow is not deployed',
249241
statusCode: 403,
250-
logCreated: true,
242+
logCreated: false,
251243
},
252244
}
253245
}

apps/sim/lib/webhooks/processor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,17 @@ export async function verifyProviderAuth(
494494
/**
495495
* Run preprocessing checks for webhook execution
496496
* This replaces the old checkRateLimits and checkUsageLimits functions
497+
*
498+
* @param isTestMode - If true, skips deployment check (for test webhooks that run on live/draft state)
497499
*/
498500
export async function checkWebhookPreprocessing(
499501
foundWorkflow: any,
500502
foundWebhook: any,
501-
requestId: string
503+
requestId: string,
504+
options?: { isTestMode?: boolean }
502505
): Promise<NextResponse | null> {
506+
const { isTestMode = false } = options || {}
507+
503508
try {
504509
const executionId = uuidv4()
505510

@@ -510,7 +515,7 @@ export async function checkWebhookPreprocessing(
510515
executionId,
511516
requestId,
512517
checkRateLimit: true, // Webhooks need rate limiting
513-
checkDeployment: true, // Webhooks require deployed workflows
518+
checkDeployment: !isTestMode, // Test webhooks skip deployment check (run on live state)
514519
workspaceId: foundWorkflow.workspaceId,
515520
})
516521

0 commit comments

Comments
 (0)