Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions src/sentry/seer/code_review/webhooks/merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,16 +658,12 @@ def _schedule_task(
validated = SeerCodeReviewTaskRequestForPrReview.parse_obj(payload)
serialized_payload = json.loads(validated.json())
except ValidationError as e:
debug_log(
logger,
organization,
"validation_failed",
{
**(log_context or {}),
"seer_path": seer_path,
"validation_errors": e.errors(),
},
level=logging.WARNING,
# Capture at warning level: a dropped review is worth surfacing, but
# should not count toward the error rate that gates a canary deploy.
sentry_sdk.capture_exception(
e,
level="warning",
contexts={"code_review_validation": {"seer_path": seer_path}},
)
record_webhook_filtered(
GITLAB_WEBHOOK_EVENT, action_value, WebhookFilteredReason.INVALID_PAYLOAD
Expand Down Expand Up @@ -791,15 +787,12 @@ def _schedule_note_task(
validated = SeerCodeReviewTaskRequestForPrReview.parse_obj(payload)
serialized_payload = json.loads(validated.json())
except ValidationError as e:
debug_log(
logger,
organization,
"note.validation_failed",
{
"mr_iid": mr_iid,
"validation_errors": e.errors(),
},
level=logging.WARNING,
# Capture at warning level: a dropped review is worth surfacing, but
# should not count toward the error rate that gates a canary deploy.
sentry_sdk.capture_exception(
e,
level="warning",
contexts={"code_review_validation": {"mr_iid": mr_iid}},
)
record_webhook_filtered(
GITLAB_WEBHOOK_NOTE_EVENT,
Expand Down
36 changes: 36 additions & 0 deletions tests/sentry/seer/code_review/webhooks/test_merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import orjson
import pytest
from pydantic import ValidationError
from scm.types import CreatePullRequestCommentReactionProtocol

from fixtures.gitlab import (
Expand All @@ -15,6 +16,7 @@
from sentry.models.organizationcontributors import OrganizationContributors
from sentry.models.repositorysettings import CodeReviewTrigger
from sentry.organizations.services.organization.model import RpcOrganization
from sentry.seer.code_review.models import SeerCodeReviewTaskRequestForPrReview
from sentry.seer.code_review.webhooks.merge_request import (
WEBHOOK_NOTE_SEEN_KEY_PREFIX,
WEBHOOK_SEEN_KEY_PREFIX,
Expand Down Expand Up @@ -176,6 +178,40 @@ def test_open_uses_review_request_endpoint(self) -> None:
call_kwargs = self.mock_seer.call_args[1]
assert call_kwargs["path"] == "/v1/code_review/review-request"

@with_feature(
{
"organizations:gen-ai-features",
"organizations:code-review-beta",
"organizations:seer-gitlab-support",
}
)
def test_validation_failure_is_captured_and_review_dropped(self) -> None:
# A payload that fails SeerCodeReviewTaskRequest validation means the
# review is dropped entirely and never reaches Seer, so it must be
# escalated via sentry_sdk.capture_exception (not just debug-logged).
self._setup_code_review()
event = _make_event("open")

with pytest.raises(ValidationError) as exc_info:
SeerCodeReviewTaskRequestForPrReview.parse_obj({})
validation_error = exc_info.value

with (
patch(
"sentry.seer.code_review.webhooks.merge_request."
"SeerCodeReviewTaskRequestForPrReview.parse_obj",
side_effect=validation_error,
),
patch(
"sentry.seer.code_review.webhooks.merge_request.sentry_sdk.capture_exception"
) as mock_capture,
self.tasks(),
):
self._call_handler(event)

mock_capture.assert_called_once_with(validation_error, level="warning")
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
Comment thread
sentry[bot] marked this conversation as resolved.
Outdated
self.mock_seer.assert_not_called()

@with_feature({"organizations:gen-ai-features", "organizations:code-review-beta"})
def test_skips_when_gitlab_flag_disabled(self) -> None:
# The GitLab MR handler is gated on organizations:seer-gitlab-support,
Expand Down
Loading