Skip to content

Prevent concurrent refresh operations from racing in EventManager#887

Draft
Copilot wants to merge 3 commits intocodex/update-error-handling-in-setuppublishersfrom
copilot/sub-pr-886
Draft

Prevent concurrent refresh operations from racing in EventManager#887
Copilot wants to merge 3 commits intocodex/update-error-handling-in-setuppublishersfrom
copilot/sub-pr-886

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 29, 2026

Addresses two issues in the EventManager refresh error handling introduced in PR #886: a race condition where concurrent refreshes could overwrite newer data with stale snapshots, and missing test coverage for the error fallback behavior.

Changes

  • EventManager.swift: Added maxPublishers: .max(1) to .flatMap operator to serialize refresh operations and cancel in-flight refreshes when new ones trigger
  • FakeEventStore.swift: Added error injection flags (shouldThrowOnFetch*) and call counters to enable testing fetch failures
  • EventManagerTests.swift: Added RefreshErrorHandlingTests.test_eventsPreservedOnRefreshFailure() verifying calendars/events retain previous values when fetches fail

Race condition scenario (now prevented)

// Before: Multiple refreshes could run concurrently
1. Refresh A starts, captures current = [Event1]
2. Refresh B starts, succeeds, publishes [Event1, Event2]
3. Refresh A fails, publishes current = [Event1]  // ❌ Overwrites newer data

// After: maxPublishers: .max(1) cancels Refresh A when B starts
1. Refresh A starts, captures current = [Event1]  
2. Refresh B starts, cancels A, succeeds, publishes [Event1, Event2]  // ✅

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 29, 2026 22:20
Co-authored-by: leits <12017826+leits@users.noreply.github.com>
Co-authored-by: leits <12017826+leits@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix last events loss on refresh errors Prevent concurrent refresh operations from racing in EventManager Jan 29, 2026
Copilot AI requested a review from leits January 29, 2026 22:25
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants