Skip to content

feat(supergroups): add issues-with-supergroups endpoint #113563

Merged
cvxluo merged 1 commit intomasterfrom
cvxluo/add-issues-with-supergroups-endpoint
Apr 28, 2026
Merged

feat(supergroups): add issues-with-supergroups endpoint #113563
cvxluo merged 1 commit intomasterfrom
cvxluo/add-issues-with-supergroups-endpoint

Conversation

@cvxluo
Copy link
Copy Markdown
Contributor

@cvxluo cvxluo commented Apr 21, 2026

Add a new 'issues' endpoint for a blended issues + supergroups view. This works by fetching x2 results, combining issues that are in the same supergroups, and then fetching that exact number to get the correct cursor for the next page.

Unfortunately this approach requires 2 search queries over basically the same data. The problem is maintaining the cursor here. Let's say we get a request for 25 results and fetch 50. We blend together to get 25 rows, using 40 of the original groups we fetched. We don't have a cursor to return at the 40th result, since each time we fetch a page, we get the cursor from the end of the page — we only have the cursor at 50. To fix this, we make another request for the number of issues we actually used, then modifying that cursor to work accordingly.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 21, 2026
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@cvxluo cvxluo force-pushed the cvxluo/extract-shared-search-serialize-helpers branch from 8c90cee to c829675 Compare April 21, 2026 18:14
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from 8146943 to 20ca2cc Compare April 21, 2026 18:26
@cvxluo cvxluo force-pushed the cvxluo/extract-shared-search-serialize-helpers branch from c829675 to 4c56715 Compare April 21, 2026 18:37
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from 20ca2cc to d959eb7 Compare April 21, 2026 18:37
@cvxluo cvxluo force-pushed the cvxluo/extract-shared-search-serialize-helpers branch from 4c56715 to 2051bce Compare April 21, 2026 20:39
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from d959eb7 to 318688d Compare April 21, 2026 20:39
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from 318688d to 9467611 Compare April 21, 2026 20:46
@cvxluo cvxluo force-pushed the cvxluo/extract-shared-search-serialize-helpers branch from 2051bce to aad3ceb Compare April 21, 2026 20:46
Base automatically changed from cvxluo/extract-shared-search-serialize-helpers to master April 21, 2026 21:38
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from 9467611 to a425799 Compare April 21, 2026 21:46
Comment thread src/sentry/issues/endpoints/organization_issues_with_supergroups.py Outdated
Comment thread src/sentry/issues/endpoints/organization_issues_with_supergroups.py Fixed
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from a425799 to c921aaf Compare April 21, 2026 22:48
Comment thread src/sentry/issues/endpoints/organization_issues_with_supergroups.py Fixed
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from c921aaf to f449dd8 Compare April 23, 2026 00:08
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from f449dd8 to 5a1ede2 Compare April 23, 2026 00:29
Comment thread src/sentry/issues/endpoints/organization_issues_with_supergroups.py Outdated
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from 5a1ede2 to f64cced Compare April 23, 2026 15:46
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from f64cced to 7139650 Compare April 23, 2026 22:10
**search_kwargs,
)
except ValidationError as exc:
return Response({"detail": str(exc)}, status=400)
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from 7139650 to b8754be Compare April 23, 2026 22:31
@cvxluo cvxluo marked this pull request as ready for review April 23, 2026 22:34
@cvxluo cvxluo requested review from a team as code owners April 23, 2026 22:34
@cvxluo cvxluo requested a review from yuvmen April 24, 2026 23:06
Copy link
Copy Markdown
Member

@yuvmen yuvmen left a comment

Choose a reason for hiding this comment

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

looks good overall, I think this works as like a best effort to make this viable for now.

return Response({"detail": str(exc)}, status=400)

response = Response(rows)
# X-Hits is the number of rows we're returning on this page. We skip
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor - can add information as a comment on the endpoint so its more visible, this x-hits behaviour that might be kinda hidden

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

going to skip for now, agree that it's not great behavior in general. i'm kind of hoping we are able to fix this with a more holistic solution before we have to deal with it seriously

# Re-run sized to what we actually consumed so its next cursor
# sits at our page boundary, not past unemitted groups.
if last_consumed + 1 < len(groups):
_, cursor_result, _ = search_and_serialize_issues(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor - we technically dont need to serialize here cuz we dont use the issues we get and its kind of a heavy operation, dont think it exists but we could actually do a search_only method just for this purpose, and save the serialization, kinda alleviating some of the pain of this second fetch

assert "supergroup" not in response.data[0]

@patch("sentry.seer.supergroups.by_group.make_supergroups_get_by_group_ids_request")
def test_paginates_without_group_overlap(self, mock_seer: MagicMock) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

feel like we should have a parallel test to this where a page does include a supergroup to make sure the cursor gets updated correctly

Subclasses OrganizationGroupIndexEndpoint and post-processes the row list to collapse Seer supergroup members into a single row. Restricted to GET via http_method_names. Behind the organizations:top-issues-ui flag.


Co-authored-by: Claude <noreply@anthropic.com>
@cvxluo cvxluo force-pushed the cvxluo/add-issues-with-supergroups-endpoint branch from b8754be to 08d4fd6 Compare April 28, 2026 00:29
return Response({"detail": ERR_INVALID_STATS_PERIOD}, status=400)

try:
limit = max(0, int(request.GET.get("limit") or 25))
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: A user can pass limit=0, causing a second search_issues call to also be made with limit=0. This is an invalid state that can lead to incorrect results.
Severity: LOW

Suggested Fix

Prevent limit=0 at the input validation stage on line 49 by changing max(0, ...) to max(1, ...). Alternatively, ensure the second search_issues call never receives a limit less than or equal to zero.

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/endpoints/organization_issues_with_supergroups.py#L49

Potential issue: The endpoint allows a user to pass `limit=0` as a query parameter. When
this happens, the `_combine_groups_and_supergroups` function returns `last_consumed=-1`.
This state triggers a second call to `search_issues` around line 110, but with `limit`
set to `0`. While the search backend might not crash, other paginators in the codebase
explicitly raise an error for `limit <= 0`, indicating this is an unsupported and
problematic state that can lead to empty or incorrect results.

Also affects:

  • src/sentry/issues/endpoints/organization_issues_with_supergroups.py:110~122

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

@cvxluo cvxluo merged commit 9b59feb into master Apr 28, 2026
57 checks passed
@cvxluo cvxluo deleted the cvxluo/add-issues-with-supergroups-endpoint branch April 28, 2026 15:52
cleptric pushed a commit that referenced this pull request May 5, 2026
Add a new 'issues' endpoint for a blended issues + supergroups view.
This works by fetching x2 results, combining issues that are in the same
supergroups, and then fetching that exact number to get the correct
cursor for the next page.

Unfortunately this approach requires 2 search queries over basically the
same data. The problem is maintaining the cursor here. Let's say we get
a request for 25 results and fetch 50. We blend together to get 25 rows,
using 40 of the original groups we fetched. We don't have a cursor to
return at the 40th result, since each time we fetch a page, we get the
cursor from the end of the page — we only have the cursor at 50. To fix
this, we make another request for the number of issues we actually used,
then modifying that cursor to work accordingly.

Co-authored-by: Claude <noreply@anthropic.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 Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants