Skip to content

wait for Y.js sync before disconnecting collaborative sessions#3675

Open
mattConnHarbour wants to merge 1 commit into
mainfrom
matthew/sd-3396-fix-wait-for-yjs-sync-before-disconnecting-collaborative
Open

wait for Y.js sync before disconnecting collaborative sessions#3675
mattConnHarbour wants to merge 1 commit into
mainfrom
matthew/sd-3396-fix-wait-for-yjs-sync-before-disconnecting-collaborative

Conversation

@mattConnHarbour
Copy link
Copy Markdown
Contributor

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

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
@mattConnHarbour mattConnHarbour requested a review from a team as a code owner June 7, 2026 20:36
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 7, 2026

SD-3396

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants