fix(hub-client): replace updateText with positional splice for CRDT sync#87
Open
shikokuchuo wants to merge 2 commits intomainfrom
Open
fix(hub-client): replace updateText with positional splice for CRDT sync#87shikokuchuo wants to merge 2 commits intomainfrom
updateText with positional splice for CRDT sync#87shikokuchuo wants to merge 2 commits intomainfrom
Conversation
… sync Eliminates race condition where concurrent remote edits were lost because `updateText` diffed against stale Automerge state. Monaco's `IModelContentChange` events now map directly to Automerge splice operations
Collaborator
Author
|
@vezwork just leaving a note as you were interested in this. This will probably be merged by the time you get to this, but we can always amend further depending on how you envisage bidirectional changes to work. |
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 #74 - a race condition where edits from other users could be silently deleted during collaborative editing.
Problem
When you type in the editor, the app sends your full document text to the sync engine, which diffs it against its own copy to figure out what changed. But if a collaborator's edit arrives between reading the editor and running that diff, the diff sees their new text as "not in the editor" and deletes it.
Fix
Instead of sending the full document and diffing, we now send the exact edit operations — "insert 'x' at position 5" or "delete 3 characters at position 10". The sync engine applies these directly as positional splices. Since it never diffs against the full document, there's no window where a collaborator's edit can be misinterpreted as something to delete. Automerge's CRDT is designed to merge concurrent positional edits correctly.
This also improves how the preview panel writes content back to the editor (e.g., when you reorder slides by dragging). Previously this used the same racy full-document path. Now it routes through the editor as a normal edit, which also means
Ctrl+Zundoes it.Unchanged
Replay mode still uses the old full-document path, which is fine — it doesn't involve concurrent editing.