jupyterlab / jupyterlab

JupyterLab computational environment.
https://jupyterlab.readthedocs.io/
Other
14.12k stars 3.35k forks source link

Autosave does not checkpoint notebook #16750

Open williambrandler opened 1 month ago

williambrandler commented 1 month ago

Description

We have a cloud environment where users can access a jupyterlab machine and write code in notebooks. Occasionally users get connection errors and are then told their File Changed and they are asked to Cancel / Revert / Overwrite (see screenshot)

image

A user clicked 'revert' and their notebook reverted back a few days. However, during this time their notebook had been saved many times using the autosave feature. It appears that the autosave is not also checkpointing the notebook, which is why the reversion went back many days to the last time the user explicitly saved the notebook. This means the user lost days of work

In summary:

I replicated the autosave checkpoint issue on a new machine in our cloud environment (no packages installed) and in classic Jupyter Notebook on my local machine (MacBook)

Is this expected behavior?

Reproduce

  1. Create notebook "hello_world.ipynb"
  2. Edit it and wait for autosave
  3. go to terminal and check the time stamp for the checkpoint and for the notebook
    • ls -l .ipynb_checkpoints
    • ls -l hello_world.ipynb
  4. Wait one minute and repeat steps 2 + 3
  5. Now edit notebook again and click File -> Save Notebook
  6. Repeat step 3

I diagnosed this in the original jupyterlab environment (docker container on a cloud virtual machine) and in Classic Jupyter Notebook on my local machine

Expected behavior

File checkpoints on autosave

Context

Selected Jupyter core packages... IPython : 8.25.0 ipykernel : 6.29.4 ipywidgets : 8.1.3 jupyter_client : 8.6.2 jupyter_core : 5.7.2 jupyter_server : 2.14.1 jupyterlab : 4.2.2 nbclient : 0.10.0 nbconvert : 7.16.4 nbformat : 5.10.4 notebook : 7.2.1 qtconsole : not installed traitlets : 5.14.3

Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.

JasonWeill commented 4 weeks ago

@williambrandler Thank you for opening this issue! It seems like a reasonable expectation that auto-save would also automatically create checkpoints. We might need to investigate where the autosave logic lives (in JupyterLab, Jupyter Server, or elsewhere).

williambrandler commented 4 weeks ago

ok great, yeah having autosave also checkpoint would be great to match the behavior of using File -> Save Notebook

in the end we were able to recover the user's work via the ipython history, although it does take a bit longer to reconstruct the lost code via the command history as opposed to using a much more recent checkpoint

ipython
IN [1]: %hist -o -g -f ipython_history.md