Repository navigation
perf(github): stop recording a delivery for events no handler reads - #248
Conversation
Every webhook delivery does an insert, a transaction and an update. Only six event names reach a handler: pull_request, pull_request_review and check_suite through parseGithubEvent, plus installation, installation_repositories and repository. Everything else runs that whole sequence and ends as 'ignored'. Production, over the 15 days the table covers: 22,990 deliveries recorded 2,560 for an event that reaches a handler 20,430 for one that does not, which is 89% check_run alone is 6,264 of them, workflow_job 6,102. The table is the largest in the database and almost none of it is product data. Recognise an unhandled event after the signature check and return 200 without touching the database. GitHub keeps its own delivery log, so nothing that could be acted on is lost. The list of handled events could go stale the moment someone adds a parser and forgets it, which would silently drop the new event, so a test asserts that every event GitHub actually sends us either is handled or is one parseGithubEvent genuinely cannot read.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 55 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile was right that the drift test was weaker than it looked. It asserted that unhandled events fail to parse, but it synthesised the payload itself, so a new parser added without a matching list entry could still be handed a payload it rejects, and the test would pass while the route dropped the event for real. A better test would still have been a test. Derive the answer instead: the three parsers become a lookup table, parseGithubEvent is a lookup into it, and handlesGithubEvent asks the same table. Adding a parser now makes the route accept that event with no second place to update, so the drift the test was guarding against cannot happen. Verified by adding an 'issues' parser to the table and touching nothing else: the event becomes handled immediately.
The waste
Every webhook delivery does an insert, a transaction, and an update. But only six event names reach a handler:
pull_request,pull_request_review,check_suiteviaparseGithubEventinstallation,installation_repositories,repositoryviaapplyGithubInstallationEventEverything else runs that whole sequence and ends up marked
ignored.Measured against production, over the 15 days
webhook_deliverycurrently covers:The worst offenders on their own:
check_runworkflow_jobworkflow_runstatusrepository_dispatchwebhook_deliveryis the largest table in the database and almost none of it is product data.The change
Recognise an unhandled event straight after the signature check and return
200without touching the database. GitHub keeps its own delivery log, so nothing that could have been acted on is lost.Ordering matters and is preserved: the signature is still verified first, so this is not a way to make the endpoint do unauthenticated work. A test covers that a forged unhandled event is still refused with
401.The drift hazard, and the test for it
The handled list lives next to the code that reads these events, but it could still go stale the moment someone adds a parser branch and forgets to list the event, which would silently drop the new event at the door. That is a worse failure than the waste this PR removes.
So there is a test asserting that every event GitHub actually sends this app either is handled, or is one
parseGithubEventgenuinely cannot read. Verified by mutation: droppingcheck_suitefrom the list makes it fail.Still open, deliberately not done here
docs/github-app.mdalready documents the correct subscription set.Tests
Services github suite: 101 pass. Web webhook suite: 34 pass. Both mutation checked.
Greptile Summary
The PR avoids database work for signed GitHub webhook events that have no handler and refactors parsed-event dispatch around a shared registry.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[GitHub webhook request] --> B[Verify signature] B -->|Invalid| C[Return 401] B -->|Valid| D[Validate event and delivery headers] D --> E{Handler registered?} E -->|No| F[Return 200 unhandled] E -->|Yes| G[Claim delivery in database] G --> H[Apply installation or parsed event] H --> I[Update delivery result]Reviews (2): Last reviewed commit: "Merge main into perf/webhook-noise" | Re-trigger Greptile