sim icon indicating copy to clipboard operation
sim copied to clipboard

feat(error-notifications): workspace-level configuration of slack, email, webhook notifications for workflow execution

Open icecrasher321 opened this issue 2 months ago • 2 comments

Summary

Adds multi-channel notifications for workflow executions with alerting capabilities.

  • New notification configuration UI in Logs page (3-dot menu → Configure Notifications)
  • Migrated legacy per-workflow webhooks to workspace-scoped system
  • Added 1-hour cooldown for alert notifications to prevent spam
  • Limits: 10 notifications per type, 10 email recipients max (to not have people exploit)

Alerts system

Consecutive failures: Alert after X failures in a row (resets on success) Failure rate: Alert when error rate exceeds X% over Y hours (requires full window of data)

Type of Change

  • [x] New feature

Testing

IN PROGRESS

Checklist

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

icecrasher321 avatar Dec 02 '25 03:12 icecrasher321

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

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Dec 5, 2025 1:58am

vercel[bot] avatar Dec 02 '25 03:12 vercel[bot]

Greptile Overview

Greptile Summary

This PR implements a comprehensive migration from per-workflow webhook notifications to a workspace-level multi-channel notification system. The changes introduce support for webhook, email, and Slack notifications for workflow executions with sophisticated alerting rules including consecutive failure detection and failure rate monitoring. The new system includes a 1-hour cooldown mechanism to prevent notification spam and enforces limits of10 notifications per type with a maximum of 10 email recipients.

Key architectural changes include removing the legacy workflowLogWebhook tables and replacing them with new workspaceNotificationSubscription and workspaceNotificationDelivery tables. The notification configuration is now centralized in the Logs page UI (accessible via 3-dot menu → Configure Notifications) rather than being scattered across individual workflow settings. The implementation includes a new background task system for reliable notification delivery with retry mechanisms, proper webhook signature verification, and comprehensive payload formatting for each notification channel.

Important Files Changed

Filename Score Overview
packages/db/migrations/0116_huge_ma_gnuci.sql 4/5 Creates new workspace notification tables and migrates existing webhook data
packages/db/schema.ts 4/5 Refactors database schema from workflow webhooks to workspace notifications
apps/sim/background/workspace-notification-delivery.ts 4/5 New background task for multi-channel notification delivery with retry logic
apps/sim/app/api/workspaces/[id]/notifications/route.ts 4/5 API endpoints for creating and fetching workspace notification subscriptions
apps/sim/app/api/workspaces/[id]/notifications/[notificationId]/route.ts 4/5 CRUD operations for individual notification subscription management
apps/sim/app/api/workspaces/[id]/notifications/[notificationId]/test/route.ts 4/5 Testing endpoint for validating notification configurations
apps/sim/app/api/auth/accounts/route.ts 4/5 Fetches OAuth accounts for notification provider integration
apps/sim/hooks/use-slack-accounts.ts 3/5 Custom hook for managing Slack account data with incomplete error handling
apps/docs/content/docs/en/execution/api.mdx 4/5 Documentation updates for new notification system features
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/webhook-settings/webhook-settings.tsx 5/5 Legacy webhook settings component removed as part of migration

Confidence score: 3/5

  • This PR introduces complex architectural changes with potential for integration issues and data migration risks
  • Score reflects concerns about missing TSDoc documentation, incomplete error handling in hooks, and the complexity of migrating legacy webhook data without comprehensive testing coverage
  • Pay close attention to the database migration file, notification delivery background task, and the new API endpoints for proper error handling and data validation

Sequence Diagram

sequenceDiagram
    participant User
    participant LogsPage as "Logs Page"
    participant NotificationSettings as "Notification Settings Modal"
    participant WorkspaceAPI as "Workspace Notifications API"
    participant Database as "Database"
    participant EventSystem as "Log Event System"
    participant DeliveryTask as "Notification Delivery Task"
    participant ExternalService as "External Service (Webhook/Email/Slack)"

    User->>LogsPage: "Click 3-dot menu → Configure Notifications"
    LogsPage->>NotificationSettings: "Open notification settings modal"
    NotificationSettings->>WorkspaceAPI: "GET /api/workspaces/{id}/notifications"
    WorkspaceAPI->>Database: "Query existing notification subscriptions"
    Database-->>WorkspaceAPI: "Return subscription list"
    WorkspaceAPI-->>NotificationSettings: "Return existing notifications"
    
    User->>NotificationSettings: "Configure new notification (webhook/email/slack)"
    User->>NotificationSettings: "Set alert rules (consecutive failures/failure rate)"
    User->>NotificationSettings: "Select workflows and filters"
    NotificationSettings->>WorkspaceAPI: "POST /api/workspaces/{id}/notifications"
    WorkspaceAPI->>Database: "Insert workspace notification subscription"
    Database-->>WorkspaceAPI: "Return created subscription"
    WorkspaceAPI-->>NotificationSettings: "Return success response"
    
    Note over EventSystem: "When workflow execution completes with error"
    EventSystem->>Database: "Query matching notification subscriptions"
    Database-->>EventSystem: "Return active subscriptions for workspace"
    EventSystem->>EventSystem: "Check alert conditions (consecutive failures/failure rate)"
    EventSystem->>Database: "Update lastAlertAt if alert triggered"
    EventSystem->>Database: "Insert notification delivery record"
    EventSystem->>DeliveryTask: "Trigger notification delivery task"
    
    DeliveryTask->>Database: "Claim delivery record"
    DeliveryTask->>DeliveryTask: "Build notification payload with execution details"
    
    alt Webhook Notification
        DeliveryTask->>ExternalService: "POST webhook with HMAC signature"
        ExternalService-->>DeliveryTask: "HTTP response"
    else Email Notification
        DeliveryTask->>ExternalService: "Send formatted email"
        ExternalService-->>DeliveryTask: "Email delivery status"
    else Slack Notification
        DeliveryTask->>ExternalService: "Post message to Slack channel"
        ExternalService-->>DeliveryTask: "Slack API response"
    end
    
    DeliveryTask->>Database: "Update delivery status (success/failed)"
    
    Note over DeliveryTask: "If delivery fails, retry with exponential backoff"
    alt Delivery Failed
        DeliveryTask->>Database: "Schedule retry with backoff delay"
        DeliveryTask->>DeliveryTask: "Wait for retry window"
        DeliveryTask->>ExternalService: "Retry delivery (up to 5 attempts)"
    end

greptile-apps[bot] avatar Dec 02 '25 03:12 greptile-apps[bot]