Skip to content

fix: offline sync conflict resolution and double-submission race conditions (#674)#682

Open
knoxiboy wants to merge 1 commit into
Shruti070107:mainfrom
knoxiboy:fix/issue-674-offline-sync
Open

fix: offline sync conflict resolution and double-submission race conditions (#674)#682
knoxiboy wants to merge 1 commit into
Shruti070107:mainfrom
knoxiboy:fix/issue-674-offline-sync

Conversation

@knoxiboy

@knoxiboy knoxiboy commented Jun 13, 2026

Copy link
Copy Markdown

Resolves #674

Description

This PR refactors the offline sync logic to use a serialized first-in-first-out (FIFO) queue and introduces a conflict-resolution system with three strategies: Server Wins, Client Wins, and Merge. It prevents database ID conflicts and double-submission race conditions when syncing offline actions back to the Appwrite server.

What changed

  • Updated syncPendingActions in src/offline-sync.js to run tasks sequentially.
  • Integrated a check that fetches the server state of the record via /api/records/${id} prior to applying updates.
  • Refactored src/conflict-resolver.js to implement resolveConflict supporting server-wins, client-wins, and merge strategies.
  • Prompts the user using window.confirm for manual selection on critical conflicts under the merge strategy.
  • Deletes items from IndexedDB only after a successful server acknowledgment.

Why

When internet connection recovers, rapid parallel uploads of offline actions can overwrite each other or create duplicate database entries, causing race conditions. Serializing writes and checking server timestamps solves this issue.

How to test

  1. Run npm run test to verify structure health.
  2. Go offline in the app and perform some dispatch/pickup updates.
  3. Edit the same records directly on the server (simulated) to simulate a conflict.
  4. Reconnect the app to online state and verify that the sync queue correctly compares timestamps, prompts the user for status discrepancies, and applies the selected strategy sequentially.

Checklist

  • Tested changes locally
  • No lint/syntax errors introduced
  • Matches all issue criteria

Files Affected

  • src/offline-sync.js
  • src/conflict-resolver.js

@knoxiboy

Copy link
Copy Markdown
Author

@Shruti070107 Please review this pr and merge it

1 similar comment
@knoxiboy

Copy link
Copy Markdown
Author

@Shruti070107 Please review this pr and merge it

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.

[Task] Fix Offline Sync Conflict Resolution and Double-Submission Race Conditions

1 participant