Skip to content

fix(api): don't double-run webhook side effects on a concurrent duplicate#355

Open
cavidelizade wants to merge 1 commit into
Devlaner:mainfrom
cavidelizade:fix/webhook-dedup-race
Open

fix(api): don't double-run webhook side effects on a concurrent duplicate#355
cavidelizade wants to merge 1 commit into
Devlaner:mainfrom
cavidelizade:fix/webhook-dedup-race

Conversation

@cavidelizade

Copy link
Copy Markdown
Contributor

Summary

Webhook deduplication was a check-then-act: ExistsByDeliveryID then Create. Two concurrent deliveries of the same GitHub event both pass the exists check; one Create wins and the other fails the unique delivery_id constraint. That error was only logged, so the losing racer fell through to dispatch and ran the side effects a second time, giving duplicate bot comments and duplicate or oscillating state changes.

Linked issues

Closes #332

Type of change

  • Bug fix (fix:)

Surface

  • API (apps/api/)

What changed

Treat a duplicate-key error from Create (gorm.ErrDuplicatedKey, already used elsewhere with TranslateError on) as "already processed" and return before dispatching. Sequential redeliveries were already short-circuited by the exists check; this closes the concurrent window.

Test plan

  • go build, go vet, go test ./... green

AI assistance

  • AI tools were used, tool(s): Claude Code (Opus 4.8), commits carry a Co-Authored-By: trailer

…cate

Webhook dedup was a check-then-act: ExistsByDeliveryID then Create. Two
concurrent deliveries of the same event both pass the exists check; one Create
wins and the other fails the unique delivery_id constraint. That error was only
logged, so the losing racer fell through to dispatch and ran the side effects
again (duplicate bot comments, duplicate or oscillating state changes).

Treat a duplicate-key error from Create as "already processed" and return
without dispatching.

Closes Devlaner#332

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cavidelizade
cavidelizade requested a review from a team as a code owner July 16, 2026 20:14
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 170e4d08-1bf8-4887-845e-56d49b66abe3

📥 Commits

Reviewing files that changed from the base of the PR and between 61bc903 and a000aa4.

📒 Files selected for processing (1)
  • apps/api/internal/service/github_events.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub webhook dedup has a concurrency race that double-runs side effects

1 participant