Skip to content

fix(triggers-persistence): triggers persistence, deletion, updating configs + state management simplifcation - #1783

Merged
icecrasher321 merged 2 commits into
stagingfrom
fix/trigger-config-persistence
Nov 1, 2025
Merged

fix(triggers-persistence): triggers persistence, deletion, updating configs + state management simplifcation#1783
icecrasher321 merged 2 commits into
stagingfrom
fix/trigger-config-persistence

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

Collaborative edits of trigger config + persistence of webhook rows and cleanups associated with failures.

Type of Change

  • Bug fix

Testing

Tested with @waleedlatif1

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

vercelBot commented Nov 1, 2025

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 1, 2025 0:52am

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Fixes trigger webhook persistence and collaborative editing synchronization. The PR introduces webhook deletion rollback for Gmail/Outlook configuration failures and adds collaborative state sync after successful saves.

Key Changes

  • Webhook rollback: API now deletes webhook records from DB if Gmail/Outlook polling configuration fails, preventing orphaned records
  • Collaborative sync: Trigger save now broadcasts webhook state to collaborators using collaborativeSetSubblockValue()
  • State management refactor: Replaces computed useMemo with subscribed Zustand selectors for better reactivity
  • Code cleanup: Extracts resolveEffectiveTriggerId() helper and removes unused isMounted tracking

Issues Found

  • Critical bug in trigger-save.tsx:231-234: Throwing error when saveConfig() returns false will skip collaborative state updates on lines 239-247, causing state desync between local store and collaborators when the API successfully rolls back a failed webhook

Confidence Score: 2/5

  • Critical bug in error handling will cause state desync in collaborative environments
  • The webhook rollback logic is solid, but throwing on saveConfig() failure skips the collaborative state sync that should propagate the deletion to other users. This creates a race condition where collaborators see stale webhook IDs while the DB has been rolled back.
  • trigger-save.tsx lines 231-234 must be fixed before merging - the error handling logic will cause collaborative state desync

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/app/api/webhooks/route.ts4/5Adds webhook deletion rollback on Gmail/Outlook configuration failures - improves error handling and prevents orphaned DB records
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/trigger-save/trigger-save.tsx2/5Refactors state management and adds collaborative sync - but contains critical bug where throwing on saveConfig() failure skips state updates causing desync
apps/sim/hooks/use-webhook-management.ts4/5Extracts resolveEffectiveTriggerId function for reusability and simplifies loading logic - cleaner code with no functional changes

Sequence Diagram

sequenceDiagram
participant User
participant TriggerSave
participant WebhookHook
participant API
participant DB
participant Collaborative
User->>TriggerSave: Click Save
TriggerSave->>TriggerSave: Aggregate config from subblocks
TriggerSave->>TriggerSave: Validate required fields
TriggerSave->>WebhookHook: saveConfig()
alt Create New Webhook
WebhookHook->>API: POST /api/webhooks
API->>API: Save webhook to DB
alt Provider is Gmail/Outlook
API->>API: configureGmailPolling() or configureOutlookPolling()
alt Configuration Fails
API->>DB: DELETE webhook (rollback)
API-->>WebhookHook: Error response
WebhookHook-->>TriggerSave: false
TriggerSave->>TriggerSave: Throw error (BUG: skips state sync)
end
end
API-->>WebhookHook: Success with webhook ID
WebhookHook->>WebhookHook: Update local state
WebhookHook-->>TriggerSave: true
else Update Existing Webhook
WebhookHook->>API: PATCH /api/webhooks/{id}
API-->>WebhookHook: Success
WebhookHook-->>TriggerSave: true
end
TriggerSave->>TriggerSave: Read saved values from store
TriggerSave->>Collaborative: collaborativeSetSubblockValue() x4
Collaborative->>Collaborative: Sync to other users
TriggerSave->>User: Show success message
Loading

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321
icecrasher321 merged commit 44271cd into stagingNov 1, 2025
9 checks passed
@icecrasher321
icecrasher321 deleted the fix/trigger-config-persistence branch November 1, 2025 01:06
waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
…onfigs + state management simplifcation (#1783)
* fix(triggers): configuration persistences issues
* required fields validation staleness issue
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto 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.

1 participant

@icecrasher321