Fix: recovery amplification loop and provider echo race (INV-SAFETY-02)#47
Open
Droyder7 wants to merge 1 commit into
Open
Fix: recovery amplification loop and provider echo race (INV-SAFETY-02)#47Droyder7 wants to merge 1 commit into
Droyder7 wants to merge 1 commit into
Conversation
…ing logic; add integration tests for recovery scenarios
5342730 to
66cd864
Compare
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.
fixes #46
This PR resolves the unbounded file growth and data corruption loops observed during editor-bound
recoveries. The fix addresses a multi-layer root cause where the system misclassified its own
repairs as remote edits and inappropriately applied stale editor state back to the CRDT during
active recovery cycles.
Technical Details
The fix implements a defense-in-depth approach across three subsystems to enforce the
INV-SAFETY-02 and INV-EDIT-02 invariants:
Provider Echo Suppression (DiskMirror):
repair writes.
incoming "remote" updates and suppresses disk writes if they are confirmed to be echoes of
a recent local repair. This closes the race window where a stale echo could overwrite a
concurrent external disk edit.
Recovery Guard (EditorBindingManager):
isDiskAuthorityRecoveryActive predicate.
repair() (applying CRDT → editor). This prevents "Frankenstein" patches from stale editor
state from undoing a successful disk-authority recovery.
State Exposure (ReconciliationController):
to respect active recovery locks.
Origin Cleanup:
future classification failures.
Motivation
Previously, a local repair would trigger a Yjs provider echo that looked like a remote change.
This caused DiskMirror to schedule a disk write, which triggered a vault event, re-starting the
reconciliation and creating an infinite loop. Additionally, concurrent health checks in the editor
would often "heal" the CRDT back to a stale state before the editor had settled on the new
recovered content.
Verification
concurrent external edits.
active recovery.
Alternative Approaches Considered
We considered purely timing-based suppression, but content-hash verification in the
echo-suppressor was chosen for higher reliability, as it explicitly confirms the content matches
the repair before skipping the write.