Skip to content

perf(github): stop recording a delivery for events no handler reads - #248

Merged
imshashank merged 3 commits into
mainfrom
perf/webhook-noise
Aug 8, 2026
Merged

imshashank merged 3 commits into
mainfrom
perf/webhook-noise

Conversation

@imshashank

@imshashank imshashank commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

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_suite via parseGithubEvent
  • installation, installation_repositories, repository via applyGithubInstallationEvent

Everything else runs that whole sequence and ends up marked ignored.

Measured against production, over the 15 days webhook_delivery currently covers:

Deliveries
Recorded 22,990
For an event that reaches a handler 2,560
For one that does not 20,430 (89%)

The worst offenders on their own:

Event Count
check_run 6,264
workflow_job 6,102
workflow_run 2,923
status 1,599
repository_dispatch 1,496

webhook_delivery is 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 200 without 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 parseGithubEvent genuinely cannot read. Verified by mutation: dropping check_suite from the list makes it fail.

(fail) the handled event list > does not drop an event that some handler would have read
 3 pass
 1 fail

Still open, deliberately not done here

  • Retention. A 30 day prune would delete nothing today: the oldest row is 15 days old. Worth adding once growth is bounded, which this PR is the bigger half of.
  • Unsubscribing in the GitHub App. Better still, since then the request never arrives. That is a settings change on the App, not code, and docs/github-app.md already 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.

  • Adds an early response for unhandled events after signature and required-header validation.
  • Derives handled parsed-event names from the parser registry to prevent list drift.
  • Adds route and service tests for signature ordering, database writes, and parser coverage.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/web/src/app/api/webhooks/github/route.ts Adds the post-authentication handled-event gate that skips delivery persistence for events no handler reads.
apps/web/tests/app/api/webhooks/github/route.test.ts Covers database avoidance, rejection of forged unhandled events, and continued persistence of handled events.
packages/services/src/github/index.ts Refactors event parsing into a registry and derives handled parsed-event membership from that registry.
packages/services/tests/github/handled-events.test.ts Verifies handled-event classification and supplies valid payloads for every current parser branch.

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]
Loading

Reviews (2): Last reviewed commit: "Merge main into perf/webhook-noise" | Re-trigger Greptile

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.
@imshashank
imshashank requested a review from pulkitxm as a code owner August 8, 2026 18:03
@vercel

vercel Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 8, 2026 6:16pm

Request Review

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI area: integrations GitHub, Slack and webhooks labels Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@imshashank, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 706a8826-1e2d-4732-8b8e-56f79db9b228

📥 Commits

Reviewing files that changed from the base of the PR and between bf2fd87 and 03da843.

📒 Files selected for processing (4)
  • apps/web/src/app/api/webhooks/github/route.ts
  • apps/web/tests/app/api/webhooks/github/route.test.ts
  • packages/services/src/github/index.ts
  • packages/services/tests/github/handled-events.test.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.
@imshashank
imshashank merged commit e7a67c1 into main Aug 8, 2026
12 checks passed
@imshashank
imshashank deleted the perf/webhook-noise branch August 8, 2026 18:22

This branch was successfully deployed

1 active deployment
Preview — 03da843d Deployed Aug 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: integrations GitHub, Slack and webhooks area: web The Next.js app and its UI tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant