Skip to content

fix(derived data): Make heal_stale_derived_data stale group selection more efficient - #123096

Open
kcons wants to merge 3 commits into
masterfrom
kcons/moregroops
Open

fix(derived data): Make heal_stale_derived_data stale group selection more efficient#123096
kcons wants to merge 3 commits into
masterfrom
kcons/moregroops

Conversation

@kcons

@kcons kcons commented Aug 29, 2026

Copy link
Copy Markdown
Member

Rather than querying for N group_ids in a not-that-efficient way, hit the (pipeline_hash, group_id) index directly and have Postgres only give us the ID ranges.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 29, 2026
@kcons
kcons marked this pull request as ready for review August 29, 2026 00:32
@kcons
kcons requested review from a team as code owners August 29, 2026 00:32
Comment thread src/sentry/issues/derived/tasks_util.py
)
# Never clamp below two chunks: a lone boundary can't close a range, so we'd
# return nothing and the caller would take that to mean there was nothing to do.
scan_limit = max(_MAX_SCANNED_GROUP_IDS, chunk_size * 2)

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.

Bug: The logic to determine scan_limit can incorrectly exceed the intended maximum value _MAX_SCANNED_GROUP_IDS if chunk_size is unusually large.
Severity: LOW

Suggested Fix

The clamping logic should be corrected to respect the upper bound. A safer implementation would be scan_limit = max(chunk_size * 2, min(_MAX_SCANNED_GROUP_IDS, scan_limit)).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/issues/derived/tasks_util.py#L104

Potential issue: The logic to clamp the `scan_limit` is flawed. The line `scan_limit =
max(_MAX_SCANNED_GROUP_IDS, chunk_size * 2)` is intended to ensure the scan limit is at
least two chunks, but it can incorrectly increase the `scan_limit` beyond the
`_MAX_SCANNED_GROUP_IDS` safety maximum. This occurs if `chunk_size` is configured to an
extremely large value (over 1 million), defeating the hard limit intended to protect
system resources.

Did we get this right? 👍 / 👎 to inform future reviews.

@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 b556924. Configure here.

Comment thread src/sentry/issues/derived/tasks_util.py
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.

1 participant