Skip to content

fix: delete the duplicate event when a parallel sync already tracks it - #1055

Merged
jaspermayone merged 2 commits into
mainfrom
fix-duplicate-event-race
Nov 16, 2026
Merged

jaspermayone merged 2 commits into
mainfrom
fix-duplicate-event-race

Conversation

@jaspermayone

Copy link
Copy Markdown
Member

Bug: two syncs can create the same calendar event in parallel. The second sync inserts its event at Google or Microsoft, and then its tracking row fails. CourseCalendars::Provider#create_event rescued only ActiveRecord::RecordNotUnique. When the other sync's row was already committed, the uniqueness validation raised RecordInvalid first. The sync then failed, and the event it had just inserted stayed as a duplicate in the student's calendar. The tests pass (#1054) found this. It left a pending spec for it.

What changes

  • create_event and create_friend_meeting_event share one helper, track_new_event. On RecordNotUnique, or on RecordInvalid with :taken on a source column, the helper deletes the duplicate it just inserted. It keeps the other sync's row and reports the error as handled (ids only). Other validation errors still raise.
  • The row insert runs in a savepoint, so a unique violation cannot abort an outer transaction.
  • A Google friend-meeting duplicate that went out with invitations is deleted with sendUpdates=all, so the invited friends get the cancellation. Microsoft Graph already cancels.
  • If the delete of the duplicate fails, the failure is reported with the event id, and the sync goes on.
  • A create that loses the race counts as skipped, not created. A recreate that loses it also counts as skipped.

Checks

  • The full suite with CI=1 passed: 6659 examples, 0 failures. Line coverage is 96.18% and branch coverage is 86.29%.
  • The pending spec from test: make service specs fail only on a regression #1054 now passes. New specs cover the RecordNotUnique path, a failed delete, a validation error that must still raise, the stats, and the friend-meeting race on Google (with and without invitations) and Microsoft.
  • RuboCop is clean.
  • An adversarial review found four gaps: friend-meeting cancellations, a failed delete, stats and test gaps. All are fixed.

@jaspermayone
jaspermayone added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 2d930e6 Nov 16, 2026
6 checks passed
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.

1 participant