Skip to content

fix(seer): Gracefully filter non-Sentry GitHub check_run webhooks#114909

Draft
sentry[bot] wants to merge 1 commit intomasterfrom
seer/fix/seer-check-run-external-id
Draft

fix(seer): Gracefully filter non-Sentry GitHub check_run webhooks#114909
sentry[bot] wants to merge 1 commit intomasterfrom
seer/fix/seer-check-run-external-id

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry Bot commented May 5, 2026

This PR addresses an issue where ValueError: invalid literal for int() with base 10: '' was being raised and logged when processing GitHub check_run webhooks from third-party CI tools (e.g., Codecov).

Root Cause:
Sentry's _validate_github_check_run_event function attempted to convert check_run.external_id to an integer using int(). While Sentry's own check runs populate this field with a numeric Seer run ID, third-party CI tools often send an empty string '' for external_id (as it's an optional field for them). Calling int('') results in a ValueError.

Although this error was caught and prevented a 500 response to GitHub, it still generated Sentry issues, creating unnecessary noise.

Solution:
Instead of relying on an exception, this change implements an explicit early filter for check_run webhooks that do not originate from Sentry's Seer:

  1. src/sentry/seer/code_review/metrics.py: Added NOT_SENTRY_CHECK_RUN to the WebhookFilteredReason enum for better metric tracking.
  2. src/sentry/seer/code_review/webhooks/check_run.py (handle_check_run_event): An early check was added. If event.check_run.external_id is empty or non-numeric, the webhook is now gracefully filtered using record_webhook_filtered with the new NOT_SENTRY_CHECK_RUN reason, and the function returns silently. This aligns the handling of these expected third-party payloads with other filtered webhook reasons.
  3. src/sentry/seer/code_review/webhooks/check_run.py (_validate_github_check_run_event): The int() conversion of external_id was removed, as the upstream filter now handles non-numeric values. The except clause was updated to only catch ValidationError.

This change reduces error noise by treating these third-party webhooks as expected, filtered events rather than exceptions.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SENTRY-5KT4

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

github-actions Bot commented May 5, 2026

Backend Test Failures

Failures on 0f235a0 in this run:

tests/sentry/seer/code_review/webhooks/test_check_run.py::CheckRunEventWebhookTest::test_check_run_fails_when_external_id_missinglog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/code_review/webhooks/test_check_run.py:70: in test_check_run_fails_when_external_id_missing
    mock_logger.exception.assert_called_once()
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/unittest/mock.py:956: in assert_called_once
    raise AssertionError(msg)
E   AssertionError: Expected 'exception' to have been called once. Called 0 times.
tests/sentry/seer/code_review/webhooks/test_check_run.py::CheckRunEventWebhookTest::test_check_run_fails_when_external_id_not_numericlog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/code_review/webhooks/test_check_run.py:91: in test_check_run_fails_when_external_id_not_numeric
    mock_logger.exception.assert_called_once()
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/unittest/mock.py:956: in assert_called_once
    raise AssertionError(msg)
E   AssertionError: Expected 'exception' to have been called once. Called 0 times.

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.

0 participants