Skip to content

perf(control): Drop check_run/check_suite completed with no pull request in their own repo - #121719

Merged
vaind merged 5 commits into
masterfrom
ivandlugos/cw-1838-drop-check-run-completed-without-own-repo-pr
Aug 11, 2026
Merged

vaind merged 5 commits into
masterfrom
ivandlugos/cw-1838-drop-check-run-completed-without-own-repo-pr

Conversation

@vaind

@vaind vaind commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

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

…wn repo

check_run.completed is the largest remaining line at the control parser --
12.1M/day at ~110ms average in the cell handler -- and a third of it does no
work when it lands. GitHub lists a PR on a check whenever they share a head
sha, including PRs based in *other* repositories, and pr_metrics'
_prs_from_check_payload resolves only entries whose base.repo is this webhook's
repo. A payload carrying none of those is a guaranteed no-op there.

Both sides of that comparison are in the payload, so control can make the call
without the cell's database: the cell looks its Repository row up by
external_id=str(event["repository"]["id"]), which is the same value the parser
compares against.

Measured at 31.7% of check_run.completed, ~3.6M requests/day (~4.1M rows after
cell fan-out) against a peak-hour backlog surplus of 110-140K rows/h.

check_suite is deliberately excluded despite carrying the same tag. Seer's
pr_iteration_from_check_suite_listener also consumes completed, and it resolves
runs by each entry's global pull_requests[].id without ever comparing base.repo
-- a suite based entirely in another repo is still work for it. Encoded as
ActionFilter.own_repo_pr_actions so the distinction lives next to the actions
rather than in the parser.

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.

The 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 moved
no counter anywhere. pr_metrics.check.activity_recorded is that signal -- it must
stay flat when the option is enabled. drop_unprocessed_event also gains a reason
tag so the new drop is separable from the two existing ones.

Fixes CW-1838
@vaind
vaind requested review from a team as code owners August 11, 2026 12:56
@linear-code

linear-code Bot commented Aug 11, 2026

Copy link
Copy Markdown

CW-1838

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 11, 2026
Comment thread src/sentry/pr_metrics/webhooks.py Resolved
The CHECK_SUITE comment claimed Seer's listener treats foreign-base pull requests as real work. It does read pull_requests[].id without comparing base.repo, but GitHub only attaches a PR to a suite on head_sha + head_branch, so a foreign-base entry is a PR with its head in this repo and its base elsewhere. Autofix opens both sides of a PR in one repo, so such an entry can never resolve one of its runs.

check_suite stays out because its share of no-op deliveries is unmeasured, not because the predicate would be wrong there.

Also drops the "10%" figure from _record_check_activity_metric: no sample_rate is passed, so the effective rate is deployment config and not something this docstring can state.
… 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.
@vaind vaind changed the title perf(control): Drop check_run.completed with no pull request in its own repo perf(control): Drop check_run/check_suite completed with no pull request in their own repo Aug 11, 2026

@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 32279c3. Configure here.

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 force-pushed the ivandlugos/cw-1838-drop-check-run-completed-without-own-repo-pr branch from e9556ec to 40d0ea2 Compare August 11, 2026 16:54
…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
vaind enabled auto-merge (squash) August 11, 2026 18:57
@vaind
vaind merged commit f92447e into master Aug 11, 2026
94 of 95 checks passed
@vaind
vaind deleted the ivandlugos/cw-1838-drop-check-run-completed-without-own-repo-pr branch August 11, 2026 19:14
vaind added a commit that referenced this pull request Aug 24, 2026
Moves the rolled-out value of
`hybridcloud.webhookpayload.github_drop_checks_without_own_repo_pr` into
the registered default, so the automator can drop its temporary
control-silo override
([options#9218](getsentry/sentry-options-automator#9218)).

Baseline, not removal: the option stays registered and the parser keeps
reading it, so setting it `false` is still the revert and needs no
deploy.

### Why

The drop ([#121719](#121719))
shipped off behind an option because its predicate reads payload shape
rather than a header — if it were wrong, real check activity would
silently stop being recorded. Two days on the control silo say it is
right. Same-clock 11:58–12:55Z windows, which avoids attributing the
European CI ramp to the change:

| Signal | 08-13 vs 08-12 | 08-13 vs 08-11 (pre-toggle) |
| --- | --- | --- |
| `check.activity_recorded` check_run | +2.2% | metric did not exist |
| `check.activity_recorded` check_suite | +1.8% | metric did not exist |
| `forwarded_event` check_run `has_own_repo_pr:true` | +3.3% | +5.4% |
| `forwarded_event` check_suite `has_own_repo_pr:true` | +2.3% | +0.8% |
| `deliver_webhooks.saved` `provider:github` | +0.7% | **−18.3%** |

The self-normalizing test — recorded activity over forwarded events,
which cancels out traffic volume — never stepped at the cutover:
check_run held 0.72–0.88 and check_suite 0.73–0.92 across 30 hours
spanning the toggle. `has_own_repo_pr:false` has emitted nothing since
11:57Z on 08-12, one minute before these windows open. Net effect:
roughly 18% fewer GitHub webhookpayload rows/day — about 14% of all
rows, since GitHub is not the only provider writing them.

### Blast radius

Control silo only. `IntegrationControlMiddleware._should_operate`
returns early unless `SiloMode` is `CONTROL`, so region, single-tenant,
and self-hosted deployments never reach this parser whatever the default
says. The control silo already runs `true` via the automator, so no live
behavior changes here — only where the value comes from.

### Tests

Six tests depended on the old default:

- The two `..._is_forwarded_by_default` tests become
`..._is_dropped_by_default`, each gaining an explicit `option: False`
counterpart covering the kill switch.
- Three `forwarded_event` metric tests asserting
`has_own_repo_pr:"false"` now pin the option off — with the drop on,
that tag is unreachable.
- `test_forwards_check_run_completed` /
`test_forwards_check_suite_completed` now carry an own-repo PR, so they
exercise the mailbox routing that production actually takes.

`tests/sentry/middleware/integrations/` passes, 174 tests.

### Merge order

Deploy this to all regions **before** merging
[options#9218](getsentry/sentry-options-automator#9218).
The other order drops the control-silo value while the deployed default
is still `false`, reverting the drop for the length of the gap.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — efeb9080 Deployed Aug 11, 2026 by vercel[bot]
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