Skip to content

Conversation

@aliu39
Copy link
Member

@aliu39 aliu39 commented Jan 14, 2026

No description provided.

@aliu39 aliu39 requested a review from a team as a code owner January 14, 2026 20:58
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 14, 2026
if "count()" not in timeseries_response:
return 0
data = timeseries_response["count()"]["data"]
return sum(item[1][0]["count"] for item in data)
Copy link

Choose a reason for hiding this comment

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

Bug: The function get_timeseries_count_total may raise an IndexError because it accesses item[1][0] without checking if item[1] is empty for time buckets with no data.
Severity: CRITICAL

Suggested Fix

Add a condition to the generator expression to filter out items where item[1] is empty. The sum should be calculated as sum(item[1][0]["count"] for item in data if item[1]). This matches the defensive pattern used elsewhere in the codebase for processing the same data structure.

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/seer/explorer/utils.py#L496

Potential issue: The function `get_timeseries_count_total` calculates a total by summing
counts from a timeseries response. It iterates through data items and accesses
`item[1][0]["count"]`. However, for time buckets that contain no events, the `item[1]`
list will be empty. The code does not check for this case, leading to an `IndexError`
when it attempts to access the 0th element of the empty list. This will cause the
`get_issue_and_event_response` function to fail, breaking the issue details view in
Explorer. Other parts of the codebase defensively check for this condition using `if
item[1]`.

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

interval = interval or "3d"

# Adjust range to equal period
end_dt = start_dt + selected_delta
Copy link

Choose a reason for hiding this comment

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

Bug: A time range mismatch between the total event count and tag data queries in get_issue_and_event_response leads to incorrect percentage calculations for tag distribution.
Severity: HIGH

Suggested Fix

Ensure the get_group_tags_overview function is called with the same adjusted time range that was used to generate the event_count. The adjusted end_dt from _get_issue_event_timeseries should be passed down and used for both the timeseries and the facets queries to maintain consistency.

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/seer/explorer/tools.py#L768

Potential issue: In `get_issue_and_event_response`, the total event count is calculated
from a timeseries query whose time range is automatically extended (e.g., from 5 minutes
to 6 hours) for resolution alignment. However, this total count is then used as the
denominator for percentage calculations in `get_group_tags_overview`, which queries for
tag data using the original, narrower time range. This mismatch between the time range
used for the total count and the time range for individual tag counts results in
incorrect tag distribution percentages being displayed to the user.

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

interval = interval or "3d"

# Adjust range to equal period
end_dt = start_dt + selected_delta
Copy link
Contributor

Choose a reason for hiding this comment

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

Timeseries and tag query time ranges are mismatched

High Severity

The _get_issue_event_timeseries function extends end_dt to match a selected period (e.g., extending a 2-day request to 3 days), but get_group_tags_overview queries tags using the original time range parameters. The event_count from the extended timeseries is then used as the denominator for tag percentage calculations in get_all_tags_overview. This causes incorrect percentages—for example, a tag appearing 50 times in a 2-day period might show 33% instead of 50% because the denominator includes events from an extended 3-day range.

Additional Locations (1)

Fix in Cursor Fix in Web

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