Skip to content

feat(pr-metrics): Record sentry-app PR attribution on close#119106

Open
giovanni-guidini wants to merge 1 commit into
masterfrom
gio/feat-pr-metrics-sentry-app-attribution-on-close
Open

feat(pr-metrics): Record sentry-app PR attribution on close#119106
giovanni-guidini wants to merge 1 commit into
masterfrom
gio/feat-pr-metrics-sentry-app-attribution-on-close

Conversation

@giovanni-guidini

@giovanni-guidini giovanni-guidini commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

There are some attribution signals that we should be capturing but are not.
The difference comes basically from events that ai.autofix.pr.closed|merged record 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 (the pull_request webhook processor for PR Merge Live Metrics) only recorded the SENTRY_APP author signal on the opened action. A Sentry-authored PR that missed its open webhook — or was opened before the organizations:pr-metrics-attribution flag was enabled — therefore had no attribution row, so it was never tracked for emission when it closed.

This re-checks the author signal on closed as well, so those PRs still get a SENTRY_APP attribution and can emit at their terminal event.

Details

  • _write_author_attribution writes only when the PR author is the Seer/Sentry GitHub app, so this is scoped to SENTRY_APP. MCP and delegated-agent attribution stay opened-only for now.
  • record_attribution_signal is 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 refreshes signal_details in place (resolved_group_ids may resolve more at close than at open), which is acceptable here.
  • handle_attribution runs before handle_emission in the same webhook delivery, so a PR first attributed at close is tracked in time to emit.
  • run_id is left unset and group_ids is whatever resolved_group_ids returns (empty for group-less Sentry PRs) — no run-state lookup is added on this path.

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.
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 7, 2026
@giovanni-guidini giovanni-guidini marked this pull request as ready for review July 7, 2026 14:32
@giovanni-guidini giovanni-guidini requested a review from a team July 7, 2026 14:33
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