Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Will do webhook lifecycle management as part of deploy process.

Type of Change

  • Other: UX Improvement

Testing

Tested manually

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 Jan 15, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 15, 2026 6:04pm

Review with Vercel Agent

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 15, 2026

Greptile Summary

This PR improves webhook lifecycle management by moving webhook creation from a manual "Save Configuration" button to the automated deploy process, and removes the deprecated save configuration UI.

Key Changes:

  • Created new apps/sim/lib/webhooks/deploy.ts module that handles webhook validation and creation during workflow deployment
  • Integrated webhook saving into the deploy flow in apps/sim/app/api/workflows/[id]/deploy/route.ts - webhooks are now validated and created before deployment
  • Moved webhook cleanup logic to apps/sim/app/api/workflows/[id]/state/route.ts to delete webhooks when blocks are edited or deleted
  • Removed the TriggerSave component and deprecated the trigger-save subblock type
  • Consolidated external provider subscription functions (Grain, Lemlist, Airtable, Calendly, Webflow) into provider-subscriptions.ts
  • Updated setup instructions for Grain, Lemlist, and HubSpot triggers to remove references to "Save Configuration" button

Issues Found:

  • The webhook cleanup logic uses JSON.stringify comparison which will trigger cleanup on every block edit, even for trivial changes, causing webhook churn

Confidence Score: 4/5

  • This PR is safe to merge with one logical issue that should be addressed
  • The refactoring successfully consolidates webhook lifecycle management into the deploy process and removes manual configuration UI. The code is well-structured with proper error handling. However, the JSON.stringify comparison in state route will cause excessive webhook churn on every block edit, which is a significant logic issue affecting production behavior.
  • apps/sim/app/api/workflows/[id]/state/route.ts needs attention for the webhook cleanup logic

Important Files Changed

Filename Overview
apps/sim/lib/webhooks/deploy.ts New file implementing webhook lifecycle management during deployment; handles trigger configuration validation, credential sets, and external provider subscriptions
apps/sim/lib/webhooks/provider-subscriptions.ts Added provider subscription functions for Grain, Lemlist, Airtable, Calendly, and Webflow with proper error handling and cleanup
apps/sim/app/api/workflows/[id]/deploy/route.ts Integrated webhook saving into deployment flow; validates and creates webhooks before workflow deployment
apps/sim/app/api/workflows/[id]/state/route.ts Moved webhook cleanup to workflow save; removes old webhook sync logic and adds external webhook cleanup for edited/deleted blocks

Sequence Diagram

sequenceDiagram
    participant User
    participant DeployModal
    participant DeployAPI
    participant WebhookDeploy
    participant ProviderAPI
    participant Database

    User->>DeployModal: Click "Deploy"
    DeployModal->>DeployAPI: POST /api/workflows/{id}/deploy
    
    DeployAPI->>WebhookDeploy: saveTriggerWebhooksForDeploy()
    
    loop For each trigger block
        WebhookDeploy->>WebhookDeploy: resolveTriggerId()
        WebhookDeploy->>WebhookDeploy: buildProviderConfig()
        WebhookDeploy->>WebhookDeploy: Validate required fields
        
        alt Has credentialSetId
            WebhookDeploy->>WebhookDeploy: syncCredentialSetWebhooks()
            WebhookDeploy->>Database: Fan out webhooks for credential set
        else Has credentialId
            WebhookDeploy->>Database: Check existing webhook
            
            alt Webhook exists & needs recreation
                WebhookDeploy->>ProviderAPI: cleanupExternalWebhook()
                ProviderAPI-->>WebhookDeploy: Cleaned up
                WebhookDeploy->>ProviderAPI: createExternalWebhookSubscription()
                ProviderAPI-->>WebhookDeploy: External ID
            end
            
            WebhookDeploy->>Database: Upsert webhook record
            
            alt Provider is Gmail/Outlook
                WebhookDeploy->>ProviderAPI: configurePolling()
            end
        end
        
        alt Error occurs
            WebhookDeploy-->>DeployAPI: Return error
            DeployAPI-->>DeployModal: Show error in UI
            DeployModal-->>User: Display error message
        end
    end
    
    WebhookDeploy-->>DeployAPI: Success
    DeployAPI->>DeployAPI: deployWorkflow()
    DeployAPI-->>DeployModal: Deployment complete
    DeployModal-->>User: Show success
Loading

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.

17 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321
Copy link
Collaborator Author

@greptile

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.

17 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

// Block still exists - check if it was edited
const newBlock = filteredBlocks[prevBlock.id]
const prevData = prevBlock.data as Record<string, unknown> | null
if (prevData && JSON.stringify(prevData) !== JSON.stringify(newBlock)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Comparing blocks with JSON.stringify will trigger webhook cleanup on every save, even for trivial changes like reordering object keys or whitespace differences. Any edit to a trigger block will delete and require re-creation of webhooks during next deploy, causing unnecessary churn.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/api/workflows/[id]/state/route.ts
Line: 212:212

Comment:
**logic:** Comparing blocks with `JSON.stringify` will trigger webhook cleanup on every save, even for trivial changes like reordering object keys or whitespace differences. Any edit to a trigger block will delete and require re-creation of webhooks during next deploy, causing unnecessary churn.

How can I resolve this? If you propose a fix, please make it concise.

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