Repository navigation
Reconcile offline edits with a hybrid logical clock - #81
Merged
Merged
Conversation
Replace device-clock last-writer-wins with a hybrid logical clock (Hlc / HybridLogicalClock in EntityVersions.kt), per-field-group LWW registers and versioned tombstones, persisted in a new EntityState table (migration 2.sqm). Stores, the sync facade and IncomingChangeRouter merge remote changes through these registers so merges are order-independent and idempotent, and an edit made after seeing a peer's change wins even when the local clock is slow. Adds EntityVersionsTest and OfflineConflictTest and updates existing store, bootstrap and serialization tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Offline edits from different devices used to be reconciled by device-clock last-writer-wins. Two problems followed: a device with a slow clock could lose an edit it made after seeing a peer's change, and concurrent edits to unrelated fields overwrote each other. This PR replaces that with:
Hlc/HybridLogicalClockinEntityVersions.kt): versions advance past any version a device has seen, so causally later edits win regardless of wall-clock skew.entity_statetable (EntityState.sq, migration2.sqm): stores the last known field values, versions and tombstones per space/entity. It is kept after a delete, cleared byclearAllSyncMetadata(so "Start over" and account deletion wipe it), and claimed with the other legacy-space tables.ChangeMessagegains optionalversions/deletedAt(null from older peers).SyncStoreFacade, the Store5 stores,LinkedTransferStoreandIncomingChangeRoutermerge through the registers.DatabaseBootstrapupgrades existing space-scoped databases that lackentity_statein place (by checking for the table, not trustinguser_version) rather than dropping data.This branch also merges the latest
main(#66–#75). It merged with no conflicts; the new account-deletion path wipesentity_statethroughwipeAll()→clearAllSyncMetadata.Tests
New:
EntityVersionsTest(12 tests, e.g.anEditMadeAfterSeeingAPeersChangeWinsEvenWithASlowClock,mergeIsOrderIndependentAndIdempotent) andOfflineConflictTest(8 tests). Updated: the store, bootstrap (v2 →entity_stateupgrade), snapshot and serialization tests.TeamCity CI steps run locally on the merged branch, all passing:
npm run test:security— 4 passedscripts/ci/test-glib-security.sh— passednpm audit(root + smoke) — 0 vulnerabilitiesscripts/enforce-architecture.sh— passedpython3 -m unittest discover -s scripts/ci/tests— 71 OKscripts/ci/check-version.py— 0.1.3 OKscripts/ci/run-jvm-tests.sh— 230 tests, 0 failures, 0 errors (first attempt)scripts/ci/test-web-database.cjs— passedscripts/ci/test-hosted-spaces.sh— passed./kotlin build -m server— passedOther compiles:
sharedfor wasmJs / iosSimulatorArm64 / android,web-app,perf-android, and theperf-iosKotlin compile all succeed. Theperf-iosXcode packaging step was not run locally because this clone doesn't have the gitignoredWebRTC.xcframework.🤖 Generated with Claude Code