8000 Implement the Danger zone section on the Control page by yakutovicha · Pull Request #262 · aiidalab/aiidalab-home · GitHub
[go: up one dir, main page]

Skip to content

Implement the Danger zone section on the Control page - #262

Merged
yakutovicha merged 29 commits into
mainfrom
feature/danger-zone-tab
Oct 27, 2026
Merged

yakutovicha merged 29 commits into
mainfrom
feature/danger-zone-tab

Conversation

@yakutovicha
@yakutovicha yakutovicha commented Sep 28, 2026 •
Copy link
Copy Markdown
Member

Fixes #257. Related: #53 (not closed: the container no longer supports a full home reset).

Depends on aiidalab/aiidalab-docker-stack#605, which reduces the container's reset to a single local mode; the image pins the home app, so both ship together.

Replaces the DangerZoneWidget placeholder with scheduling a package reset: on its next start, the container moves ~/.local (packages installed by apps and pip install --user) aside to ~/.local~<date>. Apps, AiiDA data, and profiles are kept. The app only writes or removes ~/AIIDALAB_FACTORY_RESET; the container performs the reset.

Behaviour

  • Danger zone: "Schedule package reset" is enabled once reset-packages is typed. The section refreshes synchronously (checking the flag is instant), so it always shows what is on disk; Refresh picks up a flag created or removed by hand.
  • While scheduled: the home page shows only a notice with a cancel button; cancelling brings the apps back. The same notice replaces the Danger zone form and explains how to restart: the JupyterHub Control Panel, aiidalab-launch start --restart -p <profile>, or docker restart <container>. If cancelling fails, it links to a terminal with the rm command.
  • Bad flag files: the UI applies the container's own rule (a regular, non-symlink file whose first 64 bytes, without whitespace, are local). Anything else counts as no reset, so it never locks the home page; the container ignores it too.
  • Shared logic lives in a new home/package_reset.py, without AiiDA imports, to keep the home page's check cheap.

Notes for review

  • The UI says "package reset", not "factory reset", since apps and data are kept; the flag file keeps its name for the container.
  • No mode choice, unlike Control page: implement the Danger zone section #257: after #605 only local exists.
  • Only the home page is gated; other pages stay reachable by URL.

Tests

With the flag file redirected to a temporary path: package_reset (scheduling, also over a symlink; cancelling; which files count as scheduled; the notice's cancel paths), the Danger zone (initial view and synchronous refresh, confirmation, schedule → cancel, schedule failures), and the home page gate. A session fixture fails the run if the real flag file is created.

🤖 Generated with the help of Claude Code

Steps and screenshots

[1] Initial look

image

[2] Schedule package reset button is pressed
image

[3] The start page is also now requesting a restart
image

[4] Relaunch using aiidalab-launch:

image

[5] After the restart, the home page's .local is moved (you have to trust me on this one), and the start page is restored:
image

@yakutovicha
yakutovicha added this pull request to stack #263 September 29, 2026 07:24
@yakutovicha
yakutovicha marked this pull request as ready for review September 29, 2026 07:29
@edan-bainglass
Copy link
Copy Markdown
Member

I have various nitpicky comments, but let's not hang on those. I defer to @danielhollas for review here 🙂

Comment thread home/control.py Resolved
@edan-bainglass
edan-bainglass commented Oct 12, 2026 •
Copy link
Copy Markdown
Member

@yakutovicha I think we need one more option in the danger zone, which is to reset only the .local directory. This will allow the apps to remain but to be incompatible, requiring the user to reinstall each from their manage app page. Without this, scheduling a reset and restarting the container will cause the home to be empty, making it more difficult to reinstall former apps.

I'm realizing now that this would require a coordinated change in the docker stack script that executes the resets, which currently only knows of the two options you implemented.

@danielhollas
Copy link
Copy Markdown
Contributor

I would like us to step back here and consider only what is really needed (in an MVP sense) for the python 3.12 migration. As Edan pointed out, we just need the users to clean their .local directory, and for that I don't see a reason why we need to go through a container restart; let's just have a button that actually runs the rmdir ~/.local command.

We can consider this specific PR later after 3.12 is released, but I don't want it to be a blocker.
Just some UX-design question from the top of my head.

  1. Once we have ~/.local removal, I don't really see the point of Mode 1. It's easy enough to uninstall all the apps manually (most users will not have many). Also I don't even see the reason a user would want to remove all the apps at once? Supposedly they'd like to keep and least some of them, and we now have the Reinstall button.

  2. Regarding Mode 2, I am not sure if cleaning up the whole home from within the running container is the best workflow here? Seems better to remove the home volume and attach a new one before the container starts. (also I strongly suspect should be a lot faster). aiidalab-launch already implements this workflow via the reset command. Not sure what would be best for the JypyterLab deployments here...

@edan-bainglass
Copy link
Copy Markdown
Member

I would like us to step back here and consider only what is really needed (in an MVP sense) for the python 3.12 migration. As Edan pointed out, we just need the users to clean their .local directory, and for that I don't see a reason why we need to go through a container restart; let's just have a button that actually runs the rmdir ~/.local command.

Indeed, that would do. I updated the migration banner PR recently with details in the banner regarding a .local reset, pointing to the danger zone section of the control page. But in principle, I agree that this can just be a button to trigger rmdir ~/.local, still in the danger zone. However... I did notice that when testing my migration banner PR, removing .local and restarting the container does create a new .local with only the share folder. So the two paths are not exactly equivalent.

@edan-bainglass
Copy link
Copy Markdown
Member

@yakutovicha a suggestion from @giovannipizzi is to mv the .local folder to some backup space, allowing the user to decide if they are ready to part ways with it entirely. This is to guard against forcing deletion of important things placed by users in .local that we cannot foresee. Pinging @danielhollas for feedback.

@danielhollas
Copy link
Copy Markdown
Contributor

@edan-bainglass that sounds very reasonable, let's go with that, thanks!

@yakutovicha in terms of priority, it would be great if you could focus on the danger zone first, because that's what is blocking the python 3.12 migration. The other sections are more nice-to-haves and we can ship the new image without them if needed.

@yakutovicha
yakutovicha commented Oct 21, 2026 •
Copy link
Copy Markdown
Member Author

I tested renaming the .local folder. After that, the home app (and the whole Jupyter) no longer works.

image

@danielhollas
Copy link
Copy Markdown
Contributor

I tested renaming the .local folder. After that, the home app (and the whole Jupyter) no longer works.

Is this from a fresh container? Or from your development container?

@yakutovicha
yakutovicha commented Oct 21, 2026 •
Copy link
Copy Markdown
Member Author

I tested renaming the .local folder. After that, the home app (and the whole Jupyter) no longer works.

Is this from a fresh container? Or from your development container?

I tried several options:

  • existing 3.9 container
  • existing 3.12 container
  • fresh 3.12 container

All results are the same. The only existing folder for a fresh container is ~/.local/share/jupyter:

tree
.
└── share
    └── jupyter
        ├── nbsignatures.db
        ├── notebook_secret
        └── runtime
            ├── jpserver-7-open.html
            ├── jpserver-7.json
            ├── jupyter_cookie_secret
            ├── kernel-210f562a-f0aa-4871-9c5f-020767d2f573.json
            └── kernel-93183206-e64a-4af5-a0d7-bd9b4d5b2d79.json

Curiously, doing this won't fix the problem:

image

So something in jupyter is really looking into that exact folder.

@danielhollas
Copy link
Copy Markdown
Contributor

Curiously, doing this won't fix the problem:

Oh, interesting, I would have suggested this exact solution, of moving it and then copy back the needed folder.

What we can do instead is to hardlink the whole folder into .local_backup and then remove all folders within .local except those needed by jupyter. (also write this in the email)

@edan-bainglass
edan-bainglass commented Oct 23, 2026 •
Copy link
Copy Markdown
Member

See comments here 🙏

@danielhollas
Copy link
Copy Markdown
Contributor

btw: I would still advocate for a minimal implementation here, only what we need for the migration --- less code to review and test. See also my earlier comment #262 (comment)

@yakutovicha
yakutovicha removed this pull request from stack #263 October 23, 2026 10:30
Replace the DangerZoneWidget placeholder with scheduling of a factory
reset that the AiiDAlab container performs on its next restart, via a
mode flag written to ~/AIIDALAB_FACTORY_RESET (mode 1: remove ~/apps
and ~/.local; mode 2: erase the whole home directory).

- The schedule button is enabled only by typing the literal phrase
  "factory-reset". The written flag is read back to verify it, and
  the view always reflects what is on disk, so a flag that failed
  verification shows up with a cancel button.
- A scheduled reset replaces the form with an explanatory alert and a
  cancel button that removes the flag file.
- A non-empty AIIDALAB_FACTORY_RESET environment variable overrides
  the flag file (even "0", which cancels it), so the section warns
  about it; an empty one is ignored, as by the container script.

Tested with the flag file redirected to a temporary path: confirmation
gating, the schedule and cancel flows, a failed verification, unknown
modes and the environment-variable warning. A final test checks that
the real flag file was never created.
The scheduled-reset alert told users to run `aiidalab-launch restart`,
a command that does not exist (restarting is `start --restart`). Naming
a host-side tool is also wrong on JupyterHub deployments, where the
server is stopped and started from the hub. Describe the trigger in
deployment-neutral terms instead: the reset happens the next time the
AiiDAlab container starts.

No test change: no test asserts on this sentence.
Cover the two error branches that had no test: a flag file that exists
but cannot be read (the alert says so instead of naming a mode) and a
cancel that fails (the error is shown and the scheduled view stays). A
directory in place of the flag file triggers both without mocking.
Also check that the details line follows the selected reset mode.
The phrase to type was only in the text box's placeholder, which
disappears as soon as the user starts typing, so after a typo nothing
on the page said what to type. State it in a visible label above the
box instead, and drop the placeholder so it is stated in one place.

No test change: the existing gating test covers the behaviour, and the
label is static text.
@yakutovicha
yakutovicha force-pushed the feature/danger-zone-tab branch from e135fe2 to 0efc3ef Compare October 23, 2026 10:41
@yakutovicha
yakutovicha changed the base branch from feature/profiles-tab to main October 23, 2026 10:42
@danielhollas
Copy link
Copy Markdown
Contributor

Please also see my review on aiidalab/aiidalab-docker-stack#605

@yakutovicha
yakutovicha commented Oct 23, 2026 •
Copy link
Copy Markdown
Member Author

btw: I would still advocate for a minimal implementation here, only what we need for the migration --- less code to review and test. See also my earlier comment #262 (comment)

The implementation here is rather minimal, just asking user what kind of reset they want and creating the file. Once the reset is on, I would probably disable the home app telling user "Hey, you need to restart the container to launch the reset, click on this ⏹️ to cancel it"

Please also see my review on aiidalab/aiidalab-docker-stack#605

yes, let's finalise the reset cases and add them to the docker stack.

yakutovicha and others added 2 commits October 23, 2026 12:19
aiidalab-docker-stack#605 rewrites the factory-reset script: its only
mode is now `local`, which moves ~/.local aside to ~/.local~<date>, and
the AIIDALAB_FACTORY_RESET environment variable is gone. Drop the mode
choice and the environment-variable warning, schedule `local`, and
report any other flag-file content (e.g. the old numeric modes) as an
unknown mode that the container ignores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default button width cut off "Schedule factory reset" and "Cancel
scheduled reset".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread home/package_reset.py Resolved
Co-authored-by: Edan Bainglass <45081142+edan-bainglass@users.noreply.github.com>
Comment thread home/package_reset.py Resolved
@danielhollas
Copy link
Copy Markdown
Contributor

@yakutovicha can you please update the PR description with the up-to-date design, and include relevant screenshots? I'll have a closer look at the code later today (but will not have time to test things)

@yakutovicha
Copy link
Copy Markdown
Member Author

@yakutovicha can you please update the PR description with the up-to-date design, and include relevant screenshots? I'll have a closer look at the code later today (but will not have time to test things)

done ✅

@danielhollas danielhollas 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.

Thanks, this looks great! Some minor comments inline. I've also ran xhigh Claude review, I am posting only points that I think should be fixed ideally. Feel free to merge afterwards, I will not have time for this tomorrow. I'll test things manually once this is part of the image. Some of the fixes are due to the last updates on the aiidalab-docker-stack PR. Thanks for your work on this! 🙏

Probably should be fixed

  1. While a reset is scheduled, the home page also hides the Terminal, File Manager and Control links and the admin warning in home_app_warning.md (start_page.py:78). If Cancel fails, the user has no way to reach a terminal to fix it.

  2. A garbled flag file crashes the home page (home/package_reset.py:46). scheduled_message() only catches OSError. If ~/AIIDALAB_FACTORY_RESET holds bytes that aren't valid text (e.g. \xff\xfe), it raises UnicodeDecodeError. Rendering the home page then fails and shows a traceback with no apps and no cancel button.

  3. The UI's "is a reset scheduled?" check is looser than the container's (package_reset.py:26). is_scheduled() uses Path.exists(), but 05_factory-reset.sh only acts on a regular file that isn't a symlink. With a symlink or a directory there, the page stays locked and the container never clears it, so restarting doesn't help. With a directory, Cancel also always fails. With a FIFO (a named pipe), the kernel hangs when it tries to read it. Separately, schedule() follows a broken symlink and writes to wherever it points.

Maybe worth fixing, but haven't verified

  1. The Danger zone has a threading race (control.py:582). _do_refresh creates and edits widgets on the background refresh thread, which breaks the base-class rule. It also runs from button callbacks with no lock. If the user clicks Schedule while a refresh is running, the schedule form can come back even though a reset is scheduled.

  2. An empty file or an unknown mode still blocks all apps and says "please restart", even though nothing will be reset (package_reset.py:52).

  3. If the _on_cancelled callback raises, the error is never shown. The reset is already cancelled, but the old notice stays on screen (package_reset.py:126).

  4. The Danger zone first shows the schedule form no matter what is on disk, and corrects itself only after the async refresh (control.py:558).

  5. Each refresh while a reset is scheduled builds a new notice without closing the old one, so widgets leak (control.py:586).

Comment thread home/package_reset.py Resolved
Comment thread home/package_reset.py Resolved
Comment thread home/package_reset.py Resolved
Comment thread tests/test_control.py Resolved
@edan-bainglass
edan-bainglass commented Oct 27, 2026 •
Copy link
Copy Markdown
Member

2. A garbled flag file crashes the home page (home/package_reset.py:46). scheduled_message() only catches OSError. If ~/AIIDALAB_FACTORY_RESET holds bytes that aren't valid text (e.g. \xff\xfe), it raises UnicodeDecodeError. Rendering the home page then fails and shows a traceback with no apps and no cancel button.

How does one arrive at such a situation? If this requires a user to manipulate the file directly, I don't think that is something for us to guard against.

3. The UI's "is a reset scheduled?" check is looser than the container's (package_reset.py:26). is_scheduled() uses Path.exists(), but 05_factory-reset.sh only acts on a regular file that isn't a symlink. With a symlink or a directory there, the page stays locked and the container never clears it, so restarting doesn't help. With a directory, Cancel also always fails. With a FIFO (a named pipe), the kernel hangs when it tries to read it. Separately, schedule() follows a broken symlink and writes to wherever it points.

Again, are these real scenarios? The file is not a user file - it is written by machine code. I suppose it is fine to be cautious, as long as the situations are reasonable. As stated above, if such scenarios are the result of the user messing around with things they shouldn't, I'd reconsider just how much we should guard here.

5. An empty file or an unknown mode still blocks all apps and says "please restart", even though nothing will be reset (package_reset.py:52).

Same.

yakutovicha and others added 5 commits October 27, 2026 14:49
Co-authored-by: Daniel Hollas <danekhollas@gmail.com>
aiidalab-docker-stack#605 moved it to 05_factory-reset.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only someone editing the flag file by hand could make it differ from
what was just written, so the check guarded against nothing the tools
can cause.
@yakutovicha
Copy link
Copy Markdown
Member Author
  1. While a reset is scheduled, the home page also hides the Terminal, File Manager and Control links and the admin warning in home_app_warning.md (start_page.py:78). If Cancel fails, the user has no way to reach a terminal to fix it.

Okay, put a link to the terminal, just in case f4ccce5.

The UI now applies the reset script's own rule: a regular, non-symlink
file whose first 64 bytes, without whitespace, are `local`. Anything
else (unknown or binary content, a symlink, a directory, a FIFO) is no
scheduled reset, so it no longer locks or crashes the home page. The
container ignores such files too. Scheduling replaces whatever is at
the path instead of writing through a symlink.
@yakutovicha
yakutovicha commented Oct 27, 2026 •
Copy link
Copy Markdown
Member Author

General comment to Edan's:

How does one arrive at such a situation?...

The situation is indeed quite hypothetical and rare, but the solution is simple and general enough: we simply ignore the "bad" files: f561422.

Checking the flag file is instant, so the Danger zone overrides
refresh() to run synchronously instead of on the base class's
background thread. Nothing races the schedule and cancel buttons any
more, and no widget is changed off the main thread. The section also
refreshes once when built, so it shows the right view from the start,
and the Refresh button still picks up a flag file created or removed
by hand.

The notice is built once and only shown or hidden, instead of rebuilt
on every refresh, so no widgets leak.
@edan-bainglass edan-bainglass left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All good on my end. Thanks @yakutovicha 🙏

@yakutovicha
Copy link
Copy Markdown
Member Author

Since there is also good to go from @danielhollas side, I am going to merge the PR.

@yakutovicha
yakutovicha merged commit 7e2c69d into main Oct 27, 2026
5 checks passed
@yakutovicha
yakutovicha deleted the feature/danger-zone-tab branch October 27, 2026 16:29
8
D5D5
@danielhollas
Copy link
Copy Markdown
Contributor

Okay, put a link to the terminal, just in case f4ccce5.

Why not keeping the whole top panel? Seems more consistent. I might imagine wanting to go back to the control panel, or file explorer as well.

How does one arrive at such a situation? If this requires a user to manipulate the file directly, I don't think that is something for us to guard against.

Yeah, as Sasha says, these should not happen, but given that we're implementing "Danger Zone" it's prudent to be more careful than usual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Control page: implement the Danger zone section

3 participants

0