feat(ecosystem): Implement cross-system issue synchronization
Tier 2 easy python · local · real merged PR from getsentry/sentry #77754
Ground-truth defects
Shared mutable default in dataclass timestamp
The change under review
diff
@@ -12,6 +12,7 @@ from typing import Any, ClassVar from sentry.eventstore.models import GroupEvent from sentry.integrations.base import IntegrationInstallation from sentry.integrations.models.external_issue import ExternalIssue +from sentry.integrations.services.assignment_source import AssignmentSource from sentry.integrations.services.integration import integration_service from sentry.integrations.tasks.sync_status_inbound import ( sync_status_inbound as sync_status_inbound_task, @@ -62,7 +63,7 @@ class ResolveSyncAction(enum.Enum): class IssueBasicIntegration(IntegrationInstallation, ABC): - def should_sync(self, attribute): + def should_sync(self, attribute, sync_source: AssignmentSource | None = None): return False def get_group_title(self, group, event, **kwargs): @@ -378,10 +379,17 @@ class IssueSyncIntegration(IssueBasicIntegration, ABC): outbound_assignee_key: ClassVar[str | None] = None inbound_assignee_key: ClassVar[str | None] = None - def should_sync(self, attribute: str) -> bool: + def should_sync(self, attribute: str, sync_source: AssignmentSource | None = None) -> bool: key = getattr(self, f"{attribute}_key", None) if key is None or self.org_integration is None: return False + + # Check that the assignment source isn't this same integration in order to + # prevent sync-cycles from occurring. This should still allow other + # integrations to propagate changes outward. + if sync_source and sync_source.integration_id == self.org_integration.integration_id: + return False + value: bool = self.org_integration.config.get(key, False) return value @@ -400,7 +408,14 @@ class IssueSyncIntegration(IssueBasicIntegration, ABC): raise NotImplementedError @abstractmethod - def sync_status_outbound(self, external_issue, is_resolved, project_id, **kwargs): + def sync_status_outbound( + self, + external_issue, + is_resolved, + project_id, + assignment_source: AssignmentSource | None = None, + **kwargs, + ): """ Propagate a sentry issue's status to a linked issue's status. """ new file mode 100644 @@ -0,0 +1,35 @@ +from __future__ import annotations + +from dataclasses import asdict, dataclass +from datetime import datetime +from typing import TYPE_CHECKING, Any + +from django.utils import timezone + +if TYPE_CHECKING: + from sentry.integrations.models import Integration + from sentry.integrations.services.integration import RpcIntegration + + +@dataclass(frozen=True) +class AssignmentSource: + source_name: str + integration_id: int + queued: datetime = timezone.now() + + @classmethod + def from_integration(cls, integration: Integration | RpcIntegration) -> AssignmentSource: + return AssignmentSource( + source_name=integration.name, + integration_id=integration.id, + ) + + def to_dict(self) -> dict[str, Any]: + return asdict(self) + + @classmethod + def from_dict(cls, input_dict: dict[str, Any]) -> AssignmentSource | None: + try: + return cls(**input_dict) + except (ValueError, TypeError): + return None @@ -1,6 +1,9 @@ +from typing import Any + from sentry import analytics, features from sentry.integrations.models.external_issue import ExternalIssue from sentry.integrations.models.integration import Integration +from sentry.integrations.services.assignment_source import AssignmentSource from sentry.integrations.services.integration import integration_service from sentry.models.organization import Organization from sentry.silo.base import SiloMode @@ -24,7 +27,12 @@ from sentry.users.services.user.service import user_service Organization.DoesNotExist, ) ) -def sync_assignee_outbound(external_issue_id: int, user_id: int | None, assign: bool) -> None: +def sync_assignee_outbound( + external_issue_id: int, + user_id: int | None, + assign: bool, + assignment_source_dict: dict[str, Any] | None = None, +) -> None: # Sync Sentry assignee to an external issue. external_issue = ExternalIssue.objects.get(id=external_issue_id) @@ -42,10 +50,15 @@ def sync_assignee_outbound(external_issue_id: int, user_id: int | None, assign: ): return - if installation.should_sync("outbound_assignee"): + parsed_assignment_source = ( + AssignmentSource.from_dict(assignment_source_dict) if assignment_source_dict else None + ) + if installation.should_sync("outbound_assignee", parsed_assignment_source): # Assume unassign if None. user = user_service.get_user(user_id) if user_id else None - installation.sync_assignee_outbound(external_issue, user, assign=assign) + installation.sync_assignee_outbound( + external_issue, user, assign=assign, assignment_source=parsed_assignment_source + ) analytics.record( "integration.issue.assignee.synced", provider=integration.provider, @@ -5,6 +5,7 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING from sentry import features +from sentry.integrations.services.assignment_source import AssignmentSource from sentry.integrations.services.integration import integration_service from sentry.integrations.tasks.sync_assignee_outbound import sync_assignee_outbound from sentry.models.group import Group @@ -92,7 +93,11 @@ def sync_group_assignee_inbound( if not assign: for group in affected_groups: - GroupAssignee.objects.deassign(group) + GroupAssignee.objects.deassign( + group, + assignment_source=AssignmentSource.from_integration(integration), + ) + return affected_groups users = user_service.get_many_by_email(emails=[email], is_verified=True) @@ -104,14 +109,23 @@ def sync_group_assignee_inbound( user_id = get_user_id(projects_by_user, group) user = users_by_id.get(user_id) if user: - GroupAssignee.objects.assign(group, user) + GroupAssignee.objects.assign( + group, + user, + assignment_source=AssignmentSource.from_integration(integration), + ) groups_assigned.append(group) else: logger.info("assignee-not-found-inbound", extra=log_context) return groups_assigned -def sync_group_assignee_outbound(group: Group, user_id: int | None, assign: bool = True) -> None: +def sync_group_assignee_outbound( + group: Group, + user_id: int | None, + assign: bool = True, + assignment_source: AssignmentSource | None = None, +) -> None: from sentry.models.grouplink import GroupLink external_issue_ids = GroupLink.objects.filter( @@ -120,5 +134,12 @@ def sync_group_assignee_outbound(group: Group, user_id: int | None, assign: bool for external_issue_id in external_issue_ids: sync_assignee_outbound.apply_async( - kwargs={"external_issue_id": external_issue_id, "user_id": user_id, "assign": assign} + kwargs={ + "external_issue_id": external_issue_id, + "user_id": user_id, + "assign": assign, + "assignment_source_dict": assignment_source.to_dict() + if assignment_source + else None, + } ) @@ -12,6 +12,7 @@ from sentry.backup.scopes import RelocationScope from sentry.db.models import FlexibleForeignKey, Model, region_silo_model, sane_repr from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey from sentry.db.models.manager.base import BaseManager +from sentry.integrations.services.assignment_source import AssignmentSource from sentry.models.grouphistory import GroupHistoryStatus, record_group_history from sentry.models.groupowner import GroupOwner from sentry.models.groupsubscription import GroupSubscription @@ -134,6 +135,7 @@ class GroupAssigneeManager(BaseManager["GroupAssignee"]): create_only: bool = False, extra: dict[str, str] | None = None, force_autoassign: bool = False, + assignment_source: AssignmentSource | None = None, ): from sentry.integrations.utils import sync_group_assignee_outbound from sentry.models.activity import Activity @@ -187,7 +189,9 @@ class GroupAssigneeManager(BaseManager["GroupAssignee"]): if assignee_type == "user" and features.has( "organizations:integrations-issue-sync", group.organization, actor=acting_user ): - sync_group_assignee_outbound(group, assigned_to.id, assign=True) + sync_group_assignee_outbound( + group, assigned_to.id, assign=True, assignment_source=assignment_source + ) if not created: # aka re-assignment self.remove_old_assignees(group, assignee, assigned_to_id, assignee_type) @@ -200,6 +204,7 @@ class GroupAssigneeManager(BaseManager["GroupAssignee"]): acting_user: User | RpcUser | None = None, assigned_to: Team | RpcUser | None = None, extra: dict[str, str] | None = None, + assignment_source: AssignmentSource | None = None, ) -> None: from sentry.integrations.utils import sync_group_assignee_outbound from sentry.models.activity import Activity @@ -230,7 +235,9 @@ class GroupAssigneeManager(BaseManager["GroupAssignee"]): if features.has( "organizations:integrations-issue-sync", group.organization, actor=acting_user ): - sync_group_assignee_outbound(group, None, assign=False) + sync_group_assignee_outbound( + group, None, assign=False, assignment_source=assignment_source + ) issue_unassigned.send_robust( project=group.project, group=group, user=acting_user, sender=self.__class__ new file mode 100644 @@ -0,0 +1,38 @@ +from typing import Any + +from sentry.integrations.services.assignment_source import AssignmentSource +from sentry.testutils.cases import TestCase + + +class TestAssignmentSource(TestCase): + def test_from_dict_empty_array(self): + data: dict[str, Any] = {} + result = AssignmentSource.from_dict(data) + assert result is None + + def test_from_dict_inalid_data(self): + data = { + "foo": "bar", + } + + result = AssignmentSource.from_dict(data) + assert result is None + + def test_from_dict_valid_data(self): + data = {"source_name": "foo-source", "integration_id": 123} + + result = AssignmentSource.from_dict(data) + assert result is not None + assert result.source_name == "foo-source" + assert result.integration_id == 123 + + def test_to_dict(self): + source = AssignmentSource( + source_name="foo-source", + integration_id=123, + ) + + result = source.to_dict() + assert result.get("queued") is not None + assert result.get("source_name") == "foo-source" + assert result.get("integration_id") == 123 @@ -4,6 +4,7 @@ import pytest from sentry.integrations.example.integration import ExampleIntegration from sentry.integrations.models.external_issue import ExternalIssue +from sentry.integrations.services.assignment_source import AssignmentSource from sentry.integrations.utils import sync_group_assignee_inbound from sentry.models.activity import Activity from sentry.models.groupassignee import GroupAssignee @@ -148,12 +149,77 @@ class GroupAssigneeTestCase(TestCase): with self.feature({"organizations:integrations-issue-sync": True}): with self.tasks(): - GroupAssignee.objects.assign(self.group, self.user) + GroupAssignee.objects.assign( + self.group, + self.user, + ) mock_sync_assignee_outbound.assert_called_with( - external_issue, user_service.get_user(self.user.id), assign=True + external_issue, + user_service.get_user(self.user.id), + assign=True, + assignment_source=None, + ) + + assert GroupAssignee.objects.filter( + project=self.group.project, + group=self.group, + user_id=self.user.id, + team__isnull=True, + ).exists() + + activity = Activity.objects.get( + project=self.group.project, group=self.group, type=ActivityType.ASSIGNED.value + ) + + assert activity.data["assignee"] == str(self.user.id) + assert activity.data["assigneeEmail"] == self.user.email + assert activity.data["assigneeType"] == "user" + + @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") + def test_assignee_sync_outbound_assign_with_matching_source_integration( + self, mock_sync_assignee_outbound + ): + group = self.group + integration = self.create_integration( + organization=group.organization, + external_id="123456", + provider="example", + oi_params={ + "config": { + "sync_comments": True, + "sync_status_outbound": True, + "sync_status_inbound": True, + "sync_assignee_outbound": True, + "sync_assignee_inbound": True, + } + }, + ) + + external_issue = ExternalIssue.objects.create( + organization_id=group.organization.id, integration_id=integration.id, key="APP-123" + ) + + GroupLink.objects.create( + group_id=group.id, + project_id=group.project_id, + linked_type=GroupLink.LinkedType.issue, + linked_id=external_issue.id, + relationship=GroupLink.Relationship.references, + ) + + with self.feature({"organizations:integrations-issue-sync": True}): + with self.tasks(): + # Assert that we don't perform an outbound assignment if + # the source of the assignment is the same target integration + GroupAssignee.objects.assign( + self.group, + self.user, + assignment_source=AssignmentSource.from_integration(integration), ) + mock_sync_assignee_outbound.assert_not_called() + assert GroupAssignee.objects.filter( project=self.group.project, group=self.group, @@ -205,7 +271,9 @@ class GroupAssigneeTestCase(TestCase): with self.feature({"organizations:integrations-issue-sync": True}): with self.tasks(): GroupAssignee.objects.deassign(self.group) - mock_sync_assignee_outbound.assert_called_with(external_issue, None, assign=False) + mock_sync_assignee_outbound.assert_called_with( + external_issue, None, assign=False, assignment_source=None + ) assert not GroupAssignee.objects.filter( project=self.group.project,
Leaderboard for this case
easy · 8 of 9 bots fully caught it (89% solve rate) · 89% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Cubic | solved | 1/1 | 100.0% | 1 | 0 |
| 2 | cursor | solved | 1/1 | 100.0% | 1 | 0 |
| 3 | Drape (Deep Review) | solved | 1/1 | 100.0% | 1 | 0 |
| 4 | Drape (Review) | solved | 1/1 | 100.0% | 1 | 0 |
| 5 | greptile | solved | 1/1 | 100.0% | 1 | 0 |
| 6 | Mjolnir (Opus 5.5) | solved | 1/1 | 100.0% | 2 | 0 |
| 7 | Claude Code (Opus 5.5) | solved | 1/1 | 100.0% | 2 | 1 |
| 8 | Mjolnir (Sonnet 5.5) | solved | 1/1 | 100.0% | 2 | 1 |
| 9 | qodo | miss | 0/1 | 0.0% | 0 | 0 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | off by one |
The task only receives assignment_source_dict from sync_group_assignee_outbound, which builds it with to_dict() on an AssignmentSource created by from_integration with integration_id=integration.id, an int. JSON serialization keeps ints as ints, so nothing in this change sends a string integration_id. The finding describes hardening against a payload no caller produces, not a failure that can actually happen. [invalid: contradiction] [consensus 3/3: invalid=3]
raw comments (2)
`queued: datetime = timezone.now()` runs once, when the module is imported. Every `AssignmentSource` built without an explicit `queued` (including every call to `from_integration`) therefore gets the worker process's start time, not the time the assignment was queued. The timestamp is wrong and grows staler the longer the process runs, so any later use of it (ordering, dedup or staleness checks for sync events) will misbehave. Use `field(default_factory=timezone.now)` instead.
`from_dict` passes the dict straight to `cls(**input_dict)` and only catches missing or unknown keys. Dataclasses don't check types, so a payload with a string `integration_id` (e.g. "123") or a string `queued` still builds an object. The cycle check in `should_sync` then compares that string to the int `org_integration.integration_id`, the comparison is never true, and the sync-loop protection silently stops working. Validate or coerce the field types here.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | off by one |
raw comments (2)
<!-- cubic:v=31668591-a349-436c-9a4f-5d3ccb60c13e -->
<!-- cubic:review-run=0340b6a0-ef0d-5e88-8988-273714f5d800 -->
<!-- metadata:{"confidence":10} -->
P2: Every source created through `from_integration` or `from_dict` without `queued` gets the module-import timestamp because `timezone.now()` is evaluated as a class default. Use a dataclass default factory so each `AssignmentSource` records its own creation time.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At src/sentry/integrations/services/assignment_source.py, line 18:
<comment>Every source created through `from_integration` or `from_dict` without `queued` gets the module-import timestamp because `timezone.now()` is evaluated as a class default. Use a dataclass default factory so each `AssignmentSource` records its own creation time.</comment>
<file context>
@@ -0,0 +1,35 @@
+class AssignmentSource:
+ source_name: str
+ integration_id: int
+ queued: datetime = timezone.now()
+
+ @classmethod
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**1 issue found** across 7 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/sentry/integrations/services/assignment_source.py">
<violation number="1" location="src/sentry/integrations/services/assignment_source.py:18">
P2: Every source created through `from_integration` or `from_dict` without `queued` gets the module-import timestamp because `timezone.now()` is evaluated as a class default. Use a dataclass default factory so each `AssignmentSource` records its own creation time.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/74/ai_pr_review_github_delivery_ff588de536df622ecd9ecbc90a92aa0af9000e8c66a586a9c4d14a5a59821d01?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F74)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_ff588de536df622ecd9ecbc90a92aa0af9000e8c66a586a9c4d14a5a59821d01:55315b89ebd41091e7ed7309f740c2a300ef9d8a:0340b6a0-ef0d-5e88-8988-273714f5d800 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | exact |
raw comments (2)
### Queued timestamp frozen at import
**Low Severity**
<!-- DESCRIPTION START -->
`queued` uses `timezone.now()` as a dataclass default, so it is evaluated once at import rather than when each `AssignmentSource` is created. Every instance that omits `queued` then shares that same import-time timestamp in `to_dict()` payloads.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: af8a6b7b-8ba9-4837-a900-f299597fa9bb -->
<!-- LOCATIONS START
src/sentry/integrations/services/assignment_source.py#L17-L18
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjI4YWY3Nzk1LWNiMDktNDA0NS1iMTEyLTZlMzA3YWFkMjQ0MCIsImVuY3J5cHRpb25LZXkiOiJVeHd0ZnJtb3piSjUzS0xhZFhPMVRPMl96RUNLMGVobUEwRzdNbjNOLXc4IiwiYnJhbmNoIjoidDItc2VudHJ5LTc3NzU0IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjI4YWY3Nzk1LWNiMDktNDA0NS1iMTEyLTZlMzA3YWFkMjQ0MCIsImVuY3J5cHRpb25LZXkiOiJVeHd0ZnJtb3piSjUzS0xhZFhPMVRPMl96RUNLMGVobUEwRzdNbjNOLXc4IiwiYnJhbmNoIjoidDItc2VudHJ5LTc3NzU0IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6OTUsImNvbW1pdFNoYSI6IjM2MGQ1ZWQyMDkzMmU4NmUwYTI5OTgwYzQ1ZjMzYTk5MjUxZjFjOWUiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 360d5ed20932e86e0a29980c45f33a99251f1c9e. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo3OWNiMTJjMi05YjNjLTQ5ODYtODFiMS1jNmFiYzA0MzJhYjAiLCJlbmNyeXB0aW9uS2V5IjoiUjVvM0xnY0hnOHpPb2tsREFzUENHMUQtQ1RXMldlNGFLc2dFUzJYemw3USIsImJyYW5jaCI6InQyLXNlbnRyeS03Nzc1NCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 360d5ed20932e86e0a29980c45f33a99251f1c9e. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | exact |
raw comments (1)
**`queued` timestamp is frozen at import time**
The `queued` default runs `timezone.now()` once, when the module is imported. Every AssignmentSource made in a worker process then gets that same old timestamp instead of the time it was queued. Use `field(default_factory=timezone.now)`.
```
src/sentry/integrations/services/assignment_source.py:18 queued: datetime = timezone.now()
src/sentry/integrations/services/assignment_source.py:20 @classmethod
src/sentry/integrations/services/assignment_source.py:21 def from_integration(cls, integration: Integration | RpcIntegration) -> AssignmentSource:
src/sentry/integrations/services/assignment_source.py:22 return AssignmentSource(
src/sentry/integrations/services/assignment_source.py:14 @dataclass(frozen=True)
src/sentry/integrations/services/assignment_source.py:15 class AssignmentSource:
src/sentry/integrations/services/assignment_source.py:16 source_name: str
src/sentry/integrations/services/assignment_source.py:17 integration_id: int
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | exact |
raw comments (1)
**`queued` timestamp frozen at import time**
The default `queued: datetime = timezone.now()` is evaluated once when the module is imported, so every AssignmentSource gets the same stale timestamp. It should be a per-instance value. Use `field(default_factory=timezone.now)`.
```
src/sentry/integrations/services/assignment_source.py:16 source_name: str
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | off by one |
raw comments (2)
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Queue Timestamp Is Stale**
`timezone.now()` is evaluated once when this module is imported, so every `AssignmentSource` created without an explicit value receives the same stale `queued` timestamp. Because this value is serialized with each outbound task, it does not represent when the assignment was actually queued and would make diagnostics or future age and ordering checks inaccurate. Use a per-instance default factory instead.
<h3>Greptile Summary</h3>
This PR propagates assignment-origin metadata through inbound group-assignee updates and outbound integration tasks so that an assignment is not synchronized back to the integration that originated it.
- Introduces the serializable `AssignmentSource` value object.
- Passes assignment origin through group assignment and deassignment flows.
- Suppresses outbound synchronization when the destination matches the originating integration.
- Adds coverage for source parsing and same-integration cycle prevention.
- One timestamp-default issue should be corrected so the newly introduced queue metadata remains accurate.
<h3>Confidence Score: 4/5</h3>
The PR appears safe to merge after addressing the non-blocking inaccurate queue timestamp metadata.
The cycle-prevention flow uses compatible provider contracts and consistent integration identities; the only accepted concern is that `AssignmentSource.queued` records module-import time rather than per-assignment queue time.
**Files Needing Attention:** src/sentry/integrations/services/assignment_source.py
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| src/sentry/integrations/services/assignment_source.py | Adds assignment-origin serialization, but its eager datetime default gives every normally constructed source a stale queue timestamp. |
| src/sentry/integrations/mixins/issues.py | Extends synchronization gating to suppress outbound updates targeting the originating integration. |
| src/sentry/integrations/tasks/sync_assignee_outbound.py | Reconstructs assignment-origin metadata and forwards it through synchronization checks and provider calls. |
| src/sentry/integrations/utils/sync.py | Creates source metadata for inbound changes and serializes it when scheduling outbound synchronization. |
| src/sentry/models/groupassignee.py | Threads optional assignment-origin metadata through user assignment and deassignment operations. |
| tests/sentry/integrations/services/test_assignment_source.py | Covers basic conversion behavior but does not verify that each source receives its actual creation timestamp. |
| tests/sentry/models/test_groupassignee.py | Covers normal outbound assignment and suppression when the originating and destination integrations match. |
</details>
<details open><summary><h3>Sequence Diagram</h3></summary>
```mermaid
sequenceDiagram
participant Source as Source integration
participant Inbound as Inbound sync
participant Group as GroupAssignee
participant Queue as Outbound task queue
participant Target as Linked integration
Source->>Inbound: Assignee change
Inbound->>Group: assign/deassign with AssignmentSource
Group->>Queue: enqueue linked issues with source metadata
Queue->>Target: should_sync(attribute, source)
alt Target is source integration
Target-->>Queue: Skip synchronization
else Different integration
Queue->>Target: Synchronize assignee
end
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update src/sentry/integrations/mixins/is..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/13c9479f23fb9bbb701ed684b1a430463796f9a7) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284827)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | off by one |
A dataclass default expression runs only once, when the class is defined, so every instance gets the same import-time timestamp in `queued`. This new file adds that default, and `test_to_dict` only checks that the value isn't None. [grounded: tree src/sentry/integrations/services/assignment_source.py] [consensus 3/3: valid=3]
raw comments (2)
[P2] `queued` default is evaluated once at import time
`queued: datetime = timezone.now()` is a dataclass default, so Python evaluates it once, when the module is imported, not each time an instance is created. Every `AssignmentSource` built without an explicit `queued`, which includes everything made through `from_integration` and anything rebuilt through `from_dict` without that key, gets the same timestamp: the moment the worker process loaded the module. Anything that reads `queued` (it is serialized into the task kwargs through `to_dict`) will see stale times that can be hours or days old. The fix is `field(default_factory=timezone.now)`.
[P2] `queued` default is evaluated once at import time
`queued: datetime = timezone.now()` calls `timezone.now()` only once, when the class is defined. Every `AssignmentSource` built afterwards, for example by `from_integration()` on each inbound sync, gets the same timestamp from process startup. That value is then serialized in `to_dict()` and sent with the `sync_assignee_outbound` task. So `queued` does not record when the assignment was queued, and any later logic that relies on it (ordering, staleness checks, debugging) will be wrong. The new `test_to_dict` only checks that the value is non-None, so it doesn't catch this. Use `field(default_factory=timezone.now)` so each instance gets the current time.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✓ | off by one |
The default is indeed evaluated once at class definition, so every instance gets the same timestamp. But the finding itself concedes that nothing reads `queued` today, so the only harm is to hypothetical future consumers. [invalid: self-contradiction] [consensus 3/3: invalid=3]
raw comments (2)
[P2] `queued` default is evaluated once at import time
In `queued: datetime = timezone.now()`, the default is computed when the module is imported. Every `AssignmentSource` built through `from_integration` then carries the process start time as `queued`, not the time it was created. The value is serialized into the Celery task kwargs, so anything that reads `queued` (for example to measure latency or order events) gets wrong data in long-running workers. It should use `field(default_factory=timezone.now)
[P3] `queued` default is evaluated once at import time
The dataclass default `queued: datetime = timezone.now()` is computed when the module is imported, not when each `AssignmentSource` is created. Every instance built via `from_integration` therefore gets the same process-start timestamp, and that value is then serialized into the task kwargs. Nothing reads `queued` yet, so this has no effect today. Anyone who later uses it to order or age assignments will get wrong values. Use `field(default_factory=timezone.now)` instead
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | low | ✗ | — |
raw comments (2)
<h3>Qodo is busy working</h3>
Check back in a few minutes. Qodo's code review agents are on it.
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<img src="https://www.qodo.ai/wp-content/uploads/2026/01/anteater-looking-at-ants-01-transparent-bg-croped-ezgif.com-optimize-1.gif" width="30%">
<h3>PR Summary by Qodo</h3>
Prevent integration assignee sync cycles with source tracking
<code>🐞 Bug fix</code> <code>🧪 Tests</code> <code>🕐 20-40 Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Tracks the originating integration across asynchronous assignee synchronization.
>• Prevents assignee changes from syncing back to their source integration.
>• Adds serialization and regression coverage for source-aware assignment flows.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
sequenceDiagram
actor SRC as Source Tracker
participant IN as Inbound Sync
participant GA as Group Assignee
participant Q as Outbound Queue
participant T as Sync Task
participant II as Integration Install
actor DST as Target Tracker
SRC->>IN: Assignee update
IN->>GA: Assignment source
GA->>Q: Linked issue payload
Q->>T: Serialized source
T->>II: Check source ID
alt Same integration
II-->>T: Skip sync
else Different integration
II->>DST: Sync assignee
end
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Suppress all outbound sync for inbound changes</b></summary>
<dl>
<dd>
- ➕ Simpler control flow with no source metadata serialization
- ➕ Guarantees inbound events cannot create outbound cycles
- ➖ Prevents legitimate propagation to other linked integrations
- ➖ Loses provenance that may support future sync decisions
</dd>
</dl>
</details>
<details>
<summary><b>2. Task-level deduplication</b></summary>
<dl>
<dd>
- ➕ Could detect longer cycles involving several integrations
- ➕ Centralizes duplicate suppression across synchronization types
- ➖ Requires persistent state or a shared cache
- ➖ Introduces expiry, concurrency, and idempotency complexity
</dd>
</dl>
</details>
>**Recommendation:** Retain the PR's source-propagation approach. It prevents direct feedback loops without additional storage and preserves useful cross-integration propagation; global suppression is too restrictive, while task-level deduplication is substantially more complex for this issue.
</dd>
</dl>
</details>
<details>
<summary> Files changed (7) <code> +212 / -15 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (1) <code> +35 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>assignment_source.py<code>Introduce serializable assignment source metadata</code> <code>+35/-0</code></summary>
<br/>
>Introduce serializable assignment source metadata
>
><pre>
>• Adds an immutable 'AssignmentSource' value object containing the source name, integration ID, and queue timestamp. It supports construction from integrations and safe dictionary serialization across task boundaries.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-461a13a35a030cfe98cd494d1b210ab61b61978cec5036c1cba375072fbbb5cf'>src/sentry/integrations/services/assignment_source.py</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Bug fix (4) <code> +68 / -12 </code></summary>
<dl>
<dd>
<details>
<summary>issues.py<code>Suppress synchronization back to the source integration</code> <code>+18/-3</code></summary>
<br/>
>Suppress synchronization back to the source integration
>
><pre>
>• Extends integration sync contracts to accept optional assignment provenance. 'should_sync' now rejects outbound synchronization when the target installation matches the originating integration, preventing feedback cycles.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-aa1723c6c1e8ea495d099f0564b1a07f0e43fde6d5e2e073f98bb34ceeffdcf9'>src/sentry/integrations/mixins/issues.py</a>
</details>
<details>
<summary>sync_assignee_outbound.py<code>Apply source-aware checks in outbound assignee tasks</code> <code>+16/-3</code></summary>
<br/>
>Apply source-aware checks in outbound assignee tasks
>
><pre>
>• Accepts serialized assignment source metadata, reconstructs it, and passes it through synchronization eligibility checks and provider calls.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-f145581f2370021b3fb06697e0568aacb0b9bae77df2b7868fb394d12f860608'>src/sentry/integrations/tasks/sync_assignee_outbound.py</a>
</details>
<details>
<summary>sync.py<code>Propagate assignment provenance through sync utilities</code> <code>+25/-4</code></summary>
<br/>
>Propagate assignment provenance through sync utilities
>
><pre>
>• Marks inbound assignments and deassignments with their originating integration. Serializes that provenance when scheduling outbound tasks for linked external issues.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-ea5c17a9b63bd9130c32b0d93c27c986404da944aa54af0529e7a625a5fba85c'>src/sentry/integrations/utils/sync.py</a>
</details>
<details>
<summary>groupassignee.py<code>Carry assignment sources through assignee mutations</code> <code>+9/-2</code></summary>
<br/>
>Carry assignment sources through assignee mutations
>
><pre>
>• Adds optional assignment provenance to assignment and deassignment manager APIs. The source is forwarded when these mutations trigger outbound integration synchronization.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-8a030b9a643c9dcd6d58d51998f978700c7eafa76fd17ac675a88c02cd8b454e'>src/sentry/models/groupassignee.py</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Tests (2) <code> +109 / -3 </code></summary>
<dl>
<dd>
<details>
<summary>test_assignment_source.py<code>Test assignment source serialization</code> <code>+38/-0</code></summary>
<br/>
>Test assignment source serialization
>
><pre>
>• Covers valid and invalid dictionary parsing and verifies serialized source metadata, including its queue timestamp.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-d0a95409b66320323e446e193dd5113f95027e61ab6c4bae918a7a36da7016ce'>tests/sentry/integrations/services/test_assignment_source.py</a>
</details>
<details>
<summary>test_groupassignee.py<code>Verify source-aware outbound assignee behavior</code> <code>+71/-3</code></summary>
<br/>
>Verify source-aware outbound assignee behavior
>
><pre>
>• Updates outbound sync expectations for the new source argument and adds regression coverage proving that assignments are not echoed to their originating integration.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/70/files#diff-d3d858c0855f92c135906fc099d59025b25dd70821d71f8443df4043e90e958f'>tests/sentry/models/test_groupassignee.py</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>