Skip to content

ref(notifications): Use explicit origins for notification rendering - #126529

Merged
kcons merged 7 commits into
masterfrom
kcons/stepone
Oct 6, 2026
Merged

kcons merged 7 commits into
masterfrom
kcons/stepone

Conversation

@kcons

@kcons kcons commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Introduce NotificationOrigin to represent the workflow (or for a time longer, rule) that caused a notification
so we don't have to keep using Rule.

NotificationOrigin is much more constrained and specific, allowing us to replace some of the subtler Rule hacks with explicit choices.

Fixes ISWF-3560.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 5, 2026
@sentry

sentry Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 588 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

@kcons
kcons added this pull request to stack #126600 October 6, 2026 16:24
@kcons
kcons marked this pull request as ready for review October 6, 2026 18:47
@kcons
kcons requested review from a team as code owners October 6, 2026 18:47

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 067bde9. Configure here.

Comment thread src/sentry/notifications/types.py Resolved
kcons added 6 commits October 6, 2026 14:00
Construct workflow-backed notification origins explicitly so a null workflow environment overrides any environment stored on the linked legacy rule.
Keep serializing the proxy ID in the legacy rules field while NotificationOrigin replaces synthetic Rule objects in rendering. The workflow-only payload transition remains isolated to the follow-up integration PR.
@kcons
kcons requested a review from hobzcalvin October 6, 2026 21:31
Comment thread src/sentry/notifications/types.py Outdated
Comment on lines +27 to +41
embedded_workflow_id = first_action.get("workflow_id")
embedded_legacy_rule_id = first_action.get("legacy_rule_id")

if embedded_workflow_id is not None:
embedded_workflow_id = int(embedded_workflow_id)
if embedded_legacy_rule_id is not None:
embedded_legacy_rule_id = int(embedded_legacy_rule_id)

if embedded_legacy_rule_id is not None:
legacy_rule_id = embedded_legacy_rule_id
elif embedded_workflow_id is not None:
legacy_rule_id = None
else:
legacy_rule_id = rule.id

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.

nit: the logic here seems more drawn out than it needs to be, though I don't have a specific rewrite in mind.

Comment thread src/sentry/digests/notifications.py Resolved
Comment thread src/sentry/digests/notifications.py Resolved
Comment thread src/sentry/notifications/utils/links.py Resolved
Comment thread src/sentry/notifications/utils/rules.py Resolved
Share legacy identity parsing between persisted rules and serialized payloads, document transitional origin IDs, and avoid unrelated naming and query-shape changes.
@kcons
kcons merged commit d2896b0 into master Oct 6, 2026
71 checks passed
@kcons
kcons deleted the kcons/stepone branch October 6, 2026 22:44
kcons added a commit that referenced this pull request Oct 15, 2026
First of two steps to reduce `SerializableRuleProxy` to a serializable
`NotificationOrigin`. Its only consumer is `to_notification_origin()`
(Slack/Discord/MS Teams issue renderers).

**Changes**
- Remove the `from_legacy_data` fallback in `to_notification_origin()`.
It only covered `notify_target_async` payloads serialized before #126529
(merged 10-06) put `workflow_id`/`legacy_rule_id` at the top level.
Those tasks should have drained by now.
- Remove `NotificationOrigin.from_legacy_data` from prod code; its
parsing now lives only in the `create_notification_origin` test helper.
- `NotificationOrigin.__post_init__` logs
`notifications.origin.missing_identity` (warning, with stack) when both
`workflow_id` and `legacy_rule_id` are `None`. `identifier`/`link_id`
depend on at least one being set, so this points at the producer instead
of only failing at the later assert.
- Make `id`, `data`, and `project_id` optional. Nothing reads them
anymore, but producers still populate them because workers on the
previous release require them.
- Replace `model_config = ConfigDict(frozen=True)` with `class Config:
frozen = True`. On pydantic 1.10, `model_config` is treated as an
ordinary field: the model wasn't actually frozen, and every serialized
payload carried `"model_config": {"frozen": true}`. Parsing stays
compatible in both directions: extra keys are ignored, and old workers
fall back to the field default.

**Follow-up (after this deploys)**
Stop populating and delete `id`/`data`/`project_id`, then remove
`from_action_context` and the `build_rule_data_from_action` call in
`issue_notification_data_factory`.

**Testing**
- Every test file using
`create_notification_origin`/`create_notification_action_context`, plus
`tests/sentry/notifications/platform/` and
`tests/sentry/notifications/notification_action/`: 959 passed. 3
order-dependent failures under xdist
(`msteams/test_action_state_change.py`,
`slack/notifications/test_issue_alert.py`) pass when those files run on
their own, on master and on this branch.
- After the logging change: `tests/sentry/notifications/`,
`tests/sentry/digests/`, and the Slack/MS Teams message builder tests
pass, apart from Redis Cluster tests that need a cluster not running
locally and one xdist-only flake (`test_get_context_users_affected`)
that passes on its own.
- `prek run` + pre-push mypy on changed files: pass
- Tests that relied on the legacy fallback now pass explicit identities.
The two legacy-deserialization tests are replaced with tests for frozen
behavior and parsing a previous-release payload. New test covers the
missing-identity log.

<!-- junior-request-attribution:start -->
via @kcons.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0BT0DUS6SX%3A1792088281.199639 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0BT0DUS6SX%3A1792088281.199639)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0BT0DUS6SX%3A1792088281.199639/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Kyle Consalus <6990351+kcons@users.noreply.github.com>
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.

2 participants