Skip to content

Initial Workflow Shared-editing Implementation - #1392

Merged
Xiao-zhen-Liu merged 34 commits into
masterfrom
xiaozhen-workflow-collab
Jan 17, 2022
Merged

Xiao-zhen-Liu merged 34 commits into
masterfrom
xiaozhen-workflow-collab

Conversation

@Xiao-zhen-Liu

@Xiao-zhen-Liu Xiao-zhen-Liu commented Jan 10, 2022 •

Copy link
Copy Markdown
Contributor

This PR updates #758 to the latest codebase. Some descriptions are copied here.

Introduction

This pull request includes an initial shared-editing implementation for being able to send commands between multiple clients. The gif above gives a brief demonstration behind how it looks, with each individual command being sent as soon as it's performed. Sending commands ensures that the workflows get synced between different clients after each action performed by different clients. This is still a naive implementation and leaves some concerns that need to be addressed.

Below is a demo:
Screen Recording 2022-01-12 at 19 28 20-2

Main file changes and implementation overview

CollaborationResource.java

Located at web/src/main/java/edu/uci/ics/texera/web/resource/CollaborationResource.java. This is the websocket used to communicate between the different clients, with a command being sent to all other clients currently connected to the websocket.

workflow-action.service.ts

Earlier, we had added the Command interface for undo/redo. Unfortunately, that interface kept track of each action as a set of functions, which we can't send between clients. We instead implemented the new CommandMessage interface which keeps track of an action's name, the parameters for that action, and the type for that action(e.g. normal action, undo, or redo). All of these things are able to be communicated between clients. Now, in addition to just performing the action on that client, we'll construct a command message after performing each action that we can send. An example looks like the following(this refers to WorkflowActionService):

const commandMessage1: CommandMessage = {'action': 'deleteOperator', 'parameters': ['123'], 'type': 'execute'};
// Message gets received on different client
this[commandMessage1.action].apply(this, commandMessage1.parameters);

workflow-collab.service.ts

This service is where the websocket connection gets established with the resource described above. It'll listen to the websocket and push new messages into a stream, notifying other services to perform the actions.

Minor changes were made in a handful of other files to make sure they interacted properly with the new features. Additionally, A parameter to currently disable the feature is added since it is still a work in progress, and is disabled by default so that its issues will not affect current system.

Changes from the old PR

  • Added some actions that also need to be propagated: resetAsNewWorkflow and autoLayoutWorkflow.
  • Frontend tests from that PR are deleted, might need to be reimplemented later.

Issues and next steps

  1. When a new client joins or when an existing client refreshes the page, the syncing process is supposed to be a read operation (the new client reads the current workflow). Instead, the joining client reads from the local storage and overwrites the existing client's workflow. This needs to be addressed.
  2. This implementation conflicts with the user system, and the next version should distinguish between different users and workflows.
  3. Undo-redo stacks are not synced and might lead to chaos. Need to be addressed or disable undo-redo.
  4. Currently there is no lock. Here is a potential design:
  • To simplify matters, the lock will be a global lock, i.e., on the whole workflow.
  • To minimize the impact on existing user experience, only enable locking when there are more than two clients.
  • When there is only one client, there will not be any button indicating a lock.
  • When a new client is connected, both the existing client and the new client will have a new lock button on their GUI.
  • The old client will automatically acquire the lock, and the lock will only be released when it explicitly clicks on this button.
  • Whenever a client is closed but the lock is unreleased, after a timeout the server will release this lock to prevent deadlock.

@Xiao-zhen-Liu
Xiao-zhen-Liu requested a review from zuozhiw January 10, 2022 05:12
@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor Author

Group discussion 1/11: We'll create a github project to keep track of all PRs related to workflow collaboration changes

@zuozhiw zuozhiw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left a few comments, please address them and I'll have another round of review.

@Yicong-Huang

Copy link
Copy Markdown
Contributor

@Xiao-zhen-Liu can you please modify the PR title and description? since the old PR you are referring to was never merged. we should still treat this PR as a new feature. it's better to describe its functionality, logic, and limitations. and you can give credit to the old PR by referring to it.

@Xiao-zhen-Liu Xiao-zhen-Liu changed the title Update Workflow Collaboration PR to the latest codebase Workflow Shared-editing Without Locking Mechanism Jan 13, 2022
@Xiao-zhen-Liu Xiao-zhen-Liu changed the title Workflow Shared-editing Without Locking Mechanism Initial Workflow Shared-editing Implementation Jan 13, 2022
@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor Author

@zuozhiw All the requested changes are addressed, some are to be made in the next PR.

# Conflicts:
#	core/new-gui/src/app/workspace/service/undo-redo/undo-redo.service.ts

@zuozhiw zuozhiw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left some comments

@Xiao-zhen-Liu

Xiao-zhen-Liu commented Jan 16, 2022 •

Copy link
Copy Markdown
Contributor Author

@Yicong-Huang I made all the changes per your requests, but I left few refactoring out because they involve other files not related to this PR which can be done later. Please check these changes.

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes looks good to me. Please change the print to logger. After that we can merge this PR.

@Xiao-zhen-Liu
Xiao-zhen-Liu merged commit 0758c8a into master Jan 17, 2022
@Xiao-zhen-Liu
Xiao-zhen-Liu deleted the xiaozhen-workflow-collab branch January 17, 2022 20:13
Xiao-zhen-Liu added a commit that referenced this pull request Feb 15, 2022
## Introduction
This PR does several things, among which the key is introducing workflow-level locking and integration with user system to shared editing. 

#1392 only migrates #758 to our current codebase, but did not consider user system so any change from any client will be propagated to all other clients. This PR fixes this and ensures only workflows of the same id can propagate changes to each other. 

On top of that, this PR introduces a locking mechanism on the workflow graph so that at the same time only one client can "write" the frontend workflow graph and propagate changes to others.

Other changes include redesigning the collab websocket messages to support more operations, and some refactoring work requested in #1392.

## Demos

All the changes require `workflowCollabEnabled` in the environment to be true, otherwise the frontend behavior will not be affected. (Except one place - when `workflowModificationEnabled` is set to false, operator dragging will also be disabled, previously we allow it to be enabled. I'm not introducing another level of "disableModification" here for simplicity, but this is doable.)

- Depending on `wId`, only sessions on the same workflow will have "collaboration" and "lock", so this images shows two different workflows will both have write access (indicated by a newly added button).

<img width="1392" alt="image" src="https://user-images.githubusercontent.com/36582710/152084809-b9f15e67-cdd2-47c5-80b8-44018cce78bb.png">

- When more than two sessions are both on the same workflow, only one will have write privilege, all other session will see the button as "Readonly mode - click to request write access".

- For now, to simplify matters and prevent deadlock, whichever session that clicks the button will get the lock, shown in the below gif:

![Screen Recording 2022-02-01 at 18 44 22](https://user-images.githubusercontent.com/36582710/152085577-52ccd6a9-9caa-4061-af9f-d82864cc5926.gif)

- When a lock-holding session closes, the server will give the lock to other sessions still open, in particular, the first session in server's list.

- I also implemented a simple function to allow a session to notify other sessions to reload the workflow,  and in particular this is what will happen when a particular workflow version is loaded, so reverting version will be propagated.

## Limitations
1. For now only changes on the workflow graph will be propagated (and locked). Other elements, like workflow name, PythonUDF's "edit code" button, "Run" button, etc., cannot be **locked** or changed with `CommandMessages` (but PythonUDF's code changes can indeed be propagated), so will not be affected.
2. Enabling/Disabling operators will not be locked/propagated because somehow this is not included in `WorkflowActionService`, but directly in `WorkflowGraph`.
3. Since undo/redo stacks are local to each session, potential issues might arise.

## Code Explanation

### Collab WebSocket requests/events

The "lock" is really a value in the server (see `wIdLockHolderIdMap`). I redesigned WebSocket messages to incorporate functionalities needed in this PR. In particular, I mostly followed `WorkflowWebSocket`, and below are the Request/Events added here:

- `CommandRequest`: sent by lock-holding session to notify the server and propagate commands (changes) to other target sessions.
- `CommandEvent`: Server sends commands to target sessions.

- `WIdRequest`: similar to `WorkflowWebSocket`'s `RegisterWIdRequest`, but instead of registering, this just tells the server a sessions `wId`.

- `TryLockRequest`: When a session first opens it sends this request to see if the lock is already held by this session, or if there are no other sessions of the same `wId`, and can be subsequently granted lock.
- `AcquireLockRequest`: When the new button is clicked this request will be sent.
- `LockGrantedEvent`: Server grants the lock.
- `ReleaseLockEvent`: Server asks lock holder to give up the lock.
- `LockRejectedEvent`: Response to `TryLockRequest` when the sender session is not the lock holder.

- `RestoreVersionRequest` and `RestoreVersionEvent`: similar to `CommandRequest` and `CommandEvent`, but instead this pair simply propagates workflow reloading.
- `WorkflowAccessEvent`: Server tells client whether the workflow is readonly (shared by others with read access).

### Refactoring

For `WorkflowActionService`,
1. Types related to `command` and  `commandMessage` are extracted.
2. Sending `commandMessage` is merged into `executeAndStoreCommand`.

Other potentially confusing codes, especially those related in `WorkflowCollabService`, are documented.

Co-authored-by: kerryqliu <[email protected]>
Co-authored-by: zuozhiw <[email protected]>
@Yicong-Huang Yicong-Huang added frontend Changes related to the frontend GUI and removed gui labels Jul 6, 2025
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
* Added workflow collab service

* Update other services and package.json

* Additional changes

* Added websocket to texera backend, and other changes to collab service

* More changes to workflow collab

* Clean up comments

* More bug fixes and changed tests for initial attempt

* Bug fix for save workflow service

* Typo fix

* Added missing command messages

* Communicate link add between clients

* Add commandMessage to more actions

* Deleted frontend test

* ESLint

* Fix ESLint

* Code cleanup

* Code cleanup

* Add changes to undo-redo

* Taken care of minor issues.

* Disable collab by default for now.

* Disable collab by default for now.

* Revert usersystem default

* Minor changes per requests.

* Add TODO and logging, change code to scala.

* Revert change to proxy.config.json

* Create URL util

Co-authored-by: kerryqliu <[email protected]>
Co-authored-by: zuozhiw <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
)

## Introduction
This PR does several things, among which the key is introducing workflow-level locking and integration with user system to shared editing. 

apache#1392 only migrates apache#758 to our current codebase, but did not consider user system so any change from any client will be propagated to all other clients. This PR fixes this and ensures only workflows of the same id can propagate changes to each other. 

On top of that, this PR introduces a locking mechanism on the workflow graph so that at the same time only one client can "write" the frontend workflow graph and propagate changes to others.

Other changes include redesigning the collab websocket messages to support more operations, and some refactoring work requested in apache#1392.

## Demos

All the changes require `workflowCollabEnabled` in the environment to be true, otherwise the frontend behavior will not be affected. (Except one place - when `workflowModificationEnabled` is set to false, operator dragging will also be disabled, previously we allow it to be enabled. I'm not introducing another level of "disableModification" here for simplicity, but this is doable.)

- Depending on `wId`, only sessions on the same workflow will have "collaboration" and "lock", so this images shows two different workflows will both have write access (indicated by a newly added button).

<img width="1392" alt="image" src="https://user-images.githubusercontent.com/36582710/152084809-b9f15e67-cdd2-47c5-80b8-44018cce78bb.png">

- When more than two sessions are both on the same workflow, only one will have write privilege, all other session will see the button as "Readonly mode - click to request write access".

- For now, to simplify matters and prevent deadlock, whichever session that clicks the button will get the lock, shown in the below gif:

![Screen Recording 2022-02-01 at 18 44 22](https://user-images.githubusercontent.com/36582710/152085577-52ccd6a9-9caa-4061-af9f-d82864cc5926.gif)

- When a lock-holding session closes, the server will give the lock to other sessions still open, in particular, the first session in server's list.

- I also implemented a simple function to allow a session to notify other sessions to reload the workflow,  and in particular this is what will happen when a particular workflow version is loaded, so reverting version will be propagated.

## Limitations
1. For now only changes on the workflow graph will be propagated (and locked). Other elements, like workflow name, PythonUDF's "edit code" button, "Run" button, etc., cannot be **locked** or changed with `CommandMessages` (but PythonUDF's code changes can indeed be propagated), so will not be affected.
2. Enabling/Disabling operators will not be locked/propagated because somehow this is not included in `WorkflowActionService`, but directly in `WorkflowGraph`.
3. Since undo/redo stacks are local to each session, potential issues might arise.

## Code Explanation

### Collab WebSocket requests/events

The "lock" is really a value in the server (see `wIdLockHolderIdMap`). I redesigned WebSocket messages to incorporate functionalities needed in this PR. In particular, I mostly followed `WorkflowWebSocket`, and below are the Request/Events added here:

- `CommandRequest`: sent by lock-holding session to notify the server and propagate commands (changes) to other target sessions.
- `CommandEvent`: Server sends commands to target sessions.

- `WIdRequest`: similar to `WorkflowWebSocket`'s `RegisterWIdRequest`, but instead of registering, this just tells the server a sessions `wId`.

- `TryLockRequest`: When a session first opens it sends this request to see if the lock is already held by this session, or if there are no other sessions of the same `wId`, and can be subsequently granted lock.
- `AcquireLockRequest`: When the new button is clicked this request will be sent.
- `LockGrantedEvent`: Server grants the lock.
- `ReleaseLockEvent`: Server asks lock holder to give up the lock.
- `LockRejectedEvent`: Response to `TryLockRequest` when the sender session is not the lock holder.

- `RestoreVersionRequest` and `RestoreVersionEvent`: similar to `CommandRequest` and `CommandEvent`, but instead this pair simply propagates workflow reloading.
- `WorkflowAccessEvent`: Server tells client whether the workflow is readonly (shared by others with read access).

### Refactoring

For `WorkflowActionService`,
1. Types related to `command` and  `commandMessage` are extracted.
2. Sending `commandMessage` is merged into `executeAndStoreCommand`.

Other potentially confusing codes, especially those related in `WorkflowCollabService`, are documented.

Co-authored-by: kerryqliu <[email protected]>
Co-authored-by: zuozhiw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants