wait for Y.js sync before disconnecting collaborative sessions#3675
wait for Y.js sync before disconnecting collaborative sessions#3675mattConnHarbour wants to merge 1 commit into
Conversation
When closing a collaborative document, the SDK was immediately disconnecting the Y.js provider without waiting for pending updates to be flushed to the server. This caused a race condition where the last edits could be lost if close() was called too quickly after editing. The fix awaits runtime.waitForSync() before disposing the editor and runtime, ensuring all Y.js updates reach the server before disconnecting. Fixes: SD-3396 Related: IT-1142
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e15df4b379
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -40,7 +40,7 @@ export type EditorWithDoc = Editor & { | |||
| export interface OpenedDocument { | |||
| editor: EditorWithDoc; | |||
| meta: DocumentSourceMeta; | |||
There was a problem hiding this comment.
Await async document disposal at call sites
Changing OpenedDocument.dispose() to optionally return a promise makes collaborative one-shot/session cleanup asynchronous, but most callers still invoke it without await (for example mutation-orchestrator.ts and save.ts finally blocks). In those non-host collaborative commands, openCollaborativeDocument.dispose() now starts runtime.waitForSync() and returns immediately to the CLI, so the process can finish before the Y.js sync completes and before the provider is disconnected; the intended “wait before disconnecting” behavior only works in the session-pool path that was updated.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
When closing a collaborative document, the SDK was immediately disconnecting the Y.js provider without waiting for pending updates to be flushed to the server. This caused a race condition where the last edits could be lost if close() was called too quickly after editing.
The fix awaits runtime.waitForSync() before disposing the editor and runtime, ensuring all Y.js updates reach the server before disconnecting.
Fixes: SD-3396
Related: IT-1142