feat(collaborator): add appendContent RPC for merge (non-clobbering) writes#10959
Open
jasonestewart wants to merge 1 commit into
Open
feat(collaborator): add appendContent RPC for merge (non-clobbering) writes#10959jasonestewart wants to merge 1 commit into
jasonestewart wants to merge 1 commit into
Conversation
…writes The collaborator service only exposes full-replace writes (createContent / updateContent). updateContent clears the document's Y.XmlFragment before applying the incoming update, so a read-modify-write from an automation silently clobbers any concurrent edits (e.g. a human editing the same Document in the browser). Add an appendContent RPC that is identical to updateContent but omits the `fragment.delete(0, fragment.length)` step. Applying the incoming update onto the untouched fragment lets the Y.js CRDT merge the new content in, giving append semantics that are race-free against concurrent editors (the mutation runs inside the same hocuspocus direct connection). - server/collaborator: new appendContent method + dispatch registration - collaborator-client: AppendContentRequest/Response types + appendMarkup() - tests: append-to-empty, append-preserves-prior, replace-vs-append, and two-independent-appends-both-land (CRDT merge, no clobber) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Connected to Huly®: UBERF-16634 |
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
The collaborator service currently exposes only full-replace writes (
getContent/createContent/updateContent).updateContentclears the document'sY.XmlFragment(fragment.delete(0, fragment.length)) before applying the incoming update, so a server-side read-modify-write silently clobbers concurrent edits — e.g. an automation appending to a Document body while a user is editing it in the browser.This PR adds an
appendContentRPC that is identical toupdateContentexcept it omits thefragment.delete(...)step. Applying the incoming update onto the untouched fragment lets the Y.js CRDT merge the new content in, giving append semantics. Because the mutation runs inside the same hocuspocus direct connectionupdateContentuses, it is race-free against concurrent editors via the CRDT layer.Use case
Automated agents and human editors collaborating on the same Document body — an automation can append (log lines, generated sections, status updates) without wiping out whatever a person is concurrently typing.
Changes
server/collaborator— newappendContentmethod (a copy ofupdateContentminus the fragment clear) and its registration in the RPC dispatch table.collaborator-client—AppendContentRequest/AppendContentResponsetypes and anappendMarkup(document, markup)client method wrapping the RPC (mirrorsupdateMarkup).appendContentsemantics: append into an empty doc, append preserving prior content, replace-vs-append contrast, and two independent appends both landing (CRDT merge, no clobber).Notes / open questions
server/collaboratorhas no existing RPC/hocuspocus integration harness, so the added tests validate the underlying Y.js merge behaviour the RPC relies on (the single semantic difference fromupdateContent) rather than spinning up a full hocuspocus server. Happy to add an end-to-end integration test against a live websocket session if you have a preferred harness for it.updateContentline-for-line so it tracks any future changes to that path.🤖 Generated with Claude Code