Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Jun 13, 2025

During the deletion API call we were calling seer & a couple more changes which the Group deletion model already does, thus, we don't need to do it during the API call.

Prior to this change, if the Seer call failed, the deletion task would not get scheduled, thus, many groups stay in a pending deletion state and never deleted.

Fixes #93509
Fixes ID-716

@armenzg armenzg self-assigned this Jun 13, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 13, 2025
create_audit_entries(request, project, group_list, delete_type, transaction_id)

# Tell seer to delete grouping records for these groups
call_delete_seer_grouping_records_by_hash(error_ids)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already part of delete_bulk:

# Tell seer to delete grouping records with these group hashes
call_delete_seer_grouping_records_by_hash(error_group_ids)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this call to seer fails then the task is not get scheduled.

This is one of the main reasons we have so many groups in a pending deletion state.

Redash query: https://redash.getsentry.net/queries/9170/source


# Removing GroupHash rows prevents new events from associating to the groups
# we just deleted.
GroupHash.objects.filter(project_id=project.id, group__id__in=group_ids).delete()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the models that are deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this allow new events to be added to the existing issues until the delete is processed? Is that going to do what customers want still?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory The group is already marked as pending deletion, thus, the customer can't even see the group.

See lines 67-69:

Image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to keep the group hash until the Seer task gets scheduled, thus, even the more reason to do it during the Group deletion task.

except InvalidGroupTypeError:
pass
# Tell seer to delete grouping records with these group hashes
call_delete_seer_grouping_records_by_hash(error_group_ids)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the call under _delete_children.

try:
call_delete_seer_grouping_records_by_hash([group.id for group in error_groups])
except Exception:
logger.exception("Error calling seer delete grouping records by hash")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen the call fail as part of the API deletion calls, thus, I want to put this guard against it.

@armenzg armenzg requested a review from markstory June 13, 2025 18:55
@armenzg armenzg marked this pull request as ready for review June 13, 2025 18:55
@armenzg armenzg requested review from a team as code owners June 13, 2025 18:55
@armenzg armenzg requested a review from a team as a code owner June 13, 2025 18:56
@codecov
Copy link

codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #93541      +/-   ##
==========================================
- Coverage   87.83%   87.81%   -0.02%     
==========================================
  Files       10478    10492      +14     
  Lines      605960   606303     +343     
  Branches    23674    23674              
==========================================
+ Hits       532216   532403     +187     
- Misses      73380    73536     +156     
  Partials      364      364              

@armenzg armenzg requested a review from a team as a code owner June 16, 2025 16:48
@armenzg armenzg marked this pull request as draft June 16, 2025 17:23
@armenzg armenzg removed the request for review from markstory July 3, 2025 18:53
@armenzg armenzg force-pushed the feat/hash/group/deletion/armenzg branch from 2467a33 to 2f607b6 Compare July 9, 2025 14:42
# delete the "smaller" groups first
group_list.sort(key=lambda g: (g.times_seen, g.id))
group_ids = []
error_ids = []
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this variable anymore, thus, removing the whole block.


# Removing GroupHash rows prevents new events from associating to the groups
# we just deleted.
GroupHash.objects.filter(project_id=project.id, group__id__in=group_ids).delete()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory The group is already marked as pending deletion, thus, the customer can't even see the group.

See lines 67-69:

Image

create_audit_entries(request, project, group_list, delete_type, transaction_id)

# Tell seer to delete grouping records for these groups
call_delete_seer_grouping_records_by_hash(error_ids)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this call to seer fails then the task is not get scheduled.

This is one of the main reasons we have so many groups in a pending deletion state.

Redash query: https://redash.getsentry.net/queries/9170/source

@armenzg armenzg force-pushed the feat/hash/group/deletion/armenzg branch from 2f607b6 to 449c4dd Compare July 11, 2025 12:46
@armenzg armenzg mentioned this pull request Jul 11, 2025
add_group_to_inbox(group, GroupInboxReason.NEW)

delete_groups(request, [self.project], self.organization.id)
with self.tasks():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the task does not execute the hashes will still exist.


@patch("sentry.api.helpers.group_index.delete.may_schedule_task_to_delete_hashes_from_seer")
@patch("sentry.utils.audit.log_service.record_audit_log")
def test_audit_log_even_if_exception_raised(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not make sense after this change.

@armenzg armenzg changed the title ref(deletions): Remove unnecessary calls in endpoint ref(deletions): Remove unnecessary Seer calls in endpoint Jul 11, 2025
@armenzg armenzg requested a review from markstory July 11, 2025 13:44
@armenzg armenzg marked this pull request as ready for review July 11, 2025 13:44
@armenzg armenzg requested a review from lobsterkatie July 14, 2025 18:48
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Group Deletion Logic Inconsistency

The GroupHash deletion was removed from the delete_group_list API endpoint, despite PR discussion acknowledging the need to restore it. This allows new events to associate with groups marked as PENDING_DELETION during the window before the asynchronous deletion task completes. This contradicts the original intent to prevent such associations and is inconsistent with the retained GroupInbox deletion logic.

src/sentry/api/helpers/group_index/delete.py#L78-L84

# We remove `GroupInbox` rows here so that they don't end up influencing queries for
# `Group` instances that are pending deletion
GroupInbox.objects.filter(project_id=project.id, group__id__in=group_ids).delete()
delete_groups_task.apply_async(
kwargs={

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@armenzg
Copy link
Member Author

armenzg commented Jul 14, 2025

Bug: Group Deletion Logic Inconsistency

The GroupHash deletion was removed from the delete_group_list API endpoint, despite PR discussion acknowledging the need to restore it. This allows new events to associate with groups marked as PENDING_DELETION during the window before the asynchronous deletion task completes. This contradicts the original intent to prevent such associations and is inconsistent with the retained GroupInbox deletion logic.

src/sentry/api/helpers/group_index/delete.py#L78-L84
Fix in CursorFix in Web

Was this report helpful? Give feedback by reacting with 👍 or 👎

We don't want to delete GroupHash since it will be needed during the task execution to call Seer.

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. Consolidating the deletion logic is a great idea.

@armenzg armenzg merged commit e9e09e1 into master Jul 15, 2025
65 checks passed
@armenzg armenzg deleted the feat/hash/group/deletion/armenzg branch July 15, 2025 16:58
armenzg added a commit that referenced this pull request Jul 17, 2025
armenzg added a commit that referenced this pull request Jul 18, 2025
…3541) (#95828)

This reverts commit e9e09e1.

A customer deleted an issue but new events are being associated with
the old group rather than creating a new one.

I will add a test to document the expected behaviour to prevent future regressions.
cursor bot pushed a commit that referenced this pull request Jul 18, 2025
armenzg added a commit that referenced this pull request Jul 18, 2025
When deleting an issue, a failure to query the DB would prevent scheduling the group deletion task.

From the customer's perspective, it would look that the group has been deleted, however, all relationships would still be left behind.

The biggest problem would be that the group hashes are left behind, thus, any new events matching those group hashes would not create a new issue.

This is a better fix than the one proposed in #93541.

Fixes #93509.
Fixes [ID-716](https://linear.app/getsentry/issue/ID-716/)
armenzg added a commit that referenced this pull request Jul 21, 2025
This is the test missing from #93541 that would have prevented the regression.
armenzg added a commit that referenced this pull request Jul 21, 2025
This is the test missing from #93541 that would have prevented the
regression.
armenzg added a commit that referenced this pull request Jul 21, 2025
When deleting an issue, a failure to query the DB would prevent
scheduling the group deletion task.

From the customer's perspective, it would look that the group has been
deleted, however, all relationships would still be left behind.

The biggest problem would be that the group hashes are left behind,
thus, any new events matching those group hashes would not create a new
issue.

This is a better fix than the one proposed in #93541.

Fixes #93509.
Fixes [ID-716](https://linear.app/getsentry/issue/ID-716/)
andrewshie-sentry pushed a commit that referenced this pull request Jul 21, 2025
During the deletion API call we were calling seer & a couple more
changes which the Group deletion model already does, thus, we don't need
to do it during the API call.

Prior to this change, if the Seer call failed, the deletion task would
not get scheduled, thus, many groups stay in a pending deletion state
and never deleted.

Fixes #93509 
Fixes
[ID-716](https://linear.app/getsentry/issue/ID-716/move-endpoint-code-to-the-deletion-task)
andrewshie-sentry pushed a commit that referenced this pull request Jul 21, 2025
…3541) (#95828)

This reverts commit e9e09e1.

A customer deleted an issue but new events are being associated with
the old group rather than creating a new one.

I will add a test to document the expected behaviour to prevent future regressions.
andrewshie-sentry pushed a commit that referenced this pull request Jul 21, 2025
This is the test missing from #93541 that would have prevented the
regression.
andrewshie-sentry pushed a commit that referenced this pull request Jul 21, 2025
When deleting an issue, a failure to query the DB would prevent
scheduling the group deletion task.

From the customer's perspective, it would look that the group has been
deleted, however, all relationships would still be left behind.

The biggest problem would be that the group hashes are left behind,
thus, any new events matching those group hashes would not create a new
issue.

This is a better fix than the one proposed in #93541.

Fixes #93509.
Fixes [ID-716](https://linear.app/getsentry/issue/ID-716/)
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A DB failure in the group deletion endpoint should not prevent deleting group hashes

4 participants