feat(pr-metrics): Record sentry-app PR attribution on close#119106
Open
giovanni-guidini wants to merge 1 commit into
Open
feat(pr-metrics): Record sentry-app PR attribution on close#119106giovanni-guidini wants to merge 1 commit into
giovanni-guidini wants to merge 1 commit into
Conversation
handle_attribution only wrote the SENTRY_APP author signal on the PR 'opened' event. A Sentry-authored PR that missed its open webhook (or was opened before the attribution flag was enabled) then had no attribution row, so it was never tracked for emission at close. Re-check the author signal on 'closed' as well. record_attribution_signal is keyed on (pull_request, signal_type, source), so re-running when the row already exists won't duplicate it — it refreshes signal_details in place (e.g. resolved_group_ids may return more at close than at open), which is acceptable here. handle_attribution runs before handle_emission in the same delivery, so a PR first attributed at close is tracked in time to emit. Scoped to SENTRY_APP for now: MCP and delegated-agent attribution stay open-only.
joseph-sentry
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are some attribution signals that we should be capturing but are not.
The difference comes basically from events that
ai.autofix.pr.closed|mergedrecord but we don't record attribution to.I think it could be the webhooks come out of order for PRs that open and close super fast? I've seen an example that the open-close was like 3mins. Maybe things get swapped and we don't process the attribution in time.
Because this one is cheap enough we can just double-check on close. This should be pretty safe to do.
AI fluff
Summary
handle_attribution(thepull_requestwebhook processor for PR Merge Live Metrics) only recorded theSENTRY_APPauthor signal on theopenedaction. A Sentry-authored PR that missed its open webhook — or was opened before theorganizations:pr-metrics-attributionflag was enabled — therefore had no attribution row, so it was never tracked for emission when it closed.This re-checks the author signal on
closedas well, so those PRs still get aSENTRY_APPattribution and can emit at their terminal event.Details
_write_author_attributionwrites only when the PR author is the Seer/Sentry GitHub app, so this is scoped toSENTRY_APP. MCP and delegated-agent attribution stayopened-only for now.record_attribution_signalis keyed on(pull_request, signal_type, source)— the model's unique constraint — so re-running at close doesn't duplicate the row. When it already exists it refreshessignal_detailsin place (resolved_group_idsmay resolve more at close than at open), which is acceptable here.handle_attributionruns beforehandle_emissionin the same webhook delivery, so a PR first attributed at close is tracked in time to emit.run_idis left unset andgroup_idsis whateverresolved_group_idsreturns (empty for group-less Sentry PRs) — no run-state lookup is added on this path.