feat(offline): deterministic conflict resolution and idempotent sync convergence - #1146
Open
zakariyaufarida5-wq wants to merge 2 commits into
Open
Conversation
…convergence (closes rinafcode#1144) - Version-vector based conflict detection and deterministic per-entity merge strategies, immune to device clock drift - Idempotent replay via client-generated operation ids with ack dedupe, capped exponential backoff, and a dead-letter queue - Transactional all-or-nothing batch drain with rollback and a resumable cursor that survives app restarts - UI-facing pending/conflicted/resolved state via offline hooks and the ConflictResolver, plus retention GC for acked records and a service worker background-sync trigger
…concile sync engine Keeps the deterministic offline-sync reconciliation while adopting the realtime reconnect catch-up broadcast added in rinafcode#1143/rinafcode#1145.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes offline sync deterministic and convergent for the IndexedDB queue (closes #1144):
version+updatedBy+ Lamport logical clock) replaces pure timestamp LWW. Merges are stable regardless of device clock drift, with per-entity-type merge strategies (course_progressuses max-progress / OR-completion).operationId; acknowledged ids are persisted in a dedupe map so duplicate delivery applies exactly once. Retries use capped exponential backoff, and operations that exhaust their retry cap move to a dead-letter queue (with manual retry).useOfflineSync/useOfflineModeexposepending/conflicted/resolvedcounts plus conflicts; theConflictResolverdisplays the state and both version vectors. Acked records are garbage-collected per the retention policy, and the service worker triggers a drain via background sync when connectivity returns.synchronizationEngine/persistenceLayer) is updated withlastSyncedandsyncStatusand broadcast across tabs.Tests
src/services/__tests__/offlineSync.test.ts— idempotent replay under duplicate delivery, operationId propagation, batch rollback on partial failure, cursor resume after restart, dead-lettering + retry, in-drain backoff retry, deterministic auto-merge across clock skew, manual conflict surfacing/resolution, retention GC, sync status.src/lib/conflict/__tests__/resolver.test.ts— version-vector comparison, deterministic/commutative merges across reordered and clock-skewed inputs, per-entity strategies, legacy fallback.src/testing/conflict.test.tsandOfflineSyncManager.test.tscontinue to pass (the latter was previously unloadable due to a broken relative import, now fixed).CI
Type-check, lint, validate:ui, validate:web3, and
next buildall pass locally.closes #1144