Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Check if active deployment exists pre queuing the webhook execution

Type of Change

  • Bug fix

Testing

Tested manually with Gmail trigger.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Sep 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 30, 2025 11:26pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 30, 2025 11:26pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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"
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 30, 2025 23:19 Inactive
@icecrasher321 icecrasher321 merged commit 0d881ec into staging Oct 1, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/check-deployed-version-trigger-path branch November 7, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants