Skip to content

Fixes #24691: Deduplicate recipients across multiple EventSubscription destinations - #25312

Merged
mohityadav766 merged 6 commits into
mainfrom
fix/notifications-global-recipient-deduplication
Jan 21, 2026
Merged

mohityadav766 merged 6 commits into
mainfrom
fix/notifications-global-recipient-deduplication

Conversation

@manerow

@manerow manerow commented Jan 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #24691

Problem

When an EventSubscription includes multiple destinations that resolve to overlapping recipients, users received duplicate notifications. For example:

Result: [email protected] received two identical emails.

Additionally, PATCH operations on EventSubscriptions with multiple destinations of the same type caused duplicate destination UUID entries to be created. This happened because the UI matched destinations by type only, leading to mismatches when multiple destinations of the same type existed.


Root Cause

Two interconnected issues:

  1. No global recipient deduplication across destinations
    Each destination resolved recipients independently, and internal deduplication only occurred within a single destination.

  2. No stable destination identifiers for PATCH operations
    Without unique IDs, the UI couldn't correctly identify which destination was being updated, leading to duplicates when patching subscriptions with multiple destinations with the exact same UUID (Which afterwards only one of them received the notification).


Solution

  1. Added unique IDs to destinations (EventSubscriptionRepository.ensureDestinationIds()):

    • Generates UUIDs for any destination missing an ID before storage
    • Ensures all operations (POST, PUT, PATCH) preserve destination identity
    • Updated ALERT_PATCH_FIELDS and ALERT_UPDATE_FIELDS to include destinations
  2. Updated UI destination matching (AlertsClassBase.ts):

    • Changed from matching by type to matching by id
    • Prevents mismatching when multiple destinations of the same type exist
  3. Modified RecipientResolver

    • Accepts multiple destinations
    • Returns a deduplicated Set<Recipient> across all destinations
  4. Updated AbstractEventConsumer.publishEvents()

    • Groups destinations by type before resolution
    • Resolves recipients once per type with deduplication via HashSet
  5. Changed Destination.sendMessage() interface

    • Receives pre-resolved recipients instead of resolving internally
  6. Updated all publishers

    • Email, Slack, MS Teams, GChat, Webhook now use provided recipients

Testing

  • Added integration tests in RecipientResolverIntegrationTest that verify:
    • test_recipientDeduplication_acrossMultipleDestinations:
      Same recipient in OWNERS + EXTERNAL destinations → receives only one notification
    • test_recipientDeduplication_withMixedOverlappingRecipients:
      Mix of overlapping and unique recipients → correctly deduplicated
  • Updated AlertPublisherTest for the new interface signature
  • All existing tests pass

Type of change

  • Bug fix
  • Improvement
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

Checklist

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

@manerow manerow self-assigned this Jan 15, 2026
@manerow
manerow requested a review from a team as a code owner January 15, 2026 08:33
@manerow manerow added safe to test Add this label to run secure Github workflows on PRs backend area:alerts-notifications Change events, event subscriptions, alerts, notification templates and channels, email. labels Jan 15, 2026
@manerow
manerow force-pushed the fix/notifications-global-recipient-deduplication branch from e3a51cc to 3cfa35f Compare January 16, 2026 08:22
@manerow
manerow force-pushed the fix/notifications-global-recipient-deduplication branch from 6c18194 to 02773f9 Compare January 19, 2026 15:51
@manerow
manerow force-pushed the fix/notifications-global-recipient-deduplication branch from 02773f9 to ee70b6c Compare January 20, 2026 08:40
@sonarqubecloud

Copy link
Copy Markdown

…te notifications

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java
…d of resolving internally

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowEventConsumer.java
@gitar-bot

gitar-bot Bot commented Jan 21, 2026 •

Copy link
Copy Markdown
🔍 CI failure analysis for 3edfb26: maven-sonarcloud-ci: IDENTICAL 53 test failures as maven-postgresql-ci (entity CRUD, data contracts, field loading). Combined analysis: all 10 CI failure categories across 14+ jobs are UNRELATED to PR's notification/alert recipient deduplication changes.

Issue

maven-sonarcloud-ci (job 60986229556) failed with 53 test failures out of 7891 tests after ~3.5 hours of execution. These are IDENTICAL to the maven-postgresql-ci failures. Combined with previous analysis, all 10 CI failure categories across 14+ jobs are UNRELATED to the PR.

Root Cause

maven-sonarcloud-ci has the exact same 53 test failures as maven-postgresql-ci, falling into three distinct categories, none connected to notification/alert recipient deduplication:

1. Bulk Loading & Field Fetchers (~40+ failures)

  • Pattern: expected: <1> but was: <0>
  • Issue: Owners/Followers fields not loaded correctly in bulk operations
  • Affected Test Classes:
    • 14 Service Resource Tests: Workflow, Dashboard, Pipeline, LLM, Ingestion, Storage, Metadata, Database, API, Security, Messaging, MlModel, Drive, Search
    • Each fails 3 tests: test_bulkLoadingEfficiency, test_fieldFetchersEfficiency, put_addFollowerDeleteEntity_200
  • Examples:
    WorkflowResourceTest>EntityResourceTest.test_bulkLoadingEfficiency:887
    Owners should be loaded consistently in bulk operations ==> expected: <1> but was: <0>
    
    StoredProcedureResourceTest.test_fieldFetchersEfficiency:6093
    Followers field should be consistently loaded ==> expected: <1> but was: <0>
    
  • Area: Entity CRUD operations and relationship loading
  • PR Scope: Notification/alert recipient resolution
  • Overlap: NONE

2. Data Contract ODCS Tests (7 failures)

  • DataContractResourceTest (5 failures):
    • Version mismatches: expected: <v3.0.2> but was: <v3.1.0>
    • Count mismatches: testODCSRoundTrip → expected: <3> but was: <1>
  • ODCSConverterTest (2 failures):
    • testFromODCS_WithQualityRules → expected: not <null>
    • testToODCS_WithQualityRulesInExtension → count mismatch
  • Area: Data contract export/import and versioning
  • PR Scope: Notification/alert recipient resolution
  • Overlap: NONE

3. Miscellaneous Entity Tests (6 failures)

  • ChartResourceTest.testChartWithDashboards → expected: <true> but was: <false>
  • DashboardResourceTest.get_entityIncludeDeleted_200 → expected: <3> but was: <0>
  • TestCaseResourceTest.post_delete_entityWithOwner_200 → expected: <true> but was: <false>
  • Area: Various entity CRUD operations
  • PR Scope: Notification/alert recipient resolution
  • Overlap: NONE

Infrastructure Issues

  • Multiple java.lang.InterruptedException in Disruptor threads (same as maven-postgresql-ci)
  • Test environment instability

Details

Key Observation: Both maven-postgresql-ci and maven-sonarcloud-ci show IDENTICAL test failures. This strongly suggests:

  1. The failures are NOT database-specific (both PostgreSQL and default MySQL fail)
  2. The failures are pre-existing or environmental issues
  3. The failures have NO connection to notification/alert code changes

PR Changes:

  • Modified: AbstractEventConsumer.java, RecipientResolver.java, Alert/Email/Slack/Teams/GChat publishers
  • Purpose: Deduplicate notification recipients across EventSubscription destinations
  • Scope: Event subscription and notification system ONLY

Failing Tests:

  • Area: Entity relationship loading, data contract conversions, CRUD operations
  • Scope: Core entity management, data contracts, resource operations
  • No intersection with notification/alert code paths

Complete CI Failure Summary (10 categories, 14+ jobs):

Category Failures Status
maven-postgresql-ci 53 tests (entity CRUD, data contracts) UNRELATED
maven-sonarcloud-ci 53 tests (IDENTICAL to postgresql) UNRELATED
Playwright (2 shards) 3 hard + 16 flaky (UI E2E) UNRELATED
Python tests Systematic SFTP failure UNRELATED
Frontend tests Test mock infrastructure UNRELATED
Integration tests OpenSearch disk, user filter UNRELATED
External workflows CI pipeline UNRELATED

PR modifies: Backend Java notification/alert recipient resolution

Failures involve: Entity CRUD, field loading, data contracts, UI E2E tests, Python ingestion, test infrastructure

Overlap: NONE

Code Review ✅ Approved 3 resolved / 5 findings

Well-structured deduplication fix that correctly addresses duplicate notification issues while preserving destination-specific configurations in Recipient objects.

Suggestions 💡 2 suggestions
Edge Case: extractActionConfig silently returns null for unknown types

📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/recipients/RecipientResolver.java

The extractActionConfig method returns null for the default case in the switch statement. This could lead to NullPointerException if a new SubscriptionType is added in the future but not handled here. While ACTIVITY_FEED and GOVERNANCE_WORKFLOW_CHANGE_EVENT are filtered out earlier, any new type would silently fail.

Suggested fix: Either log a warning for unknown types, throw an exception, or ensure comprehensive handling of all enum values:

default -> {
  LOG.warn("Unknown destination type: {}", destination.getType());
  return null;
}
Performance: RecipientResolver instantiated on every sendAlert call

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AlertPublisher.java

A new RecipientResolver instance is created on every sendAlert() invocation. Since RecipientResolver appears to be stateless (it only contains static strategy mappings), creating a new instance per call is unnecessary overhead.

Suggested fix: Make RecipientResolver a singleton or inject it via dependency injection, or instantiate it once as a field in AlertPublisher.

Resolved ✅ 3 resolved
Bug: Different destination configs for same type are merged, first used

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java:243-277 📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java
When multiple destinations of the same type (e.g., two different EMAIL destinations with different configurations) are present, the code groups them together and:

  1. Resolves recipients from ALL destinations (correctly deduplicating recipients)
  2. But uses only destinations.getFirst() to send the message (line 53)

This means if you have:

  • Destination 1: EMAIL with template A, endpoint A
  • Destination 2: EMAIL with template B, endpoint B

Recipients from both are merged (good for deduplication), but only Destination 1's publisher sends the message. Destination 2's specific configuration (different template, different format, etc.) is completely ignored.

Suggested fix: The deduplication should occur at the recipient level, but each destination should still send its own message with its own configuration. Consider:

  1. Resolving recipients per destination (not merged)
  2. Track which recipients have already been notified
  3. Skip sending to recipients already notified by an earlier destination of the same type

Or document this as expected behavior if destinations of the same type are intended to be deduplicated entirely.

Bug: Only first destination used per type, ignoring other configurations

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java:246-255
In AbstractEventConsumer.publishEvents(), when destinations are grouped by type, only the first destination in each group is used to send messages:

Destination<ChangeEvent> publisher = destinations.get(0);

This means if there are multiple destinations of the same type (e.g., two different Slack webhooks for different channels), only the first one will actually send messages. The other destinations' configurations (like different webhook URLs) will be ignored.

While recipients are correctly deduplicated across all destinations, the actual sending only uses one publisher instance. For webhook-based destinations (Slack, Teams, GChat, Generic), this could result in messages only going to one webhook endpoint instead of all configured endpoints.

Suggested Fix: Either:

  1. Iterate through all destinations in the group and send to each
  2. Aggregate all webhook endpoints from destinations of the same type and send to all of them
  3. Or document this as intended behavior if deduplication is meant to be across all configurations
Bug: Grouping by type may send same message to only one destination

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java
The publishEvents() method groups destinations by SubscriptionType and then uses only the first destination (destinations.get(0)) as the publisher for all deduplicated recipients. This is problematic because different destinations of the same type (e.g., two different Slack webhooks) may have different configurations, webhook URLs, or message templates.

For example, if there are two Slack destinations:

  • Destination 1: webhook-A with template-A
  • Destination 2: webhook-B with template-B

The current code will:

  1. Group both under SLACK type
  2. Deduplicate recipients across both
  3. Use only Destination 1's publisher to send to ALL recipients

This means recipients that should receive messages from webhook-B with template-B will instead receive messages from webhook-A with template-A. The deduplication should only apply within the same effective notification channel, not across different webhook endpoints.

Suggested fix: Either deduplicate recipients per destination (not per type), or ensure the grouping accounts for webhook endpoint/configuration differences.

What Works Well

Clean architectural refactor moving recipient resolution from individual publishers to a centralized location. Comprehensive integration tests verify deduplication works across multiple destinations. Good use of requiresRecipients() to handle publishers that don't need recipient resolution.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

Options

Auto-apply is off Gitar will not commit updates to this branch.
Display: compact Hiding non-applicable rules.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | This comment will update automatically (Docs)

This branch was previously deployed

1 inactive deployment
test — 3edfb26a Deployed Jan 21, 2026 by manerow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:alerts-notifications Change events, event subscriptions, alerts, notification templates and channels, email. backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notifications Missing Global Recipient Deduplication

3 participants