Skip to content

feat: add cryptographic conflict resolution engine for offline sync queues#619

Merged
Nitya-003 merged 4 commits into
Nitya-003:mainfrom
Neelr1912:feature/conflict-resolution-engine
Jul 7, 2026
Merged

feat: add cryptographic conflict resolution engine for offline sync queues#619
Nitya-003 merged 4 commits into
Nitya-003:mainfrom
Neelr1912:feature/conflict-resolution-engine

Conversation

@Neelr1912

Copy link
Copy Markdown
Contributor

📌 Overview
This PR implements a Cryptographic Conflict Resolution Engine to safely sequence and merge offline updates in CropChain, addressing potential race conditions and blockchain transaction ordering issues when multiple offline users edit the same batch.

Key Changes:

Logical Versions & Vector Clocks: Added version and vectorClock schemas to the MongoDB batch model to track concurrent updates logic.
Conflict Detection Middleware: Implemented a backend middleware that evaluates incoming sync payloads against the current MongoDB and Blockchain state (expectedVersion logical clocks, vector clock concurrency check, sequential stage transition checks, and on-chain latest update validation).
Idempotency Handling: Gracefully permits identical duplicate offline sync requests while rejecting out-of-sync ones with a 409 Conflict.
WebSocket Push Notifications: Pushes real-time sync conflict alerts to the client on failure.
Radix Manual Resolution UI: Created a beautiful ConflictResolutionModal component that allows users to review current DB/Blockchain state side-by-side with their local state, providing interactive Discard or Edit & Resubmit strategies.
Robust ID Mapping: Integrated remapping of temporary TEMP-xxxx batch IDs to official database IDs for pending updates once batch creation is successfully synced.
🛠️ Type of Change
⛓️ Smart Contract (Solidity changes, Gas optimization)
💻 Frontend (UI/UX, React components, Tailwind)
⚙️ Backend (API routes, MongoDB schemas, Middleware)
📄 Documentation (README, Roadmap updates)
🧪 Testing (Hardhat tests, Jest/Vitest)
🔗 Related Issue
Closes #600

🧪 Testing & Verification
Smart Contracts: NA (Verified via mock smart contract queries, no state changes made to CropChain.sol directly)
Frontend: Yes (Radix UI components verified on desktop and mobile responsive viewport styles)
Integration: Yes (Jest backend test suite verifying logical clocks, vector clock concurrency, stage transition limits, and blockchain state discrepancies)

✅ PR Checklist
My code follows the project's style guidelines.
I have commented my code, particularly in complex areas (e.g., conflict checking rules, vector clock merging).
I have updated the documentation accordingly.
My changes generate no new warnings.
💬 Additional Notes
The backend unit tests are fully configured under backend/tests/conflictDetector.test.js and all 6 tests run successfully without any open handle leakage or database timeouts.

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

@Neelr1912 is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel.

A member of the Team first needs to authorize it.

- Resolve SyncStatusIndicator.tsx merge conflict between
  feature/conflict-resolution-engine and main: keep all conflict-
  detection state & ConflictResolutionModal integration from the PR
  while using i18n t() calls from main throughout

- Add ConflictResolutionModal component (Radix UI Dialog) with
  side-by-side local vs server state diff, Discard and Edit &
  Resubmit strategies

- Extend SyncManager with discardPendingUpdate() and
  resubmitWithResolution() methods for conflict resolution actions

- Extend OfflineStorageService: add 'conflict' status to PendingUpdate
  union, add conflictDetails/stage/pendingId fields, add
  updatePendingUpdateData() method

- Add 21 new sync.* i18n keys (conflict UI strings) to en.json,
  hi.json, and add missing offline + sync sections to mr.json

Closes Nitya-003#619
@Neelr1912 Neelr1912 force-pushed the feature/conflict-resolution-engine branch from 39e2345 to a75a536 Compare July 6, 2026 19:00
Neelr1912 added 3 commits July 7, 2026 00:38
- Add a fallback dummy HMAC secret in auditLogger.js to prevent crashes during tests due to missing AUDIT_EVENT_HMAC_SECRET env variable.
- Update react-i18next useTranslation t function type signature in global.d.ts to allow additional option arguments, resolving numerous compilation errors across frontend pages.
- In VerificationBadge.test.tsx, update assertions to expect translation keys ('verification.verified' and 'verification.unverified') rather than hardcoded English text.
- In profile/page.test.tsx, update role-based button selectors (profile.editProfile, profile.saveChanges) and toast error validation checks to assert their respective translation keys to align with the i18n implementation.
@Neelr1912

Copy link
Copy Markdown
Contributor Author

Hi @Nitya-003 , you can merge and close

@Nitya-003 Nitya-003 added frontend gssoc:approved gssoc'26 approved quality:clean *1.2 for contributor +5 pts for mentor level:intermediate 35 pts for contributor 20 pts for mentor labels Jul 7, 2026
@Nitya-003 Nitya-003 merged commit 8c59318 into Nitya-003:main Jul 7, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend gssoc:approved gssoc'26 approved level:intermediate 35 pts for contributor 20 pts for mentor quality:clean *1.2 for contributor +5 pts for mentor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Build a Cryptographic Conflict Resolution Engine for Offline Sync Queues

2 participants