Skip to content

fix: Trigger ad-hoc explorer index runs#116530

Open
shruthilayaj wants to merge 2 commits into
masterfrom
shruthi/fix/trigger-explorer-index-in-outbox
Open

fix: Trigger ad-hoc explorer index runs#116530
shruthilayaj wants to merge 2 commits into
masterfrom
shruthi/fix/trigger-explorer-index-in-outbox

Conversation

@shruthilayaj
Copy link
Copy Markdown
Member

@shruthilayaj shruthilayaj commented May 29, 2026

The organizations:seer-run-mirror-explorer on SeerAgentClient.start_run meant
we weren't triggering the ad-hoc create explorer index tasks. This PR now calls the
index build tasks for explorer runs.

compute_delay was causing a circular import - so just moved that to a utils file

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 29, 2026
@shruthilayaj shruthilayaj marked this pull request as ready for review May 29, 2026 21:08
@shruthilayaj shruthilayaj requested review from a team as code owners May 29, 2026 21:08
@shruthilayaj shruthilayaj changed the title fix: Trigger Explorer index from outbox fix: Trigger ad-hoc explorer index runs May 29, 2026
@shruthilayaj shruthilayaj requested a review from trevor-e May 29, 2026 21:09
Comment thread src/sentry/tasks/utils.py
# ensure there is some padding before the end of the duration
remaining -= step

return batch_index * int(step.total_seconds()) % int(remaining.total_seconds())
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 compute_delay function can cause a ZeroDivisionError if called during a specific second of the hour, as the remaining time can become zero before the modulo operation.
Severity: MEDIUM

Suggested Fix

Add a guard in compute_delay to handle cases where remaining.total_seconds() is zero or negative. For example, ensure the divisor for the modulo operation is at least 1. Using max(1, int(remaining.total_seconds())) as the divisor would prevent the division by 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/tasks/utils.py#L33

Potential issue: The `compute_delay` function calculates a delay based on the time
remaining until the next hour. If the function is executed at a specific second (e.g.,
59 minutes and 43 seconds into the hour), the calculated `remaining` time can become
zero. This leads to a `ZeroDivisionError` during the modulo operation `... %
int(remaining.total_seconds())`. This pull request exposes the function to a new ad-hoc
call path triggered by user actions, making this edge case more likely. While the
exception is caught, it causes the associated explorer index tasks to silently fail to
dispatch.

Also affects:

  • src/sentry/receivers/outbox/cell.py:293~297

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

@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on a358d4b in this run:

tests/sentry/services/test_organization_actions.py::OrganizationUpdateWithOutboxTest::test_update_organization_with_outbox_messagelog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/testutils/cases.py:404: in _pre_setup
    super()._pre_setup()
src/sentry/utils/db.py:64: in _enter
    return original_enter(self)
           ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/django/db/transaction.py:211: in __enter__
    sid = connection.savepoint()
          ^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/django/utils/asyncio.py:26: in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/django/db/backends/base/base.py:400: in savepoint
    self._savepoint(sid)
.venv/lib/python3.13/site-packages/django/db/backends/base/base.py:367: in _savepoint
    cursor.execute(self.ops.savepoint_create_sql(sid))
.venv/lib/python3.13/site-packages/django/db/backends/utils.py:122: in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/sentry_sdk/utils.py:1887: in runner
    return original_function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/django/db/backends/utils.py:79: in execute
    return self._execute_with_wrappers(
.venv/lib/python3.13/site-packages/django/db/backends/utils.py:92: in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/db/postgres/base.py:70: in _execute__include_sql_in_error
    return execute(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/db/postgres/base.py:58: in _execute__clean_params
    return execute(sql, clean_bad_params(params), many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/testutils/hybrid_cloud.py:129: in __call__
    raise CrossTransactionAssertionError(
E   sentry.testutils.hybrid_cloud.CrossTransactionAssertionError: Transaction opened for db {'default'}, but command running against db control
E   SQL: SAVEPOINT "s140478049540992_x9047"
tests/sentry/tasks/test_options.py::SyncOptionsTest__InControlMode::test_task_persistent_namelog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/testutils/cases.py:411: in _post_teardown
    super()._post_teardown()
.venv/lib/python3.13/site-packages/django/db/backends/postgresql/base.py:482: in check_constraints
    cursor.execute("SET CONSTRAINTS ALL IMMEDIATE")
.venv/lib/python3.13/site-packages/django/db/backends/utils.py:122: in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/sentry_sdk/utils.py:1887: in runner
    return original_function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/django/db/backends/utils.py:79: in execute
    return self._execute_with_wrappers(
.venv/lib/python3.13/site-packages/django/db/backends/utils.py:92: in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/db/postgres/base.py:70: in _execute__include_sql_in_error
    return execute(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/db/postgres/base.py:58: in _execute__clean_params
    return execute(sql, clean_bad_params(params), many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/testutils/hybrid_cloud.py:129: in __call__
    raise CrossTransactionAssertionError(
E   sentry.testutils.hybrid_cloud.CrossTransactionAssertionError: Transaction opened for db {'secondary'}, but command running against db control
E   SQL: SET CONSTRAINTS ALL IMMEDIATE

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