Skip to content

ref(seer): Skip check-suite pull requests not based in the suite's repo - #121724

Merged
vaind merged 4 commits into
masterfrom
ivandlugos/seer-check-suite-skip-foreign-repo-prs
Aug 11, 2026
Merged

vaind merged 4 commits into
masterfrom
ivandlugos/seer-check-suite-skip-foreign-repo-prs

Conversation

@vaind

@vaind vaind commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

resolve_check_suite_autofix_run looks every check_suite.pull_requests entry up by its global pr.id and returns matches[0], pairing it with repository=candidate — the repo the suite fired for, not the entry's own base.repo.

GitHub attaches a PR to a check suite whenever they share head_sha and head_branch. So an entry can be a PR with its head in this repo and its base in another one — a fork syncing from upstream is the usual shape. Autofix opens both sides of a PR in a single repo, so such an entry is never one of its own.

That entry ordered ahead of the legitimate own-repo entry shadowed it. The run it resolves has no repo_pr_states for this repo, so both downstream paths bail:

  • failure path — check_suite_head_match returns matched=False, and should_queue / should_consume are matched and ...
  • green path — resolve_green_check_suite gets no pr_number and skips with no_pr_number

The own-repo run's CI feedback is then dropped with no signal: the suite already resolved "successfully" to the wrong run.

Changes

GithubCheckSuitePullRequest now parses base.repo.id, and the resolver skips entries the payload does not place in this repo before spending a Seer lookup on them.

The rule now has one home. Three call sites decided which entries belong to the webhook's repo — pr_metrics' _prs_from_check_payload, the control parser's has_own_repo_pr tag, and this resolver — and they disagreed. sentry/integrations/github/check_payloads.py holds the comparison and the reasoning; all three call it.

The disagreement was the entry with no base.repo, resolved here by skipping, matching pr_metrics rather than the reverse:

  • pr_metrics must skip it — it resolves a repo-scoped number, and numbers repeat across repositories, so placing an unplaceable entry here can attribute another repo's PR to this one.
  • This resolver could keep it, since a global pr.id has no such collision. But GitHub always sends base.repo, so it would be guessing at a shape live payloads do not take — and resolving one anyway re-admits, for the entry we cannot place, the shadowing this PR fixes.

Skipping strands no in-flight feedback: base is new here, but the model that predates it had extra = "allow", so base round-tripped through as an extra and parses into the field on the way back in. Pinned by test_resolves_legacy_entry_round_tripped_through_the_old_model.

Skipped entries are counted as autofix.pr_iteration.check_suite.foreign_pull_request. Paired with green_check_suite.run_resolved{found:true}, a nonzero skip count with unchanged resolves confirms the filter only removes entries that could never have resolved.

Note on the import

The resolver imports check_payloads inside the function. sentry/integrations/github/__init__.py registers rule actions at import time, and this module loads while the SCM stream listeners initialize in AppConfig.ready, before options init — the same constraint that already defers make_scm in confirm_green_check_suite. At module scope it breaks test collection outright.

resolve_check_suite_autofix_run looked every check_suite.pull_requests entry up by its global id and returned the first match, pairing it with the repository the suite fired for rather than the entry's own base repo.

GitHub attaches a PR to a suite whenever they share head_sha + head_branch, so an entry can be a PR with its head in this repo and its base in another one. Such an entry ordered ahead of the own-repo entry shadowed it: the run it resolves has no repo_pr_states for this repo, so check_suite_head_match and resolve_green_check_suite both skip, and the real run's CI feedback is lost with no signal.

Entries the payload places in another repo are now skipped, matching what _prs_from_check_payload already does for pr_metrics. An entry that cannot be placed is kept, since dropping one costs a real Autofix iteration.
@vaind
vaind requested a review from a team as a code owner August 11, 2026 15:07
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 11, 2026
@vaind
vaind requested a review from a team August 11, 2026 15:09
vaind added a commit that referenced this pull request Aug 11, 2026
… own repo

Measured at 3.73M of 9.87M/day (37.8%), roughly doubling what this option
reclaims -- check_suite carries nearly check_run's volume, not a fraction of it,
and a larger share of it does no work on arrival.

Held back until now on the grounds that its second consumer, Seer's
pr_iteration_from_check_suite_listener, resolved runs by each entry's global id
without comparing base.repo. It compares as of #121724, so both consumers now
skip entries based in another repo.

They still part ways on the entry carrying no base.repo at all: pr_metrics skips
it, Seer keeps it deliberately, since dropping one costs a real Autofix
iteration. Reusing check_run's predicate here would drop those payloads on
pr_metrics' stricter reading alone and lose that work, so ActionFilter gains
unplaceable_pr_is_work and the predicate keeps them for check_suite. The drop
stays a subset of every consumer's no-op set rather than the strictest one's.

The has_own_repo_pr tag keeps the strict predicate so the series holds one
meaning across event types and stays comparable with the measurement above. On
check_suite it is therefore an upper bound: enabling the drop takes `false` to
near zero, and the remainder is the unplaceable entries the drop preserves.

Enabling the option is not safe until #121724 has merged and deployed.
Three places decided which `pull_requests` entries on a check payload belong to
the webhook's repo, and they did not agree. Moved to
integrations/github/check_payloads.py so the rule, and the reasoning behind it,
live in one place: pr_metrics' _prs_from_check_payload, the control parser's
forwarded-event tag, and this module's suite resolver.

The disagreement was the entry carrying no base.repo at all. pr_metrics skips it
-- it resolves a repo-scoped number, and on a collision an unplaceable entry
would attribute another repo's PR to this one -- while the suite resolver kept
it, resolving by global pr.id, which has no such collision.

Aligned on skipping. The control parser drops payloads that reference no
own-repo pull request, so keeping the entry here only preserved a decision about
events this path would no longer receive, and it re-admitted for the unplaceable
entry exactly the shadowing this commit set out to fix.

Skipping does not strand in-flight feedback: the model that predates `base` had
`extra = "allow"`, so `base` round-tripped through it as an extra and parses into
the declared field on the way back in. Covered by
test_resolves_legacy_entry_round_tripped_through_the_old_model.
@vaind
vaind requested review from a team as code owners August 11, 2026 16:43

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7e0d393. Configure here.

vaind added a commit that referenced this pull request Aug 11, 2026
The entry carrying no base.repo needed special handling here only because the
two check_suite consumers read it differently: pr_metrics skipped it, Seer's
suite resolver kept it. #121724 aligns them on skipping, so the carve-out
describes a disagreement that no longer exists.

ActionFilter.unplaceable_pr_is_work and the predicate's `unplaceable_is_work`
branch go with it, and check_suite now takes exactly check_run's rule. The
has_own_repo_pr tag is unchanged and is no longer an upper bound on either event
type, so `false` falls to zero for both once the option is enabled.
@vaind vaind changed the title fix(seer): Skip check-suite pull requests based in another repo ref(seer): Skip check-suite pull requests not based in the suite's repo Aug 11, 2026
vaind added a commit that referenced this pull request Aug 11, 2026
The entry carrying no base.repo needed special handling here only because the
two check_suite consumers read it differently: pr_metrics skipped it, Seer's
suite resolver kept it. #121724 aligns them on skipping, so the carve-out
describes a disagreement that no longer exists.

ActionFilter.unplaceable_pr_is_work and the predicate's `unplaceable_is_work`
branch go with it, and check_suite now takes exactly check_run's rule. The
has_own_repo_pr tag is unchanged and is no longer an upper bound on either event
type, so `false` falls to zero for both once the option is enabled.
Trim the shared-module and resolver docstrings to the reasoning that is not
already evident from the code, and drop the restatement in
_prs_from_check_payload now that the rule has one home.

Also fixes an inverted clause inherited from #121434: the predicate drops on
False, so the hazard is a False for a payload a consumer would act on, not a
True for one it would ignore.
The docstrings argued that skipping an entry with no base.repo is safe because
the control parser drops those payloads. That filter is not in this branch, does
nothing until an option is enabled even once it is, and pointed at a PR whose own
safety note points back here -- so neither change could be reviewed on its own.

The real reason needs neither: GitHub always sends base.repo, so an unplaceable
entry is not a shape a live payload takes, and resolving one anyway would
re-admit for it the shadowing this branch fixes. Legacy serialized feedback is
covered separately by the extra="allow" round trip.
@vaind
vaind enabled auto-merge (squash) August 11, 2026 18:04
@vaind
vaind merged commit 92c6ef6 into master Aug 11, 2026
66 of 67 checks passed
@vaind
vaind deleted the ivandlugos/seer-check-suite-skip-foreign-repo-prs branch August 11, 2026 18:09
vaind added a commit that referenced this pull request Aug 11, 2026
…without-own-repo-pr

#121724 moved the own-repo predicate into
integrations/github/check_payloads.py and deleted the parser's local copy, which
this branch had edited. Took master's side: the local
_references_own_repo_pull_request is gone and the drop calls the shared
references_own_repo_pull_request, same as the has_own_repo_pr tag already does.

The dependency this branch documented is now satisfied -- check_suite's second
consumer resolves through the shared rule on master, so the option is safe to
enable once this lands.
vaind added a commit that referenced this pull request Aug 11, 2026
…est in their own repo (#121719)

## Problem

`check_run.completed` and `check_suite.completed` are the two largest
remaining lines at the control parser — **11.8M and 9.9M/day**, the
former at ~110ms average, roughly 370 CPU-hours/day in the cell handler
alone — and about a third of each does no work when it lands.

GitHub lists a PR on a check whenever the two share a head sha, which
includes PRs based in *other* repositories. The cell's
`_prs_from_check_payload` resolves only entries whose `base.repo` is
this webhook's repo, so a payload carrying none of those resolves zero
PRs and writes nothing. Today every one of them is still stored as a
`WebhookPayload`, POSTed cross-silo, HMAC-verified, JSON-parsed,
dispatched through the per-org handler loop, and republished to Kafka
with its full body.

Both sides of that comparison are in the payload, so control can make
the call without the cell's database. The predicate is not an
approximation of the cell's filter — it is the same comparison:
`GitHubWebhook.__call__` looks the `Repository` row up by
`external_id=str(event["repository"]["id"])`, which is exactly what the
parser compares `base.repo.id` against.

Measured over a full 24h window:

| event | total/day | no own-repo PR | share |
| --- | --- | --- | --- |
| `check_run.completed` | 11.83M | 3.75M | 31.7% |
| `check_suite.completed` | 9.87M | 3.73M | 37.8% |

**~7.5M requests/day** combined (~8.5M rows after the 1.13× cell
fan-out), against a peak-hour backlog surplus of 110–140K rows/h.

## Changes

**The drop.** `ActionFilter` gains `own_repo_pr_actions` — the actions
where *every* cell-side consumer resolves PRs through the payload's own
repo. `references_own_repo_pull_request` was already implemented in
#121434 to tag the forwarded counter; it now decides.

For `check_run.completed` all three processors were re-checked:
`handle_preprod_check_run_event` returns unless `requested_action`, code
review's `handle_check_run_event` returns unless `rerequested`, and only
`pr_metrics_handle_check_run` reads `pull_requests`. The SCM stream's
`listen_for_check_run` is still a no-op stub.

**`check_suite.completed` has a second consumer** — Seer's
`pr_iteration_from_check_suite_listener`, via the SCM stream — so the
predicate rests on two filters there rather than one. Both resolve
through the shared `is_own_repo_pull_request` as of
#121724 (merged), which also fixed a foreign-base entry
shadowing the own-repo one. So `check_suite` takes exactly `check_run`'s
rule, with no carve-out, and the drop is a subset of both consumers'
no-op sets.

**The kill switch.** Unlike the existing parser drops, this one keys off
payload shape rather than a header, so it ships behind
`hybridcloud.webhookpayload.github_drop_checks_without_own_repo_pr`,
**default off**. As merged this is a strict no-op. One option covers
both event types.

**The signal that makes the switch usable.** A switch is only worth
having if a wrong predicate is detectable, and it was not:
`_write_activity_row` is a bare insert, so silently losing these events
would move no counter anywhere and GitHub — already 202'd — never
redelivers. `pr_metrics.check.activity_recorded` closes that gap. It
must stay **flat** when the option is enabled; any dip is the predicate
being wrong, visible within the hour instead of never.

`drop_unprocessed_event` also gains a `reason` tag
(`unprocessed_event_type` / `unconsumed_action` / `no_own_repo_pr`) so
the new drop is separable from the two existing ones. The metric is in
Datadog exclude-tags mode, so the tag indexes with no dashboard-side
config.

## Rollout

Enable the option, then watch two things together, per event type:

```
sum:sentry.github.webhook.drop_unprocessed_event{reason:no_own_repo_pr} by {event_type}.as_count()
sum:sentry.pr_metrics.check.activity_recorded{*} by {github_event}.as_count()
```

The first should climb toward ~3.75M/day for `check_run` and ~3.73M/day
for `check_suite` while the second does not move.
`forwarded_event{action:completed,has_own_repo_pr:false}` should fall to
zero for both over the same window — the tag and the drop now use the
same predicate, so there is no expected residual on either event type.

The option is a rollout control, not a permanent feature — it should be
removed once a week of flat activity volume confirms the predicate.

## Risk

Most of the reclaimed volume is not the subtle case. The cell's
`pr_metrics.check.foreign_pull_request` counter — one increment per
entry skipped for a non-matching `base.repo` — runs at 759K/day across
*both* check event types, counting entries rather than payloads, and
including payloads that also carried an own-repo entry and were
processed normally. So **at least ~79% of the drop is the empty
`pull_requests: []` case**: CI on a commit with no PR, where "the cell
does nothing" is `for ref in ()`, not an inference about repo identity.

One second-order effect, the same one #121434 called out
for `check_suite`: `GitHubWebhook.__call__` auto-creates missing
`Repository` rows and calls `update_repo_data()` for any event carrying
a `repository` key, independent of the processors, and dropped
deliveries no longer trigger that. Safe for the same reason — `push`,
`pull_request` and `issue_comment` all still flow through that path.

Minor observability change: code review's `record_webhook_received` /
`record_webhook_filtered(UNSUPPORTED_ACTION)` counters stop firing for
dropped `check_run.completed`. No behavior attached.

Fixes [CW-1838](https://linear.app/getsentry/issue/CW-1838)
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