Skip to content

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

Description

@knoxiboy

Problem Statement

When a user performs actions offline (e.g. creating a dispatch request or logging a confirmation), the transactions are stored in LocalStorage. When the connection is restored, the offline sync client triggers rapid parallel writes to Appwrite. This causes database ID conflicts and double-submission race conditions.

Proposed Solution

Implement a robust conflict-resolution and synchronization queue:

  1. Refactor src/offline-sync.js to use a serialized sync queue (FIFO).
  2. For each transaction, compare local modification timestamps against Appwrite server records.
  3. In src/conflict-resolver.js, implement three strategies: Server Wins, Client Wins, and Merge (prompting user selection for critical conflicts).
  4. Remove successfully synced tasks from LocalStorage only after server write acknowledgment.

Alternatives Considered

Overwriting database entries directly, but this can lead to data loss if multiple riders update the same order status concurrently.

Additional Context

Title: [BUG] Fix Offline Sync Conflict Resolution and Double-Submission Race Conditions
Level: Critical
Affected Files: src/offline-sync.js, src/conflict-resolver.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions