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
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. Additionally, close() without --discard was throwing "unsaved changes" errors in collab-only sessions (no source file). Since collab sessions persist changes to the server, not a local file, the "dirty" flag doesn't apply the same way. Fixes: - waitForFinalFlush() ensures Y.js updates reach the server before disconnect - Allow close() without --discard for collab-only sessions Fixes: SD-3396 Related: IT-1142 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
e15df4b to
c47ab1b
Compare
Summary
Wait for Y.js sync before disconnecting: When closing a collaborative document, the SDK was immediately disconnecting without waiting for pending updates to flush to the server. This caused edits to be lost if
close()was called too quickly after editing. The fix addswaitForFinalFlush()which waits for the websocket buffer to drain before disconnecting.Allow
close()without--discardfor collab-only sessions: Previously,close()on a collab-only session (no source file) threw "unsaved changes" errors, forcing users to useclose({ discard: true }). Since collab sessions persist changes to the server (not a local file), the "dirty" flag doesn't apply. Nowclose()works without--discardfor collab-only sessions.