Overview

As a first small step towards #3587587 we should start detecting conflicts during the polling of auto-save endpoint.
More specifically, conflicts that are caused by updating entity for which there is already an auto-save entry in Canvas.

Current openapi definition of the auto-saves/pending endpoint only describes a HTTP 200 response.
That is correct, as ApiAutoSaveController::get() does not perform validation or conflict detection and currently only returns HTTP 200 responses.
This issue aims to change that by adding ability to detect certain types of conflicts and respond with HTTP 409.
This will allow Canvas UI to be notified about a conflict, even if the user is not performing any actions that would previously trigger a conflict detection.

Proposed resolution

  1. Add openapi definition for HTTP 409 response from the auto-saves/pending endpoint.
  2. Start storing "original hash" during auto-save entry save, as this allows us to detect if the underlying entry has been updated since and there is a conflict between what auto-save assumes about the entity and the actual entity state.
  3. Make AutoSaveManager to check for conflicts during fetching of the auto-save entry list, add relevant conflict metadata (conflictId and timestamp) to the entries.
  4. Make ApiAutoSaveController::get() check entries for Page entities in the list and respond with HTTP 409 if at least one such entry has a conflict
  5. As we will be making it possible to recover from some of detected conflicts, on conflicts caused by the change of the underlying auto-save entry entity we will return HTTP 409 and the response body will contain both:
  6. Add tests for all of this as well as update any existing tests that might start break due to unexpected HTTP 409

User interface changes

For brief period of time until #3585970: UI changes for detection of conflicts caused by external updates to underlying entity of auto-save entry is merged there will be a possibility to encounter a situation where Canvas UI forces to refresh the page based on the conflict detection during auto-save endpoint polling.
No other UI changes are introduced in this issue.

Issue fork canvas-3589076

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

f.mazeikis created an issue. See original summary.

wim leers’s picture

Component: Internal HTTP API » Auto-save
Issue tags: +openapi

Lovely precise issue, thanks! 🤩

This could live either under the Auto-save component or the Internal HTTP API component. But based on the plan, the key changes are Start storing "original hash" during auto-save entry save, as this allows us to detect if the underlying entry has been updated since and there is a conflict between what auto-save assumes about the entity and the actual entity state..

So changing to the other issue queue component to ensure @tedbow reviews this.