nextcloud / nextcloud/text

Detect inconsistent initial steps in yjs and require page reload

Open
#5,724 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement feature: sync
Dominant language
JavaScript
Stars
659
Forks
133
Avg merge
1d 20h
Merged PRs (30d)
110

Description

Is your feature request related to a problem? Please describe.
In case two users start a new yjs session at the same time they need to initialize it with the initial ydoc content to create a consistent world view. https://github.com/nextcloud/text/pull/5589 tackles this. If for some reason the two clients come up with a different initial doc state we end up with a "split brain" situation - where both work on a similar yet different document and fail to sync fully.

Planned solution

  • Push the doc state as soon as we have it to reduce the timespan in which conflicts may occure.
    • Use a new endpoint to save the document state only without the autosave content.
    • Use a separate wrapper in the SessionApi on the client side.
    • Store documentState but no autosaveContent to avoid writing unchanged documents.
  • In case a conflicting documentState already exist:
    • Log the information this happened.
    • On the client handle the error response with an appropriate message and ask the user to reload the page.
  • backport to stable28 - as that's how far #5589 was backported.

Tasks

  • New API endpoint that only stores the initial document state.
  • Wrapper in SessionApi for that endpoint.
  • Test the API endpoint from cypress api tests.
  • Send the initial document state to the server as soon as we have it.
  • Handle errors on the client side.

Acceptance Criteria

  • If one client connects a following client will receive an initial yjs document state shortly after (< 5sec.)
  • If two clients connect within the same timeframe and the initial yjs document state matches they continue without interruption.
  • If two clients connect within the same timeframe and the initial yjs document state differs one gets to continue - the other one displays an error message that instructs the user to reload the page.

Open questions

  • Does this interfere in somehow with
    • read only sessions
    • reconnecting
    • reconnecting after a session cleanup

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SessionApi wrapper and the Cypress API tests mentioned in the issue, then trace where the initial documentState is produced and sent. The work is done when matching concurrent states continue normally, conflicting states produce a logged error and a reload message, and the stated read-only and reconnecting cases are understood.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend-api-design, frontend, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.