Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sim/app/api/chat/[identifier]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('Chat Identifier API Route', () => {
error: {
message: 'Workflow is not deployed',
statusCode: 403,
logCreated: true,
logCreated: false,
},
})

Expand Down
6 changes: 5 additions & 1 deletion apps/sim/app/api/webhooks/test/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/background/webhook-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function executeWebhookJobInternal(
const loggingSession = new LoggingSession(
payload.workflowId,
executionId,
payload.provider || 'webhook',
payload.provider,
requestId
)

Expand Down
16 changes: 4 additions & 12 deletions apps/sim/lib/execution/preprocessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down
9 changes: 7 additions & 2 deletions apps/sim/lib/webhooks/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
})

Expand Down