Skip to content

fix(crdt): stop sync_from_files clobbering unmaterialized local edits#124

Merged
rs545837 merged 1 commit into
mainfrom
fix/weave-sync-authority
Jul 1, 2026
Merged

fix(crdt): stop sync_from_files clobbering unmaterialized local edits#124
rs545837 merged 1 commit into
mainfrom
fix/weave-sync-authority

Conversation

@rs545837

@rs545837 rs545837 commented Jul 1, 2026

Copy link
Copy Markdown
Member

Problem

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-weave apply loop 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):

  • Seed on first sight (base empty): take the file.
  • AdvanceBase when file and CRDT already agree (e.g. right after weave apply): only move the ancestor.
  • PreserveLocal when the file is unchanged since last sync: keep the local edit (this is the bug).
  • FastForward when only the file changed: take the file.
  • Conflict when both changed: preserve local and flag it instead of silently dropping a side.

The decision is a pure reconcile_entity_content function 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 apply loop depends on.

Tests

10 lib unit tests (5 new reconcile cases) + 34 integration tests pass, no regressions.

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.
@rs545837 rs545837 merged commit c6e39bd into main Jul 1, 2026

@inspect-review inspect-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant