-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(deployed-version-check): check deployed version existence pre-queuing #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(deployed-version-check): check deployed version existence pre-queuing #1508
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR adds a critical defensive check to prevent webhook executions for workflows without active deployments. The change introduces a new utility function `hasActiveDeployment` in the workflow database helpers that performs a lightweight query to verify deployment existence, and integrates this check into the webhook trigger route to return a 404 error if no active deployment is found.The implementation follows existing patterns in the codebase by adding deployment validation as another pre-execution gate alongside existing auth, rate limits, and usage checks. The utility function is designed for efficiency, selecting only the ID field with a limit of 1 record, and includes proper error handling by returning false on query failures. This change addresses a bug where webhooks could be queued for execution against workflows that have no deployed version, which would likely cause runtime failures downstream in the execution pipeline.
The integration point in the webhook trigger route occurs after workflow lookup but before queuing execution, providing early feedback to webhook providers with a clear 404 response when attempting to trigger non-deployed workflows. This aligns well with the existing execution target being set to 'deployed', making the pre-check a logical prerequisite.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/workflows/db-helpers.ts | 4/5 | Added hasActiveDeployment utility function for checking workflow deployment existence |
| apps/sim/app/api/webhooks/trigger/[path]/route.ts | 5/5 | Integrated deployment check before webhook execution queuing with 404 error handling |
Confidence score: 4/5
- This PR is safe to merge with minimal risk of production issues
- Score reflects solid implementation following existing patterns with appropriate error handling
- Pay attention to apps/sim/lib/workflows/db-helpers.ts for the new utility function logic
Sequence Diagram
sequenceDiagram
participant User
participant WebhookAPI as "Webhook Trigger API"
participant Parser as "Webhook Processor"
participant DB as "Database"
participant Queue as "Webhook Queue"
User->>WebhookAPI: "POST /api/webhooks/trigger/[path]"
WebhookAPI->>WebhookAPI: "Generate Request ID"
WebhookAPI->>Parser: "parseWebhookBody(request, requestId)"
Parser-->>WebhookAPI: "{ body, rawBody }"
WebhookAPI->>Parser: "handleProviderChallenges(body, request, requestId, path)"
Parser-->>WebhookAPI: "challengeResponse or null"
alt Challenge Response Exists
WebhookAPI-->>User: "Return Challenge Response"
end
WebhookAPI->>Parser: "findWebhookAndWorkflow({ requestId, path })"
Parser->>DB: "Query webhook and workflow by path"
DB-->>Parser: "webhook and workflow data"
Parser-->>WebhookAPI: "{ webhook, workflow } or null"
alt Webhook/Workflow Not Found
WebhookAPI-->>User: "404 Not Found"
end
WebhookAPI->>Parser: "verifyProviderAuth(webhook, request, rawBody, requestId)"
Parser-->>WebhookAPI: "authError or null"
alt Auth Error
WebhookAPI-->>User: "Return Auth Error"
end
WebhookAPI->>Parser: "checkRateLimits(workflow, webhook, requestId)"
Parser-->>WebhookAPI: "rateLimitError or null"
alt Rate Limit Error
WebhookAPI-->>User: "Return Rate Limit Error"
end
WebhookAPI->>Parser: "checkUsageLimits(workflow, webhook, requestId, false)"
Parser-->>WebhookAPI: "usageLimitError or null"
alt Usage Limit Error
WebhookAPI-->>User: "Return Usage Limit Error"
end
WebhookAPI->>DB: "hasActiveDeployment(workflow.id)"
DB-->>WebhookAPI: "boolean (deployment exists)"
alt No Active Deployment
WebhookAPI-->>User: "404 Workflow not deployed"
end
WebhookAPI->>Parser: "queueWebhookExecution(webhook, workflow, body, request, options)"
Parser->>Queue: "Queue webhook execution job"
Queue-->>Parser: "Execution queued"
Parser-->>WebhookAPI: "Success response"
WebhookAPI-->>User: "200 OK with provider-specific response"
2 files reviewed, no comments
Summary
Check if active deployment exists pre queuing the webhook execution
Type of Change
Testing
Tested manually with Gmail trigger.
Checklist