Skip to content

fix(notifications): use regression event data instead of stale group metadata#115871

Draft
sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/regression-notification-use-regression-event
Draft

fix(notifications): use regression event data instead of stale group metadata#115871
sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/regression-notification-use-regression-event

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 20, 2026

Problem

When an issue regresses, both email and Slack notifications show the original issue's error message instead of the event that actually triggered the regression.

For example:

  • Issue originally triggered by ValueError: missing field 'name'
  • Issue gets resolved
  • New event ValueError: timeout connecting to database triggers regression
  • Notification shows ValueError: missing field 'name'wrong

This was reported by a customer: "the original message from an issue gets posted over and over again even though the latest issue in an issue group is a totally different one."

Root Cause

Two compounding issues:

  1. RegressionActivityNotification ignores the regression event — the Activity.data stores event_id but the notification code never reads it. All downstream renderers fall back to group-level metadata.
  2. Notification fires before group metadata is updated_handle_regression triggers the async notification, then _process_existing_aggregate updates metadata via buffer_incr (also async). The notification task reads stale group data.

Fix

  • Load the regression event from activity.data['event_id'] in RegressionActivityNotification.__init__ using eventstore.backend.get_event_by_id()
  • Override build_attachment_title and get_title_link to use the regression event when available
  • Pass event to email template context via get_group_context override
  • Update _group.html to prefer event metadata over group metadata when present (backwards-compatible via |default filter)
  • Graceful fallback: if event lookup fails (deleted, unavailable), falls back to existing group-based behavior

Changes

File Change
src/sentry/notifications/notifications/activity/regression.py Load regression event, override title/link/context methods
src/sentry/templates/sentry/emails/_group.html Prefer event metadata when available
tests/.../slack/notifications/test_regression.py Add tests for regression event metadata usage and fallback

Testing

  • test_regression_uses_regression_event_metadata — verifies Slack notification shows regression event's error message
  • test_regression_without_event_id_falls_back_to_group — verifies graceful fallback when no event_id present
  • All existing regression notification tests remain unchanged

Requested-by: Daniel Griesser daniel@sentry.io

…metadata

When an issue regresses, the notification (Slack and email) was showing
the original issue's error message instead of the event that triggered
the regression. This happened because:

1. RegressionActivityNotification never loaded the regression event,
   even though Activity.data stores the event_id
2. The notification fires before group metadata is updated via
   buffer_incr, so even group-level data was stale

Fix:
- Load the regression event from activity.data['event_id'] in
  RegressionActivityNotification.__init__
- Override build_attachment_title and get_title_link to use the
  regression event when available
- Pass event to email template context via get_group_context override
- Update _group.html to prefer event metadata over group metadata
  when an event is present (backwards-compatible via |default filter)
- Graceful fallback: if event lookup fails, falls back to existing
  group-based behavior

Fixes: regression notifications showing original error message instead
of the error that caused the regression
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants