mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
fix(pre-proc-checks): deployed checks should precede cost/ratelimit increments" (#2250)
This commit is contained in:
committed by
GitHub
parent
3ce2788562
commit
b7a1e8f5cf
@@ -364,7 +364,7 @@ describe('Chat Identifier API Route', () => {
|
||||
error: {
|
||||
message: 'Workflow is not deployed',
|
||||
statusCode: 403,
|
||||
logCreated: true,
|
||||
logCreated: false,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ async function executeWebhookJobInternal(
|
||||
const loggingSession = new LoggingSession(
|
||||
payload.workflowId,
|
||||
executionId,
|
||||
payload.provider || 'webhook',
|
||||
payload.provider,
|
||||
requestId
|
||||
)
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user