fix(code-review): Add cache to dedupe github webhook events#107734
Open
suejung-sentry wants to merge 3 commits intomasterfrom
Open
fix(code-review): Add cache to dedupe github webhook events#107734suejung-sentry wants to merge 3 commits intomasterfrom
suejung-sentry wants to merge 3 commits intomasterfrom
Conversation
suejung-sentry
commented
Feb 5, 2026
|
|
||
|
|
||
| def _get_webhook_seen_cluster() -> RedisCluster[str] | StrictRedis[str]: | ||
| return redis_clusters.get("default") |
724dc45 to
0230d2e
Compare
suejung-sentry
commented
Feb 6, 2026
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| WEBHOOK_SEEN_TTL_SECONDS = 20 |
Member
Author
There was a problem hiding this comment.
I picked 20 seconds because per the redash, if there ever is a dupe, they happen within 500 milliseconds of each other. I thought 20 seconds would comfortably cover that and any errant github redelivery behavior
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.
This PR handles webhook delivery deduplication by introducing redis idempotency keys for the github webhook id.
GitHub guarantees "at-least-once" delivery so may send duplicate webhooks. We have seen anecdotally that seer can receive multiple requests for a single commit (from a pull_request.synchronize event) within 500 milliseconds of each other (redash).
It's unclear whether GitHub is delivering the webhook twice or something in our control-->regional forwarding queues is causing redelivery. In any case, it seems likely that the same payload is getting processed with the same github webhook id. So use that as the idempotency key.
I considered whether we should go for a lock instead. The downside of that is the lock would release after the function returns, which may happen sooner than the 500 milliseconds we are currently seeing dupes in.
So instead in this PR, we just say any webhook with the same webhook id delivered within the same 20 second window are not replayed and re-forwarded to seer.
I chose 20 second TTL to cover the 500 milliseconds period and any errant github retry+backoff behavior.
Redis should be able to handle this load which is one SET per github webhook that makes it past our "preflight" feature enablement filters (a max hour is around 2,000 code reviews, so say 1 request per second in a peak hour). Also the keys are small with a short TTL.
Closes CW-673