cryptee / web-client

Cryptee's web client source code for all platforms.
https://crypt.ee
Other
445 stars 22 forks source link

[Change Request] Auto reload current doc when stale #171

Closed michaeldurland closed 7 months ago

michaeldurland commented 1 year ago

Is your feature request related to a problem? Please describe. Problem: I have a doc open on desktop. I make edits to it. It auto-saves (push to server). Now I go to lunch and open the doc on my phone. I make some edits, and it auto-saves (push to server). I get back from lunch and see stale doc open on my desktop browser. That's not good.

Describe the solution you'd like The open desktop browser doc should show the edits I made on my phone. I shouldn't have to force a manual refresh and pull from the server. The doc should automatically reload when it detects the current version in the browser is older than the version on the server.

Just like the auto-save happens after ~5 seconds of keyboard inactivity, maybe the current doc could poll the server to check timestamps every 5 seconds and pull the server version to the client if the client doc timestamp is older than the server doc timestamp.

Thank you for considering.

johnozbay commented 7 months ago

Hi there!

First off — Apologies for getting back to this so late.

Part of the reason why this issue got buried is because we used to have this feature, in fact Cryptee used to be a realtime-updating cross-device editor when we first launched years ago, but we had to remove this feature due to inherent problems with how conflict resolution needs to happen in encrypted environments. (Otherwise as a team who uses cryptee internally daily, we feel your frustration all too well)

In short, with unencrypted services, servers can see your documents' contents, and they can handle all the conflict resolution. (i.e. server notices which lines changed, pushes only the delta to clients)

But with Cryptee, since our servers can't see your documents' contents, all the conflict resolution needs to be handled on your devices. The best way to do this at the moment is by utilizing timestamps. (i.e. most recent save wins)

So for example : @ 11:50 on your desktop you create / save a document (leave your desktop, which is still online) @ 12:20 you walk away for lunch, add a new line while away on your phone & save & upload @ 12:50 you come back to your desktop, and now the document on your screen is outdated, since the last save was at 12:20 from your phone.

= this is the hypothetically easier to fix scenario, and what you'd like to see a fix for. Since the saved version @12:20 should win, and all the devices are online.


But what should happen if you have multiple devices, and one was offline and never got the earlier changes?

Example 2 :

@ 14:50 on your work desktop you create / save a document (leave your desktop, which is still online)

@ 16:50 you leave office, add a new line ( line 1 ) on your phone & save & upload

@ 17:00 you're in the subway, and add another line ( line 2 ) on your phone, which is now offline. it's saved offline, and it can only sync up once you launch Cryptee while your phone's connected again. But you saved the line, and quit the app. Didn't even think about it.

@ 17:30 you arrive home, open your laptop, and you'll only see line 1, perhaps you didn't notice line 2 is missing, since it's a long document, so you keep on typing and adding in more lines, i.e. line 3 and line 4.

@ 9:00 next day — you arrive at work, and find that the line 2 you wrote in the subway while offline is missing, and even if you load the app on your phone now while it's connected, that edit/change now has an outdated timestamp, since you edited the document after you made changes and saved things on your home laptop.


This would be very easy to handle for an unencrypted service, since the server would notice the change deltas, combine the changes and display you the correct document. For an on-device encrypted service like Cryptee, with offline support, where all your data is encrypted/decrypted on your devices however, this is a very difficult problem to solve, since conflict resolution would need to take place on all your devices, and the complexity grows exponentially with the number of devices.

We had okay solutions to these types of issues, and even then users had issues. (i.e. what happens if you delete lines, instead of add lines? what happens if you delete a document on one device, but the device where the document is open on the screen is offline, and you keep typing on that device, and press save once device connects again etc etc)

After considering hundreds of angles, we decided against having a realtime editor, as the risks were outweighing the pros, even though with your example it may seem otherwise.

We're open to thoughtful suggestions, but I'm afraid we won't be working on this due to the level of complexity involved in making this possible in an encrypted environment until there's a better technological solution possible. (i.e. we're investigating conflict resolution algorithms using a combination of timestamps, hashes, XORs and some smart messaging)

Even if we were to show a simple popup that says : "this document is now outdated, because you saved it elsewhere, click here to reload for the new version" ... what if you had a change on that outdated document? this leaves no way to rescue that change either. Either way it's a frustrating situation.

So at the moment, we're intentionally not handling any of these edge cases until we have a better solution.

Hoping these make sense and help!

I'll close this issue for now, but we're open to feedback and thoughtful ideas and solutions that cover all edge cases, and would love to implement these! So if you're reading this, please feel free to chime in ✌🏻

Many thanks for your patience and understanding!

Best,

J ✌🏻