fix(crdt): stop sync_from_files clobbering unmaterialized local edits#124
Merged
Conversation
sync_from_files unconditionally overwrote each entity's CRDT content with the file's content, so an entity edited in the CRDT but not yet written to disk was silently reverted on the next sync. That made the CRDT non- authoritative and the edit-then-apply loop sequence-dependent. Reconcile each entity with a 3-way rule (base = last sync, CRDT = possibly locally-edited, file = current): seed on first sight, advance the ancestor when file and CRDT already agree (e.g. right after `weave apply`), preserve the local edit when the file is unchanged, fast-forward when only the file changed, and flag a conflict when both changed. The decision is a pure `reconcile_entity_content` fn with unit tests, including the regression that a local edit survives a re-sync.
There was a problem hiding this comment.
inspect review
Triage: 9 entities analyzed | 0 critical, 0 high, 3 medium, 6 low
Verdict: standard_review
Findings (0)
Reviewed by inspect | Entity-level triage found 0 high-risk changes
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.
Problem
sync_from_filesunconditionally overwrote each entity's CRDTcontentwith the file's content, so an entity edited in the CRDT but not yet written to disk was silently reverted on the next sync. That made the CRDT non-authoritative and the edit-then-weave applyloop sequence-dependent (any intervening sync dropped the edit).Fix
Reconcile each entity with a 3-way rule (
base= last sync, CRDT = possibly locally-edited,file= current):weave apply): only move the ancestor.The decision is a pure
reconcile_entity_contentfunction with unit tests, including the regression that a local edit survives a re-sync. This makes the CRDT genuinely the source of truth, which the read-with-sem / edit-with-weave /weave applyloop depends on.Tests
10 lib unit tests (5 new reconcile cases) + 34 integration tests pass, no regressions.